能力值:
( LV3,RANK:20 )
|
-
-
17 楼
extc int _export cdecl ODBG_Pluginmenu(int origin,char data[4096],void *item)
{
if (origin!=PM_MAIN)
return 0; // No pop-up menus in OllyDbg's windows
strcpy(data,"0 开始拦截|1 停止拦截");
return 1;
}
这段是加入菜单,加载后会看到插件里有个HookApi项,里面有两项 "开始拦截" "停止拦截"
|
能力值:
( LV3,RANK:20 )
|
-
-
19 楼
extc void _export cdecl ODBG_Pluginaction(int origin,int action,void *item)
{
HANDLE hProcess;
if (origin == PM_MAIN)
{
switch (action)
{
case 0:
if (pMyAllocMemory)
{
hProcess = (HANDLE)_Plugingetvalue(VAL_HPROCESS);
VirtualFreeEx(hProcess,pMyAllocMemory,0x500,MEM_RELEASE);
}
if (dwExternData[5])
{
hProcess = (HANDLE)_Plugingetvalue(VAL_HPROCESS);
VirtualFreeEx(hProcess,(LPVOID)dwExternData[5],SIZEOF_API_ARRAY * 1000,MEM_RELEASE);
}
if (hModuleArray)
{
hProcess = (HANDLE)_Plugingetvalue(VAL_HPROCESS);
VirtualFreeEx(hProcess,(LPVOID)hModuleArray,sizeof(HMODULE) * 100,MEM_RELEASE);
}
hProcess = (HANDLE)_Plugingetvalue(VAL_HPROCESS);
pMyAllocMemory = VirtualAllocEx(hProcess,NULL,0x500,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
if (!pMyAllocMemory)
{
MessageBox(NULL,"内存分配失败","",MB_OK);
break;
}
_Addtolist(0,0,"内存分配成功");
dwExternData[5] = (DWORD)VirtualAllocEx(hProcess,NULL,SIZEOF_API_ARRAY * 1000,MEM_COMMIT,PAGE_READWRITE);
if (!dwExternData[5])
{
VirtualFreeEx(hProcess,pMyAllocMemory,0x500,MEM_RELEASE);
pMyAllocMemory = 0;
MessageBox(NULL,"内存分配失败1","",MB_OK);
break;
}
_Addtolist(0,0,"内存分配成功1");
hModuleArray = (HMODULE *)VirtualAllocEx(hProcess,NULL,sizeof(HMODULE) * 100,MEM_COMMIT,PAGE_READWRITE);
if (!hModuleArray)
{
VirtualFreeEx(hProcess,pMyAllocMemory,0x500,MEM_RELEASE);
pMyAllocMemory = 0;
VirtualFreeEx(hProcess,(LPVOID)dwExternData[5],SIZEOF_API_ARRAY * 1000,MEM_RELEASE);
dwExternData[5] = 0;
MessageBox(NULL,"内存分配失败2","",MB_OK);
break;
}
lpszStringBuffer = (char *)VirtualAllocEx(hProcess,NULL,1000,MEM_COMMIT,PAGE_READWRITE);
if (!lpszStringBuffer)
{
VirtualFreeEx(hProcess,pMyAllocMemory,0x500,MEM_RELEASE);
pMyAllocMemory = 0;
VirtualFreeEx(hProcess,(LPVOID)dwExternData[5],SIZEOF_API_ARRAY * 1000,MEM_RELEASE);
dwExternData[5] = 0;
VirtualFreeEx(hProcess,(LPVOID)hModuleArray,sizeof(HMODULE) * 100,MEM_RELEASE);
hModuleArray = 0;
MessageBox(NULL,"内存分配失败3","",MB_OK);
break;
}
InitData();
break;
case 1:
hProcess = (HANDLE)_Plugingetvalue(VAL_HPROCESS);
VirtualFreeEx(hProcess,pMyAllocMemory,0x500,MEM_RELEASE);
pMyAllocMemory = 0;
VirtualFreeEx(hProcess,(LPVOID)dwExternData[5],SIZEOF_API_ARRAY * 1000,MEM_RELEASE);
dwExternData[5] = 0;
VirtualFreeEx(hProcess,(LPVOID)hModuleArray,sizeof(HMODULE) * 100,MEM_RELEASE);
hModuleArray = 0;
VirtualFreeEx(hProcess,(LPVOID)lpszStringBuffer,1000,MEM_RELEASE);
lpszStringBuffer = 0;
break;
default:
break;
}
}
}
菜单处理程序,主要为调试程序的注入分配内存
pMyAllocMemory前面100个双字空间,用来存放一些变量(预留100个,真正用到的只有几个),然后再把注入的程序放在预留空间的后面
|
能力值:
( LV3,RANK:20 )
|
-
-
20 楼
__declspec(naked) void HookProc()
{
__asm{
push eax;
push ecx;
push edx;
call loop1;
loop1:
pop eax;
add eax,2eh;//原本调用的函数名称
push eax;
call [pMyAllocMemory];//RecordCallProc,必须要另外更改地址
call loop2;
loop2:
pop eax;
add eax,1ah;
mov eax,[eax];//调用正常的API
lea esp,[esp + 4];
pop edx;
pop ecx;
xchg [esp],eax;
ret;
}
}
这是用来挂钩的函数,每个API复制一份(为了方便),当调用到一个API时,程序会先运行这段程序
call [pMyAllocMemory];这句在后面会做修整(在InitData()中修整),其实就是调用记录函数RecordCallProc
|
能力值:
( LV3,RANK:20 )
|
-
-
22 楼
因为这函数尾部用来存放真正的API入口地址
call loop2;
loop2:
pop eax;
add eax,1ah;是获得尾部位置
mov eax,[eax];//得到真正的存放API入口地址的地址
xchg [esp],eax将真正的API入口地址和堆栈中原有的返回地址交换一下,那下面的RET就会跳到API中接着运行
|
能力值:
( LV3,RANK:20 )
|
-
-
23 楼
void InitData()
{
int i;
DWORD dwAddress,dwWrite,dwProcAddrEntry;
HANDLE hProcess;
BYTE * lpData;
char szText[100];
GETPROCADDRESS MyGetProcAddress = (GETPROCADDRESS)0x7C80AE45;
LOADLIBRARY MyLoadLibrary = (LOADLIBRARY)0x7C801D7B;
BOOL bRet;
if (!pMyAllocMemory)
return;
dwProcAddrEntry = sizeof(DWORD) * 100 + (DWORD)pMyAllocMemory;
hProcess = (HANDLE)_Plugingetvalue(VAL_HPROCESS);
//dwExternData[0] = offset RecordCallProc
dwExternData[0] = (DWORD)RecordCallProc - (DWORD)HookGetProcAddress + (DWORD)dwProcAddrEntry;
//dwExternData[1] = offset HookGetProcAddress
dwExternData[1] = (DWORD)dwProcAddrEntry;
dwExternData[2] = 0;
dwExternData[7] = (DWORD)LocalGetProcAddress1 - (DWORD)HookGetProcAddress + (DWORD)dwProcAddrEntry;
//修正LocalGetProcAddress中的跳转
//dwExternData[7] = offset LocalGetProcAddress1
* (DWORD *)((BYTE *)LocalGetProcAddress + 2) = (DWORD)((BYTE *)pMyAllocMemory + 28);
//修正LocalGetProcAddress1中的跳转
//dwExternData[1] = offset HookGetProcAddress
* (DWORD *)((BYTE *)LocalGetProcAddress1 + 3) = (DWORD)((BYTE *)pMyAllocMemory + 4);
//写入HookProc的地址
* (DWORD *)((DWORD)HookProc + 0x0f) = (DWORD)pMyAllocMemory;
dwAddress = dwExternData[5];
for (i = 0;i < 1000;i ++)
{
if (!WriteProcessMemory(hProcess,(LPVOID)dwAddress,HookProc,0x2c,&dwWrite))
{
MessageBox(NULL,"无法注入内存","",MB_OK);
return;
}
dwAddress += SIZEOF_API_ARRAY;
}
_Addtolist(0,0,"API表初始化成功");
lpData = (BYTE*)dwExternData;
if (!WriteProcessMemory(hProcess,pMyAllocMemory,lpData,sizeof(DWORD) * 100,&dwWrite))
{
MessageBox(NULL,"无法注入内存1","",MB_OK);
return;
}
memset(szStringBuffer,0,1000);
strcpy(szStringBuffer,"kernel32.dll");
strcpy(szStringBuffer + 100,"CreateFileA");
strcpy(szStringBuffer + 200,"WriteFile");
strcpy(szStringBuffer + 300,"e:\\log_files\\logfile.dat");
strcpy(szStringBuffer + 400,"CloseHandle");
strcpy(szStringBuffer + 500,"SetFilePointer");
if (!WriteProcessMemory(hProcess,lpszStringBuffer,szStringBuffer,1000,&dwWrite))
{
MessageBox(NULL,"无法注入内存11","",MB_OK);
return;
}
bRet = SearchAndSet((BYTE *)RecordCallProc,0x45678123,(DWORD)lpszStringBuffer);
if (!bRet)
return;
bRet = SearchAndSet((BYTE *)RecordCallProc,0x56781234,(DWORD)lpszStringBuffer + 100);
if (!bRet)
return;
bRet = SearchAndSet((BYTE *)RecordCallProc,0x67812345,(DWORD)lpszStringBuffer + 200);
if (!bRet)
return;
bRet = SearchAndSet((BYTE *)RecordCallProc,0x78123456,(DWORD)lpszStringBuffer + 300);
if (!bRet)
return;
bRet = SearchAndSet((BYTE *)RecordCallProc,0x81234567,(DWORD)lpszStringBuffer + 400);
if (!bRet)
return;
bRet = SearchAndSet((BYTE *)RecordCallProc,0x91234567,(DWORD)lpszStringBuffer + 500);
if (!bRet)
return;
bRet = SearchAndSet((BYTE *)HookGetProcAddress,0x12345678,(DWORD)pMyAllocMemory + 8);
if (!bRet)
return;
// * (DWORD *)lpData = (DWORD)pMyAllocMemory + 8;
// MessageBox(NULL,"123","",MB_OK);
bRet = SearchAndSet((BYTE *)HookGetProcAddress,0x23456781,dwProcAddrEntry + (DWORD)OldGetProcAddress - (DWORD)HookGetProcAddress);
if (!bRet)
return;
// MessageBox(NULL,"456","",MB_OK);
bRet = SearchAndSet((BYTE *)RecordCallProc,0x7C80AE40,dwProcAddrEntry + (DWORD)OldGetProcAddress - (DWORD)HookGetProcAddress);
if (!bRet)
return;
// MessageBox(NULL,"789","",MB_OK);
if (!WriteProcessMemory(hProcess,(LPVOID)dwProcAddrEntry,HookGetProcAddress,0x300,&dwWrite))
{
MessageBox(NULL,"无法注入内存2","",MB_OK);
return;
}
wsprintf(szText,"myApiArray = %X",dwExternData[5]);
_Addtolist(0,0,szText);
wsprintf(szText,"pMyAllocMemory = %X",pMyAllocMemory);
_Addtolist(0,0,szText);
wsprintf(szText,"hModuleArray = %X",hModuleArray);
_Addtolist(0,0,szText);
_Addtolist(0,0,"注入成功");
//hook GetProcAddress
if (!WriteProcessMemory(hProcess,(LPVOID)MyGetProcAddress,LocalGetProcAddress,7,&dwWrite))
{
MessageBox(NULL,"无法注入内存3","",MB_OK);
return;
}
}
|