未调用 IAT 挂钩但挂钩函数
IAT hooked but hooked function is not being called
我正在编写代码来在Windows中执行IAT的钩子。我能够在 IAT 中更改目标函数的地址(Kernel32!GetCurrentProcessId),但是在程序的后面,当钩子函数被称为Kernel32!调用 GetCurrentProcessId 而不是钩子。
在调试过程中,我能够看到内核的原始 IAT 地址!GetCurrentProcessId:
获取当前进程 ID 地址: 7C8099C0
我要换入的函数是:
MyGetCurrentProcessId 地址: 100118BB
我钩住了thunkIAT->u1的地址。函数并将其从 7C8099C0 更改为 100118BB,但是正如我之前提到的,当从程序中调用 GetCurrentProcessId() 时,将调用 Kernel32 函数(不是我注入的函数)。
执行钩子的部分代码是:
if(strcmp(apiName,(char*)(*nameData).Name)==0)
{
DBG_PRINT2("[processImportDescriptor]: found match for %sn", apiName);
VirtualProtect(
&thunkIAT->u1.Function, // start addres of the zone to "unlock"
0x010, // size to protect
PAGE_EXECUTE_READWRITE, // new permission
&dwOldProtect // old permission
);
procPtr = MyGetCurrentProcessId;
thunkIAT->u1.Function = (DWORD)procPtr;
DBG_PRINT2("MyGetCurrentProcessId() address: %08Xn", MyGetCurrentProcessId);
DBG_PRINT2("procPtr address: %08Xn", procPtr);
DBG_PRINT2("thunkIAT->u1.Function address: %08Xn", thunkIAT->u1.Function);
VirtualProtect(
&thunkIAT->u1.Function, // start addres of the zone to "relock"
0x0010, // size to protect
dwOldProtect, // new permission
&dwOldProtect2 // old permission
);
}
有什么想法吗?谢谢。
利用 CreateToolhelp32Snapshot API,我能够将所有 IAT 的函数调用(没有在注入的 DLL IAT 中插入钩子,因为这会导致崩溃)挂接到我的Helloworld
程序中的GetCurrentProcessId()
,该程序被编写为每隔几秒钟简单地报告其进程 ID。在注入 DLL 和挂钩GetCurrentProcessId()
Helloworld
之后,开始按预期调用挂钩函数。在我的研究过程中,我确实发现了一些关于为什么由于现代程序中内置防御而在某些情况下 IAT 挂钩可能不起作用的信息:
http://www.codeproject.com/Articles/12516/Win32-API-hooking-Another-reason-why-it-might-nothttp://www.codeproject.com/Articles/21414/Powerful-x86-x64-Mini-Hook-Engine
也许 exe 有一个自执行代码包。如果是这种情况,请尝试在启动后或调用该函数后注入它。
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 返回指向对象的指针的函数调用是否为 prvalue?
- C++ 如何重载 [] 运算符并进行函数调用
- 代码的效率. 转到和函数调用
- 是同一作用域的函数部分中的函数调用
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 类型擦除的std::function与虚拟函数调用的开销