-
-
[旧帖]
[求助]菜鸟我刚学驱动编程,今日学用hOOK出了点问题,来看看吧
0.00雪花
-
发表于:
2014-4-30 20:34
2562
-
[旧帖] [求助]菜鸟我刚学驱动编程,今日学用hOOK出了点问题,来看看吧
0.00雪花
代码编译通过,但没有完美运行呢,也不蓝屏,希望大家能给我找出一下问题,
先上几个图
我是HOOK的NtOpenProcess这个函数,首先通过ssdt表获得NtOpenProcess函数入口地址,然后偏移22的位置开始HOOK,具体看图
但加载驱动后,能执行,但感觉有点小问题,比如我关了xuetr,再次打开时会提示这样:
还有就是比如打开任务管理器
http://www.mengwuji.net/data/attachment/forum/201404/30/122953gb4re001mzvvoy1j.png
界面的边框,都变了,希望大大们能把我找一下错误啊,或者是不是这里不能HOOK啊
代码是这样的:
#include "ntddk.h"
#pragma pack(1)
typedef struct ServiceDescriptorEntry {
unsigned int *ServiceTableBase;
unsigned int *ServiceCounterTableBase; //仅适用于checked build版本
unsigned int NumberOfServices;
unsigned char *ParamTableBase;
} ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t;
#pragma pack()
_declspec(dllimport)ServiceDescriptorTableEntry_t KeServiceDescriptorTable;
//global
ULONG g_OpenProcess;
ULONG g_OpenProcess_jmp;
ULONG g_OpenProcess_tem;
ULONG g_adress;
UCHAR g_cmd[5];
ULONG g_f_code[5];
void PageProtectOn()
{
__asm{//恢复内存保护
mov eax,cr0
or eax,10000h
mov cr0,eax
sti
}
}
void PageProtectOff()
{
__asm{//去掉内存保护
cli
mov eax,cr0
and eax,not 10000h
mov cr0,eax
}
}
void _stdcall Fifter()
{
KdPrint(("%s",(char*)PsGetCurrentProcess()+0x16c));
}
_declspec(naked)
NTSTATUS NewNtOpenProcess()
{
__asm{
add esp,4
pushad
pushfd
call Fifter
popfd
popad
mov edx,dword ptr[ebp + 10]
mov byte ptr[ebp - 4],al
jmp g_OpenProcess_jmp
}
}
NTSTATUS HookNtOpenProcess()
{
g_OpenProcess = KeServiceDescriptorTable.ServiceTableBase[190];
g_OpenProcess_jmp = g_OpenProcess + 22 + 6;
KdPrint(("%X",g_OpenProcess_jmp));
g_adress = (ULONG)NewNtOpenProcess - g_OpenProcess - 22 - 5;
g_cmd[0] =0xE8;
*(ULONG*)&g_cmd[1] = g_adress;
PageProtectOff();
RtlCopyMemory(g_f_code,(PVOID)(g_OpenProcess+22),5);
RtlCopyMemory((PVOID)(g_OpenProcess+22),g_cmd,5);
PageProtectOn();
return STATUS_SUCCESS;
}
VOID UnloadOpenProcess()
{
PageProtectOff();
RtlCopyMemory((PVOID)(g_OpenProcess+22),g_f_code,5);
PageProtectOn();
}
void MyUnloadDriver(PDRIVER_OBJECT pDriverObject)
{
UnloadOpenProcess();
//
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject,PUNICODE_STRING pRger)
{
HookNtOpenProcess();
pDriverObject->DriverUnload = MyUnloadDriver;
return STATUS_SUCCESS;
}
菜鸟我,先在这里谢谢各位前辈们了。
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课