5
votes

i have been trying to detect API Hook, inline and EAT hook.

For now I did not find anything on how to detect EAT hook.

For Inline Ring 3 hook, what i have so far:

FARPROC Address = GetProcAddress(GetModuleHandle("kernel32.dll"),"ExitProcess");
if (*(BYTE*)Address == 0xE9 || *(BYTE*)Address == 0x90 || *(BYTE*)Address == 0xC3)
{
 printf("Api hooked\n");
}

The problem is that there are several opcodes that can be used to hook/change the prologue of functions, checking JMP / NOP / RET is trivial, I've seen a lot of HOOK types like PUSH RET, MOV, RETN etc ...

I wonder if anyone knows how to detect these hooks (detours) or modifications in the API. And also some way to detect the EAT hook.

Thank you.

3
If somebody has hooked your program, then they can hook your hook detector. - Raymond Chen
Well, the obvious way to check to see if the Export Address Table has been hooked is to see if any of the addresses in the table point to somewhere outside the DLL the EAT belongs to. Although, I believe some standard DLLs forward some functions to other DLLs through the EAT, so you'd have to handle that case. - Ross Ridge

3 Answers

1
votes

GetProcAddress could be hooked as well. Also since you could not know exact API that would be patched, you would have to check all imported functions, which is pretty tedious. Since an intruder has sufficient privileges to inject into your process address space and hook API methods, honestly there is pretty much no way to prevent him from just patching away any protection mechanism altogether. Usually modern software protection systems include kernel mode driver, that scans program memory and prevents dll injection and remote memory modification. Also it is pretty common to use code encryption/obfuscation systems (Themida for example), or even internal virtual execution machines with entirely alien processor instruction sets, which makes patching code on the fly pretty difficult.

0
votes

I believe you should compare the kernel32.dll from the disk with your current dll in the memory, also you should ignore the IAT and fix relocations or you will get different hashes.

If you want an easier solution just rename kernel32.dll and make your API calls from your renamed DLL.

0
votes

You need to hook the IAT address for your current process, then save immediately the bytes.

After this you have the original bytes, so you can later try to copy them again and use memcmp() to compare the old ( original ) bytes with the new ones, if they are different then your IAT address has been hooked by another process.