4

我正在编写代码以在 Windows 中执行 IAT 的挂钩。我可以在 IAT (Kernel32!GetCurrentProcessId) 中更改目标函数的地址,但是稍后在程序中调用挂钩函数时会调用 Kernel32!GetCurrentProcessId 而不是挂钩。

在调试过程中,我可以看到 Kernel!GetCurrentProcessId 的原始 IAT 地址:

GetCurrentProcessId 地址:7C8099C0

我要交换的功能是:

MyGetCurrentProcessId 地址:100118BB

我挂钩 thunkIAT->u1.Function 的地址并将其从 7C8099C0 更改为 100118BB,但是正如我之前提到的,当从程序中调用 GetCurrentProcessId() 时,会调用 Kernel32 函数(不是我注入的那个)。

执行钩子的部分代码是:

if(strcmp(apiName,(char*)(*nameData).Name)==0)
{
DBG_PRINT2("[processImportDescriptor]: found match for %s\n", 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: %08X\n", MyGetCurrentProcessId);
DBG_PRINT2("procPtr address: %08X\n", procPtr);
DBG_PRINT2("thunkIAT->u1.Function address: %08X\n", thunkIAT->u1.Function);

VirtualProtect(
    &thunkIAT->u1.Function, // start addres of the zone to "relock"
    0x0010,          // size to protect
    dwOldProtect,       // new permission
    &dwOldProtect2      // old permission
);

}

有什么想法吗?谢谢你。

4

2 回答 2

2

利用CreateToolhelp32Snapshot API,我能够将所有 IAT 的函数调用(未在注入的 DLL IAT 中插入钩子,因为这会导致崩溃)连接到GetCurrentProcessId()我的Helloworld程序中,该程序被编写为每隔几秒报告一次它的进程 ID。在注入 DLL 和挂钩之后,GetCurrentProcessId() Helloworld开始按预期调用挂钩函数。在我的研究中,我确实发现了一些信息,说明为什么 IAT 挂钩在某些情况下可能由于现代程序中的内置防御而无法工作:

http://www.codeproject.com/Articles/12516/Win32-API-hooking-Another-reason-why-it-might-not
http://www.codeproject.com/Articles/21414/Powerful-x86-x64 -Mini-Hook-Engine

于 2012-06-23T17:07:08.303 回答
0

也许 exe 打包了一个自执行代码。如果是这种情况,请尝试在启动后或调用该函数后注入它。

于 2021-03-25T15:47:40.083 回答