首页
社区
课程
招聘
[求助]鬼,我hook了一个轮回都不知道任务管理器是用哪个API枚举进程
发表于: 2009-6-10 20:29 5556

[求助]鬼,我hook了一个轮回都不知道任务管理器是用哪个API枚举进程

2009-6-10 20:29
5556
新手,不要笑我。
我在ring3下练习hook api,想在任务管理器隐藏自己,从EnumProcesses到Process32NextW,结果发现任务管理器根本没使用这些API,请高手指点下。
不要搞什么ring0下的NtQuerySystemInformation!弄个有效果点。
代码如下,不要笑我,水平一般,一搞explorer就出错,如果sys估计蓝了。
补充下:hook其它函数都成功,只是hook NtQuerySystemInformation不行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <windows.h>
#include "HookApi_JMP.h"
typedef LONG NTSTATUS;
 
 
CHookApi_Jmp msgbox;
HHOOK g_hHook;
BOOL bHook=false;
BOOL Init();
 
 
typedef enum _SYSTEM_INFORMATION_CLASS    //    Q S
{
    SystemBasicInformation,                // 00 Y N
    SystemProcessorInformation,            // 01 Y N
    SystemPerformanceInformation,          // 02 Y N
    SystemTimeOfDayInformation,            // 03 Y N
    SystemNotImplemented1,                // 04 Y N
    SystemProcessesAndThreadsInformation,  // 05 Y N
    SystemCallCounts,                      // 06 Y N
    SystemConfigurationInformation,        // 07 Y N
    SystemProcessorTimes,                  // 08 Y N
    SystemGlobalFlag,                      // 09 Y Y
    SystemNotImplemented2,                // 10 Y N
    SystemModuleInformation,              // 11 Y N
    SystemLockInformation,                // 12 Y N
    SystemNotImplemented3,                // 13 Y N
    SystemNotImplemented4,                // 14 Y N
    SystemNotImplemented5,                // 15 Y N
    SystemHandleInformation,              // 16 Y N
    SystemObjectInformation,              // 17 Y N
    SystemPagefileInformation,            // 18 Y N
    SystemInstructionEmulationCounts,      // 19 Y N
    SystemInvalidInfoClass1,              // 20
    SystemCacheInformation,                // 21 Y Y
    SystemPoolTagInformation,              // 22 Y N
    SystemProcessorStatistics,            // 23 Y N
    SystemDpcInformation,                  // 24 Y Y
    SystemNotImplemented6,                // 25 Y N
    SystemLoadImage,                      // 26 N Y
    SystemUnloadImage,                    // 27 N Y
    SystemTimeAdjustment,                  // 28 Y Y
    SystemNotImplemented7,                // 29 Y N
    SystemNotImplemented8,                // 30 Y N
    SystemNotImplemented9,                // 31 Y N
    SystemCrashDumpInformation,            // 32 Y N
    SystemExceptionInformation,            // 33 Y N
    SystemCrashDumpStateInformation,      // 34 Y Y/N
    SystemKernelDebuggerInformation,      // 35 Y N
    SystemContextSwitchInformation,        // 36 Y N
    SystemRegistryQuotaInformation,        // 37 Y Y
    SystemLoadAndCallImage,                // 38 N Y
    SystemPrioritySeparation,              // 39 N Y
    SystemNotImplemented10,                // 40 Y N
    SystemNotImplemented11,                // 41 Y N
    SystemInvalidInfoClass2,              // 42
    SystemInvalidInfoClass3,              // 43
    SystemTimeZoneInformation,            // 44 Y N
    SystemLookasideInformation,            // 45 Y N
    SystemSetTimeSlipEvent,                // 46 N Y
    SystemCreateSession,                  // 47 N Y
    SystemDeleteSession,                  // 48 N Y
    SystemInvalidInfoClass4,              // 49
    SystemRangeStartInformation,          // 50 Y N
    SystemVerifierInformation,            // 51 Y Y
    SystemAddVerifier,                    // 52 N Y
    SystemSessionProcessesInformation      // 53 Y N
} SYSTEM_INFORMATION_CLASS;
 
