|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 迷雾少年 于 2015-7-2 08:37 编辑
继上次发了SSDT HOOK 后 现在来发个inline hook 同样是hook inline hook是修改了原函数体 SSDT HOOK 只是修改SSDT表的地址
看图 原始函数地址和当前函数地址不一样就是被HOOK了
inline hook也有好多种的 jmp hook是最简单的 下次写个call hook吧
- [hide]#include <ntddk.h>
- #include "Header.h"
- //NtOpenKey的前5字节
- UCHAR NtCreateFileHeader[5] = {NULL};
- //UCHAR Jmp[5] = {233,0,0,0,0};
- 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 Hook_Stop();
- VOID Hook_Start();
- /* NtCreateFile原形 */
- NTSTATUS NtCreateFile(
- PHANDLE FileHandle,
- ACCESS_MASK DesiredAccess,
- POBJECT_ATTRIBUTES ObjectAttributes,
- PIO_STATUS_BLOCK IoStatusBlock,
- PLARGE_INTEGER AllocationSize,
- ULONG FileAttributes,
- ULONG ShareAccess,
- ULONG CreateDisposition,
- ULONG CreateOptions,
- PVOID EaBuffer,
- ULONG EaLength
- )
- {
- NTSTATUS status;
- /*
- __asm
- {
- mov edi,edi
- push ebp
- mov ebp,esp
- mov eax,KeServiceDescriptorTable.ServiceTableBase[119]
- add eax,5
- jmp eax
- }
- */
- /* 停止HOOK */
- Hook_Stop();
- DbgPrint("目录:%ws",ObjectAttributes->ObjectName->Buffer);
- /* 在文件名中寻找字符串 -> fishc 中文可能DbgView 不支持 */
- if(wcsstr(ObjectAttributes->ObjectName->Buffer,L"fishc"))
- {
- /* 修改返回值有不一样的结果 */
- status = STATUS_OBJECT_NAME_NOT_FOUND;
- }
- else
- {
- /* 把参数传 给zwcreatefile 并保存返回值 */
- status = ZwCreateFile(FileHandle,DesiredAccess,ObjectAttributes,IoStatusBlock,AllocationSize,FileAttributes,ShareAccess,CreateDisposition,CreateOptions,EaBuffer,EaLength);
- }
- Hook_Start();
- return status;
- }
- VOID Hook_Start()
- {
- /* 局部变量 */
-
- UINT32 *Address = NULL; //
- UINT32 Desaddress = NULL; //偏移地址
-
- //关闭内存保护
- PageProtectOff();
- //写前保存前5字节
- RtlCopyMemory((VOID*)&NtCreateFileHeader,(VOID*)KeServiceDescriptorTable.ServiceTableBase[37],5);
- /* 计算偏移地址 公式 = 目标地址 - 原地址 - 5 */
- Desaddress = (ULONG)&NtCreateFile - (ULONG)KeServiceDescriptorTable.ServiceTableBase[37] - 5;
- *((UCHAR*)(KeServiceDescriptorTable.ServiceTableBase[37])) = 233; //JMP
- *((unsigned int*)(KeServiceDescriptorTable.ServiceTableBase[37]+1)) = Desaddress; //地址
-
- //恢复内存保护
- PageProtectOn();
- }
- VOID Hook_Stop()
- {
- PageProtectOff();
-
- /* 恢复HOOK */
- RtlCopyMemory((VOID*)KeServiceDescriptorTable.ServiceTableBase[37],(VOID*)NtCreateFileHeader,5);
-
- PageProtectOn();
- }
- VOID DriverUnload(PDRIVER_OBJECT pDriverObject)
- {
- DbgPrint("Driver Unload!");
- /* 停止HOOK */
- Hook_Stop();
- }
- NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING RegistryPath)
- {
- DbgPrint("Hello! Driver! Driver Entry\n");
- DbgPrint("NtOpenKey address:0x%x\n",(unsigned int)KeServiceDescriptorTable.ServiceTableBase[37]);
- pDriverObject->DriverUnload = DriverUnload;
- /* 开始HOOK */
- Hook_Start();
- return STATUS_SUCCESS;
- }[/hide]
复制代码
Windows7 Visual Stdio 2012 编译通过
虚拟机 XP 系统测试
这里显示SSDT HOOK 是因为QQ的驱动已经比我们先实现 SSDT HOOK 了 但你可以看到我在QQ驱动的那个函数开头有个JMP XX
把QQ卸载重启后再安装启动驱动
inline hook
就这样 如果还有不懂的可以Q我 回复帖子也可以 秒回
效果图
|
|