加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – IAT挂钩但挂钩功能未被调用

发布时间:2020-12-16 07:30:37 所属栏目:百科 来源:网络整理
导读:我正在编写代码以在 Windows中执行IAT的挂钩.我可以在IAT(Kernel32!GetCurrentProcessId)中更改目标函数的地址,但是稍后在程序中,当钩子函数被称为Kernel32时!调用GetCurrentProcessId而不是钩子. 在调试过程中,我能够看到内核的原始IAT地址!GetCurrentPr
我正在编写代码以在 Windows中执行IAT的挂钩.我可以在IAT(Kernel32!GetCurrentProcessId)中更改目标函数的地址,但是稍后在程序中,当钩子函数被称为Kernel32时!调用GetCurrentProcessId而不是钩子.

在调试过程中,我能够看到内核的原始IAT地址!GetCurrentProcessId:

GetCurrentProcessId地址:7C8099C0

我要交换的功能是:

MyGetCurrentProcessId地址:100118BB

我挂钩thunkIAT-> u1.Function的地址并将其从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-not
http://www.codeproject.com/Articles/21414/Powerful-x86-x64-Mini-Hook-Engine

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读