未调用 IAT 挂钩但挂钩函数

IAT hooked but hooked function is not being called

本文关键字:函数 调用 IAT      更新时间:2023-10-16

我正在编写代码来在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 有一个自执行代码包。如果是这种情况,请尝试在启动后或调用该函数后注入它。