硬编码 HOOK API
这里实现 显示的 “失败” 换成 “成功了啊?”
77D507EA >- E9 733F6B88 jmp MyCrackM.00404762//这里是MessageBoxA 00404762 是 exe程序领空的一个地址
77D507EF 833D BC14D777 0>cmp dword ptr ds:[0x77D714BC],0x0
77D507F6 74 24 je short user32.77D5081C
77D507F8 64:A1 18000000 mov eax,dword ptr fs:[0x18]
77D507FE 6A 00 push 0x0
此时堆栈:
$ ==> > 5F4323CC /CALL 到 MessageBoxA 来自 MFC42D.5F4323C6
$+4 > 000C060C |hOwner = 000C060C ('CrackMe',class='#32770')
$+8 > 004153F0 |Text = "失败"
$+C > 00384520 |Title = "MyCrackMe"
$+10 > 00000000 \Style = MB_OK|MB_APPLMODAL
00404762 8BC4 mov eax,esp //换成 eax操作 最后不用还原
00404764 83C0 08 add eax,0x8
00404767 C700 96474000 mov dword ptr ds:[eax],MyCrackM.00404796
0040476D 8BFF mov edi,edi //这里是HOOK掉的硬编码
0040476F 55 push ebp
00404770 8BEC mov ebp,esp
00404772 - E9 78C09477 jmp user32.77D507EF
00404777 90 nop
00404778 90 nop
编程HOOK API:
程序运行后显示
CPUID0:
EAX = 0000000D //现在要求HOOK 这里显示的值 注入 DLLHOOK OD插件注入
EBX = 756E6547
ECX = 6C65746E
EDX = 49656E69
程序汇编:
00401030 |. B8 00000000 mov eax,0x0
00401035 |. 0FA2 cpuid
00401037 |. 8985 ECFEFFFF mov [local.69],eax ;准备HOOK这里
0040103D |. 899D F0FEFFFF mov [local.68],ebx
00401043 |. 898D E8FEFFFF mov [local.70],ecx
00401049 |. 8995 E4FEFFFF mov [local.71],edx
0040104F |. 8B85 E4FEFFFF mov eax,[local.71]
00401055 |. 8B8D E8FEFFFF mov ecx,[local.70]
0040105B |. 8B95 F0FEFFFF mov edx,[local.68]
00401061 |. 50 push eax
00401062 |. 8B85 ECFEFFFF mov eax,[local.69]
00401068 |. 51 push ecx
00401069 |. 52 push edx
0040106A |. 50 push eax
0040106B |. 68 B0D14000 push 获取硬件.0040D1B0 ; ASCII "CPUID0:
EAX = %p
EBX = %p
ECX = %p
EDX = %p
"
00401070 |. E8 B1010000 call 获取硬件.00401226 //这里是显示函数
跟平常不一样的是 我是要HOOK它进入我VC6.0函数中
#include "stdafx.h"
#include <windows.h>
DWORD g_addr;
__declspec (naked) void IsCPUID(void)
{
__asm
{
mov eax,0x11111111;
mov ebx,0x22222222
mov ecx,0x33333333;
mov edx,0x44444444;
mov dword ptr ss:[ebp-0x114],eax //这里是刚才HOOK掉的代码
push g_addr
ret
}
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
::MessageBox(NULL, "DLL注入成功...", ":)", MB_ICONINFORMATION);
g_addr = 0x00401037; //这里是HOOK处
BYTE szJmp[6] = {0x90};
szJmp[0] = 0xe9;
DWORD dwJmp = (DWORD)IsCPUID - 0x00401037 - 5; //用我的函数地址-HOOK处的地址-5 就是 E9 后面的数据
memcpy(&szJmp[1],&dwJmp,4); //第一个字符为E9 所以从第二字符开始复值
DWORD dwProtet = 0;
VirtualProtect((void*)g_addr,0x10000,PAGE_EXECUTE_READWRITE,&dwProtet);
memcpy((void*)g_addr,(void*)szJmp,6); //HOOK代码
g_addr = g_addr + 6; //这里跳过6个字符 在运行到函数时就 push ret
}
break;
}
return TRUE;
}