使用 Sys Internals 的 procmon 记录进程
过滤文件访问的日志
(最新版本有一个文件摘要选项卡,可将输入过滤器表达式简化为仅单击鼠标)
一个简单的 xorrer 的代码(接受一个输入文件并写回一个 xorred 文件)
#include <stdio.h>
#include <stdlib.h>
#define ENOENT 2
void main(int argc, char *argv[]) {
if(argc !=3 ) { printf("usage : %s infile outfile",argv[0]); return;}
FILE *fp = 0; errno_t err=ENOENT; long flen =0,bread =0 ; char *buff =0;
if (((err = fopen_s(&fp,argv[1],"rb")) == 0) && (fp !=0)) {
fseek(fp,0,SEEK_END);
flen = ftell(fp);
if((buff = (char *)calloc(flen,sizeof(char))) !=0 ) {
fseek(fp,0,SEEK_SET);
if (( bread = fread(buff,sizeof(char),flen,fp) ) == flen) {
fclose(fp); err=ENOENT;
for(int i = 0; i< flen; i++) {
buff[i] ^= 'A' ;
}
if(((err = fopen_s(&fp,argv[2],"wb")) == 0) && (fp !=0)) {
fwrite(buff,1,flen,fp);
fclose(fp);
free(buff);
}
}
}
}
}
一个 batfile 记录此文件访问(盲运行)并将日志再次加载到 procmon 以应用过滤器并将过滤的事件保存为 xml,这允许 powershell 解析和打印
echo off
start procmon.exe /quiet /minimized /backingfile /nofilter .\LogFile.pml
procmon.exe /waitforidle
start /wait encfile.exe rawdata.txt encdata.txt
procmon.exe /terminate
start /wait procmon.exe /openlog .\logfile.pml
powershell ([xml] ( Get-Content .\logfile.xml)).procmon.eventlist.event[2].stack.frame
pause
用于保存 xml 文件的过滤器是“如果路径包含 xxxx,其中 xxxx 是感兴趣的文件名,则包括”
这是文件读取的堆栈
PS > ([xml]
( Get-Content .\logfile.xml)).procmon.eventlist.event[2].stack.frame
depth address path location
----- ------- ---- --------
0 0xb9ed5888 C:\WINDOWS\Syste... FltpPerformPreCa...
1 0xb9ed72a0 C:\WINDOWS\Syste... FltpPassThroughI...
2 0xb9ed7c48 C:\WINDOWS\Syste... FltpPassThrough ...
3 0xb9ed8059 C:\WINDOWS\Syste... FltpDispatch + 0...
4 0x804ee129 C:\WINDOWS\syste... IopfCallDriver +...
5 0x80571d9c C:\WINDOWS\syste... NtReadFile + 0x580
6 0x8053d658 C:\WINDOWS\syste... KiFastCallEntry ...
7 0x40364c C:\Documents and... encfile.exe + 0x...
8 0x403ac0 C:\Documents and... encfile.exe + 0x...
9 0x4033a2 C:\Documents and... encfile.exe + 0x...
10 0x4015bf C:\Documents and... encfile.exe + 0x...
11 0x401698 C:\Documents and... encfile.exe + 0x...
12 0x4016d1 C:\Documents and... encfile.exe + 0x...
13 0x4010d3 C:\Documents and... encfile.exe + 0x...
14 0x401d09 C:\Documents and... encfile.exe + 0x...
15 0x7c817077 C:\WINDOWS\syste... BaseProcessStart...
16 0x0
确定 ReadFile 调用
:\cdb -c "ub 40364c;q" encfile.exe | tail -n 2
00403646 ff1550b04000 call dword ptr [image00400000+0xb050 (0040b050)]
quit:
:\cdb -c ".printf \"%y\n\",poi(40b050);q" encfile.exe | tail -n 2
kernel32!ReadFile (7c801812)
quit: