SDT Hook 을 통한 File Monitoring 문제점
원본 : http://www.themssforum.com/Drivers/File-System-104809/

Will not work on x64 Vista/2008, also note that NtReadFile hook will not catch
paging IO.
- Maxim Shatskih, Windows DDK MVP

Using a SSDT hook driver for this is incredibly irresponsible. First as Max
pointed out, it will not work for X64, and it will not catch paging I/O.
Also, getting these right is harder than one thinks, and is likely to
destabilize the system. Also, the driver will immediately be flagged as
MALWARE. Following such a path for file operations that are easily
catchable with approved ways, is beyond stupid.
- Don Burn (MVP, Windows DDK)

This can be done with a mini-filter and Microsoft provides one FileSpy that
meets most of the OP's needs. Get the WDK and take a look.

I don't think SSDT hook driver look like malware. Too many HIPS
software are using this technology.
Mini-filter driver maybe is the best way to done this case.

And some not all of these are special cased in the MALWARE detection.
Bottom lime is you cannot hook and unhook safely and it is a damaging
practice that hopefully Microsoft will block in 32 bit someday as well as 64
bit.

결국은 미니 필터 드라이버, WDK에 새로 추가된 미니필터 드라이버를 공부해 보도록 해야겠다.

자료가 별로 없는게 단점이지만 WDK에 minifilter예제들이 있으므로 그걸참고로 해야할듯 -ㅁ-;
by 꿍스 | 2008/08/06 20:22 | 삽질 | 트랙백 | 덧글(0)
AIR로 프로그램 실행하기 ( Windows AIR Proxy )
Adobe AIR가 SQLite및 File 함수를 지원하지만 정작 파일 실행은 하지 못한다.
예제로 배우는 Flex3 책에는 AIRConnect라는 AIR와 MFC를 연동한 부분이 있지만, 그 프로그램은 같은 파일을 반복적으로 쓰고,
또 검사해야하야 하기때문에, 빠른 응답을 기대할 수 없어서 소켓을 이용하여 Win32 어플리케이션과 통신을 하는 방법을 이용했다.

서버가 Socket Accepct를 하는 부분은 다음과 같다.

Win32


while(true) {
//접속을 기다림
hClntSock = accept(hServSock,(SOCKADDR*)&clntAddr,&clntAddrSize);
if(hClntSock == INVALID_SOCKET) {
MessageBox(m_hWnd,"ACCEPT 에러.","에러",NULL);
}

memset(message,0,BUFSIZE);

// 클라이언트와 통신
while((strLen = recv(hClntSock,message,BUFSIZE,0)) != 0) {
int rs = (int)ShellExecute(NULL, "open", message,
NULL,NULL, SW_SHOW);
sprintf_s(retMsg, "%d", rs);
send(hClntSock,retMsg,3,0);
}
closesocket(hClntSock);
}

여기서는 AIR에서 파일명을 던지면, Win32어플리케이션에서 무조건 실행을 시키도록 했다.
전체 파일은 첨부파일을 참고면 된다.
Win32 어플리케이션 (여기서는 WTL이용) 에서 서버소켓을 생성하고 AIR에서 이제 이벤트가 발생할때마다 Win32어플리케이션으로 통지를 한다.

AIR


var socket:Socket = new flash.net.Socket();
socket.addEventListener(Event.CONNECT, function(event:Event) :void {
socket.writeMultiByte(temp.label,"euc-kr");
socket.flush();
});

socket.addEventListener(IOErrorEvent.IO_ERROR,
function(event:Event) : void {
mx.controls.Alert.show(event.toString());
socket.close();
});

socket.addEventListener(ProgressEvent.SOCKET_DATA,
function(event:ProgressEvent) : void {
var str:String = socket.readMultiByte(3, "euc-kr");
if(int(str) < 32) {
mx.controls.Alert.show("파일 실행 에러 입니다. 에러 : " + str);
}
socket.close();
});

socket.connect("127.0.0.1",8000);

AIR 에서는 소켓으로 로컬로 접속하여 메세지를 보내고 결과값을 받는다. 여기서는 ShellExecute의 리턴값을 받는다.
에러처리를 AIR에서 하기위해서 이다. ( ShellExecute가 32보다 작은값을 리턴하면 에러이다. )

readMultiByte 일반 MultiByte String을 읽어와서 UTF-8로 변경해서 리턴한다. 이함수는 읽어올 데이터의 길이를 정해주어야 하는데, 틀릴경우 익셉션이 발생하므로 미리 프로토콜을 지정하는 것이 좋다.

AirSocketProxy.zip
by 꿍스 | 2008/07/31 08:43 | 삽질 | 트랙백(1) | 덧글(0)
SDT를 후킹하여 파일 삭제 모니터링 하기

ZwDeleteFIle(NtDeleteFile) 이라는 함수가 있어서 파일 삭제가 될때 이 ZwDeleteFile이라는 함수가 불리어 질것이라고 예상을 하여 ZwDeleteFIle함수를 후킹하였으나 DbgPrint로 뿌리니 아무런 반응이 없어서, 인터넷을 찾는 도중 원인을 알아냈다.

http://www.rohitab.com/discuss/index.php?showtopic=29037

This should be interesting for you(Windows Nt/2000 Native Api Reference By Gary Nebbett):
"There are alternative methods of deleting a file, and the Win32 DeleteFile function uses ZwSetInformationFile with a FileInformationClass of
FileDispositionInformation."

간단하게 말해서 Win32의 파일 삭제 함수는 ZwSetInformation으로 FileInformationClass 정보가 FileDispostionInformation면 삭제되는 것이다.

대략적으로 소스코드를 보면

NTSTATUS NewZwSetInformationFile(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN PVOID FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInformationClass
)
{
NTSTATUS rc;

rc = ((ZWSETINFORMATIONFILE)(OldZwSetInformationFile)) (
FileHandle,
IoStatusBlock,
FileInformation,
Length,
FileInformationClass
);

if(FileInformationClass == FileDispositionInformation) {
DbgPrint("Deleted File");

}
return rc;
}


이렇게 처리하면 된다.

by 꿍스 | 2008/07/20 23:43 | 삽질 | 트랙백 | 덧글(0)


<< 이전 페이지 다음 페이지 >>