65,210
社区成员
发帖
与我相关
我的任务
分享kd> u 805C24B5 //双机调试的命令 就是反汇编一个地址
nt!NtOpenProcess+0x21f: 显示该地址在NtOpenProcess+0x21f
805c24b5 75c8 jne nt!NtOpenProcess+0x1e9 (805c247f) //地址 机器码 反汇编
805c24b7 ff75dc push dword ptr [ebp-24h]
805c24ba e88bfefeff call nt!ObOpenObjectByPointer (805b234a)
805c24bf 8bf8 mov edi,eax
805c24c1 8d8548ffffff lea eax,[ebp-0B8h]
805c24c7 50 push eax
805c24c8 e887590200 call nt!SeDeleteAccessState (805e7e54)
805c24cd 8b4dd0 mov ecx,dword ptr [ebp-30h]DWORD dwEditAddress/*保存地址805c24b7*/,dwRetAddress/*因为是jmp所以保存call下一个地址805c24bf*/;
DWORD pObOpenObjectByPointer=NULL;//保存ObOpenObjectByPointer函数地址
__declspec(naked)VOID MyNtOpenProcess()
{
__asm
{
push dword ptr[ebp-24] //恢复指令
push dwRetAddress //push call下一个地址以便遇到ret返回那里
jmp pObOpenObjectByPointer //call nt!ObOpenObjectByPointer (805b234a)
}
}
VOID Hook()
{
UNICODE_STRING Us_ObOpenObjectByPointer;
RtlInitUnicodeString(&Us_ObOpenObjectByPointer,L"ObOpenObjectByPointer");
pObOpenObjectByPointer=(DWORD)MmGetSystemRoutineAddress(&Us_ObOpenObjectByPointer);
DWORD dwNtOpenProcess;
UNICODE_STRING Us_NtOpenProcess;
RtlInitUnicodeString(&Us_NtOpenProcess,L"NtOpenProcess");
dwNtOpenProcess=(DWORD)MmGetSystemRoutineAddress(&Us_NtOpenProcess);//获得NtOpenProcess地址
dwEditAddress=dwNtOpenProcess+0x221; //获得准备修改的地址
KdPrint(("EditAddress=%x\n",dwNtOpenProcessAdd221));
dwRetAddress=dwNtOpenProcess+0x229; //获得返回的地址
KdPrint(("RetAddress=%x\n",dwRetAddress));
__asm
{
//去掉保护
cli
mov eax,cr0
and eax,not 10000h
mov cr0,eax
//还原NtOpenProcess
mov ebx,dwEditAddress
mov al,0xe9
mov byte ptr[ebx],al //写入jmp指令
lea eax,MyNtOpenProcess //取得函数地址
sub eax,ebx //网上获得的方法当前地址sub要跳转的地址再sub 5
sub eax,5
mov DWORD ptr[ebx+1],eax 写入函数地址
//开启保护
mov eax,cr0
or eax,10000h
mov cr0,eax
}
return;
}
kd> u nt!NtOpenProcess+0x21e
nt!NtOpenProcess+0x21e:
805c24b4 ff75c8 push dword ptr [ebp-38h]
805c24b7 ff75dc push dword ptr [ebp-24h]
805c24ba e88bfefeff call nt!ObOpenObjectByPointer (805b234a)
805c24bf 8bf8 mov edi,eax
805c24c1 8d8548ffffff lea eax,[ebp-0B8h]
805c24c7 50 push eax
805c24c8 e887590200 call nt!SeDeleteAccessState (805e7e54)
805c24cd 8b4dd0 mov ecx,dword ptr [ebp-30h]
kd> u nt!NtOpenProcess+0x21f
nt!NtOpenProcess+0x21f:
805c24b5 75c8 jne nt!NtOpenProcess+0x1e9 (805c247f)
805c24b7 ff75dc push dword ptr [ebp-24h]
805c24ba e88bfefeff call nt!ObOpenObjectByPointer (805b234a)
805c24bf 8bf8 mov edi,eax
805c24c1 8d8548ffffff lea eax,[ebp-0B8h]
805c24c7 50 push eax
805c24c8 e887590200 call nt!SeDeleteAccessState (805e7e54)
805c24cd 8b4dd0 mov ecx,dword ptr [ebp-30h]DWORD dwEditCodeAddress,dwRetAddress,dwJneAddress,dwObOpenObjectByPointer;
__declspec(naked)VOID MyNtOpenProcess()
{
__asm
{
jne 805C247Fh //不是很清楚为什么jne dwJneAddress 通不过编译
push dword ptr[ebp-24] //仿照NtOpenProcess里的指令
push dwRetAddress //push返回地址
jmp pObOpenObjectByPointer //调用函数
}
}
VOID Hook()
{
UNICODE_STRING Us_ObOpenObjectByPointer,Us_NtOpenProcess;
DWORD dwNtOpenProcess;
RtlInitUnicodeString(&Us_ObOpenObjectByPointer,L"ObOpenObjectByPointer");
dwObOpenObjectByPointer=(DWORD)MmGetSystemRoutineAddress(&Us_ObOpenObjectByPointer);//取得ObOpenObjectByPointer函数地址
RtlInitUnicodeString(&Us_NtOpenProcess,L"NtOpenProcess");
dwNtOpenProcess=(DWORD)MmGetSystemRoutineAddress(&Us_NtOpenProcess);//取得NtOpenProcess函数地址
dwEditCodeAddress=dwNtOpenProcess+0x21f; //NtOpenProcess+0x21f是要修改的地址
dwRetAddress=dwNtOpenProcess+0x229; //这个是当ObOpenObjectByPointer遇到ret时返回的地址
dwJneAddress =dwNtOpenProcess+0x1e9;//这个是jne跳转的地址
__asm
{
//去掉保护
cli
mov eax,cr0
and eax,not 10000h
mov cr0,eax
//还原NtOpenProcess
mov ebx,dwEditCodeAddress
mov al,0xe9
mov byte ptr[ebx],al //往要修改的地址里写入jmp
lea eax,MyNtOpenProcess
sub eax,ebx
sub eax,5
mov DWORD ptr[ebx+1],eax //写入jmp的函数地址
//开启保护
mov eax,cr0
or eax,10000h
mov cr0,eax
}
return;
}805c24b5 75c8 jne nt!NtOpenProcess+0x1e9 (805c247f)
805c24b7 ff75dc push dword ptr [ebp-24h]
805c24ba e88bfefeff call nt!ObOpenObjectByPointer (805b234a)
805c24bf 8bf8 mov edi,eax
805c24b5 e956bb3977 jmp Hook!MyNtOpenProcess (f795e010)
805c24ba e88bfefeff call nt!ObOpenObjectByPointer (805b234a)
805c24bf 8bf8 mov edi,eaxf795e010 0f8500000000 jne Hook!MyNtOpenProcess+0x6 (f795e016)
f795e016 ff75e8 push dword ptr [ebp-18h]
f795e019 ff351c0096f7 push dword ptr [Hook!dwRetAddress (f796001c)]
f795e01f ff25240096f7 jmp dword ptr [Hook!dwObOpenObjectByPointer (f7960024)] __asm
{
je a
jne 0x805c247f //jne dwJneAddress 通不过编译
a:
push dword ptr[ebp-0x24] //仿照NtOpenProcess里的指令
mov eax,dwRetAddress
push eax //push返回地址
mov eax,0x805b234a
jmp eax //调用函数
}f7cf1b80 7406 je hook!MyNtOpenProcess+0x8 (f7cf1b88)
f7cf1b82 0f8500000000 jne hook!MyNtOpenProcess+0x8 (f7cf1b88)
f7cf1b88 ff75dc push dword ptr [ebp-24h]
f7cf1b8b a11c16cff7 mov eax,dword ptr [hook!dwRetAddress (f7cf161c)]
f7cf1b90 50 push eax
f7cf1b91 b84a235b80 mov eax,offset nt!ObOpenObjectByPointer (805b234a)
f7cf1b96 ffe0 jmp eax
我乌龙f7bccb80 7406 je hook!MyNtOpenProcess+0x8 (f7bccb88)
f7bccb82 0f8500000000 jne hook!MyNtOpenProcess+0x8 (f7bccb88)
f7bccb88 ff75dc push dword ptr [ebp-24h]
f7bccb8b ff351cc6bcf7 push dword ptr [hook!dwRetAddress (f7bcc61c)]
f7bccb91 ff2518c6bcf7 jmp dword ptr [hook!pObOpenObjectByPointer (f7bcc618)]