首页
社区
课程
招聘
[旧帖] HOOK的NtQuerySystemInformation逻辑问题 0.00雪花
发表于: 2016-2-16 10:37 3848

[旧帖] HOOK的NtQuerySystemInformation逻辑问题 0.00雪花

2016-2-16 10:37
3848
收藏
免费 0
支持
分享
最新回复 (17)
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
你昨天贴的汇编的代码是不是就是用这个代码生成的?
2016-2-16 10:39
0
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
我感觉上下文不够全,很难预测你到底想做什么,所以想帮助也无从下手
2016-2-16 10:48
0
雪    币: 8
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
对啊,就是在模拟一下,帮我缕一缕,我有点不清楚了
2016-2-16 10:50
0
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
我建议你先把你要做的事儿的前因后果描述一下,咱们再说该怎么去做。
2016-2-16 10:51
0
雪    币: 8
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
假设有 a.exe  a.exe a.exe b.exe c.exe d.exe
(a.exe里有遍历同进程名函数,正常能遍历到3个a.exe)
hook a.exe NtQuerySystemInformation 让a.exe只能发现自身发现不了其他的 且 能发现b.exe c.exe d.exe(这样更安全)
2016-2-16 11:04
0
雪    币: 8
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
pSystemProcesses := PSYSTEM_PROCESSES(SystemInformation);
pSystemProcesses.ProcessId是遍历到的进程ID
如果发现不是自身getcurrentprocessid,让pSystemProcesses结构里取不到任何信息,咋弄
2016-2-16 11:56
0
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
这个事儿不难,现在你想做的事儿就是写个HOOK程序,把a.exe里面调用NtQuerySystemInformation的地方修改成你自己的处理代码 ,是这样吗?

还是你自己现在就有a.exe的源代码?
2016-2-16 14:09
0
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
提示你一下:pSystemProcesses->ProcessName.Buffer 是对应的进程的image名字,你可以根据这个名字来区分:
     if( (GetProcessId() != GetCurrentProcessId()) && (!wcscmp(pSystemProcesses->ProcessName.Buffer,"a.exe"))
{
        //同名的其他进程,此时让它什么也不能做?
}
2016-2-16 14:33
0
雪    币: 8
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
Hook[53].UnHook;
     pSystemProcesses := PSYSTEM_PROCESSES(SystemInformation);
   pSystemProcesses:=SizeOf(PSystemProcesses);
    fh:=NtQuerySystemInformation(SystemProcessesAndThreadsInformation,SystemInformation,SystemInformationLength,ReturnLength);

      if Result=0 then
      begin
           if SystemInformationClass= SystemProcessesAndThreadsInformation then// outputdebugstring('ProcessesAndThreads');
             while pSystemProcesses.NextEntryDelta>0 do
             begin
                 if pSystemProcesses.ProcessId<>getcurrentprocessid then
                 begin
                 outputdebugstring(pansichar(inttostr(pSystemProcesses.ProcessId)));
                 end;
             outputdebugstring(pansichar(inttostr(pSystemProcesses.ProcessId)));
             pSystemProcesses.NextEntryDelta:=pSystemProcesses.NextEntryDelta-1;
           //  ZwQueryInformationProcess(getcurrentprocess,ProcessBasicInformation,@pbi, sizeof(pbi), @bytesIO);
             end;
      end;
   Result:= TNewNtQuerySystemInformation(Hook[53].BaseAddr)(SystemInformationClass,SystemInformation,SystemInformationLength,ReturnLength);
   Hook[53].Hook;
end;
我这样写的,pSystemProcesses.ProcessId等于0,那个条件一会再弄,先让buffer有内容在说。我是新手,请指教,谢谢了
2016-2-16 14:41
0
雪    币: 8
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
你帮我缕一缕,C代码我也能看懂,感谢
2016-2-16 14:42
0
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
难道现在你调用完NtQuerySystemInformation 之后,还不能成功返回一些有用的进程信息?

如果是这样的话,你需要看看fh的返回值是什么,然后根据对应的返回值进行参数调整。比如说:
fh:=NtQuerySystemInformation(SystemProcessesAndThreadsInformation,SystemInformation,SystemInformationLength,ReturnLength);
这个语句的话,里面第一个参数指明你要查询的是进程和线程的信息,第二个参数是用来返回系统当前所有进程信息的一块内存, 第三个参数应该是这块内存的大小,第四个参数是返回据的总大小。一般应该让第二个参数提供的存存空间足够大才行。比如:
SystemInformation = malloc(1000000*sizeof(char)) ; //这里是申请了大约一M的内存
然后这样调用:

fh:=NtQuerySystemInformation(SystemProcessesAndThreadsInformation,SystemInformation,1000000,ReturnLength);
2016-2-16 14:54
0
雪    币: 8
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
hook程序,和a.exe引用NtQuerySystemInformation遍历进程数量都有,我自己琢磨着测试做呢,就是不成功。请指教感谢
2016-2-16 14:55
0
雪    币: 116
活跃值: (190)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
用C写的一段例子,你看看或者就有启发了

int main()
{
        HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
        if(!hNtDll)
                return -1;
        ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(hNtDll,"ZwQuerySystemInformation");
        ULONG cbBuffer = 0x1000000;
        LPVOID pBuffer = NULL;
        pBuffer = malloc(cbBuffer);
        if(pBuffer == NULL)
                return -1;
        NTSTATUS ret = ZwQuerySystemInformation(SystemProcessesAndThreadsInformation,pBuffer,cbBuffer,NULL);
        if(ret != STATUS_SUCCESS)
        {
                printf("ZwQuerySystemInformation return failed with status %d\n", ret);
        }
        PSYSTEM_PROCESS_INFORMATION pInfo = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
        for(;;)
        {
                if(pInfo->ProcessName.Buffer && !wcscmp(pInfo->ProcessName.Buffer, L"EnumProcess.exe"))
                {
                        pInfo = (PSYSTEM_PROCESS_INFORMATION)(((PUCHAR)pInfo) + pInfo->NextEntryDelta);
                        continue;
                }
                printf("PID: %d (%ls) \n",pInfo->ProcessId,pInfo->ProcessName.Buffer);
       
                if(pInfo->NextEntryDelta == 0)
                        break;
                pInfo = (PSYSTEM_PROCESS_INFORMATION)(((PUCHAR)pInfo) + pInfo->NextEntryDelta);
        }
        free(pBuffer);
        getchar();
        return 0;
}
2016-2-16 15:16
0
雪    币: 43
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
YY哦哦哦哦哦哦
2016-2-16 15:56
0
雪    币: 43
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
我就随便看看
2016-2-16 16:13
0
雪    币: 43
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
我默默哦的哦哦么的额
2016-2-16 16:17
0
雪    币: 43
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
18
浓浓,天下我摸
2016-2-16 16:19
0
游客
登录 | 注册 方可回帖
返回
//