typedef struct _SYSTEM_MODULE_INFORMATION  // Information Class 11
{
    ULONG  Reserved[2];
    PVOID  Base;
    ULONG  Size;
    ULONG  Flags;
    USHORT Index;
    USHORT Unknown;
    USHORT LoadCount;
    USHORT ModuleNameOffset;
    CHAR  ImageName[256];
}SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;
 
typedef NTSTATUS ( __stdcall *NtQUERYSYSTEMINFORMATION ) ( IN SYSTEM_INFORMATION_CLASS SystemInformationClass, IN OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength OPTIONAL );
static NtQUERYSYSTEMINFORMATION NtQuerySystemInformation = NULL;
 
 
NTSTATUS __stdcall MyNtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass, IN OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength OPTIONAL )
{
msgbox.SetHookOff();
NtQuerySystemInformation=(NtQUERYSYSTEMINFORMATION)GetProcAddress(LoadLibrary("ntdll.dll"),"NtQuerySystemInformation");
if(NtQuerySystemInformation==NULL) MessageBox(NULL, "can't get NtQueryInformationThread", "", MB_OK);
NTSTATUS nReturn=NtQuerySystemInformation(SystemInformationClass,SystemInformation,SystemInformationLength,ReturnLength);
msgbox.SetHookOn();
return(nReturn);
}
// 空的钩子函数
LRESULT WINAPI Hook(int nCode,WPARAM wParam,LPARAM lParam)
{
    return(CallNextHookEx(g_hHook,nCode,wParam,lParam));
}
//---------------------------------------------------------------------------
BOOL Init()
{
  
msgbox.Initialize("ntdll.dll","NtQuerySystemInformation",(FARPROC)MyNtQuerySystemInformation);
msgbox.SetHookOn(); // 开始拦截
return(true);
}
// 输出,安装空的钩子函数
extern"C"__declspec(dllexport) bool InstallHook()
{
    g_hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)Hook,LoadLibrary("dll.dll"),0);
    if (!g_hHook)
    {
     MessageBoxA(NULL,"启用进程保护失败,请把本程序加入进程白名单后再试一次!","失败",MB_OK);
    return(false);
    }
    return(true);
}
//---------------------------------------------------------------------------
// 输出,Uninstall钩子函数
extern"C"__declspec(dllexport) bool  UninstallHook()
{
    msgbox.SetHookOff();
    return(UnhookWindowsHookEx(g_hHook));
}
//---------------------------------------------------------------------------
// 初始化得到MessageBoxA的地址,并生成Jmp XXX(MyMessageBoxA)的跳转指令
//---------------------------------------------------------------------------
int WINAPI DllMain(HINSTANCE hinst,unsigned long reason,void* lpReserved)
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        if(!Init()) return(false);
        break;
      case DLL_PROCESS_DETACH:
        if(bHook) UninstallHook();
        break;
    }
    return TRUE;
}

[注意]看雪招聘,专注安全领域的专业人才平台!

收藏
免费
支持
分享
最新回复 (5)
雪    币: 635
活跃值: (101)
能力值: ( LV12,RANK:420 )
在线值:
发帖
回帖
粉丝
2
hook ring3的ntquerysysteminformation就可以了~
2009-6-10 20:46
0
雪    币: 137
活跃值: (12)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
弄了,打开任务管理器,没触发,浏览文件夹时触发了,不过出错退出了,查了下,别人说,NtQuerySystemInformation本来说是多次调用最后才成功的。
但我hook 问题不知道在什么地方,难道它不一般?
2009-6-11 09:00
0
雪    币: 209
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
ring3的Hook API是不是只在本进程有效?
2009-6-11 11:05
0
雪    币: 206
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
在哪有效要看你hook到哪了,hook本进程就只有本进程有效了,hook其他进程,其他进程就有效了
2009-6-12 10:31
0
雪    币: 137
活跃值: (12)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
6
经过反复调试,只有很少几次能进入新的MyNtQuerySystemInformation,一般都没进去,不知道转到哪里去了,因此引起出错。请大牛指点下,jmp到什么地方去了(hook其它函数都一直成功),是不是hook NtQuerySystemInformatione 有什么特别地方?
我另开帖讨论了:http://bbs.pediy.com/showthread.php?t=91525
2009-6-14 17:23
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册