首页
社区
课程
招聘
[求助]大家来看看这段 SSDT 钩子的代码哪儿错了
发表于: 2009-3-18 22:07 5803

[求助]大家来看看这段 SSDT 钩子的代码哪儿错了

2009-3-18 22:07
5803
下面的代码,加载后钩不上
typedef struct _SystemServiceDescriptorTable
{
     PVOID     ServiceTableBase;
     PULONG     ServiceCounterTableBase;
     ULONG     NumberOfService;
     ULONG     ParamTableBase;
}SystemServiceDescriptorTable,*PSystemServiceDescriptorTable;
extern "C" _declspec(dllimport) SystemServiceDescriptorTable *KeServiceDescriptorTable;
typedef NTSTATUS (__stdcall*MYNTOPENPROCESS)();
MYNTOPENPROCESS mynt;
NTSTATUS MyNtOP();
ULONG yuanNtOpenProcess;
void hook();
void unhook();
VOID SSDT_DriverUnload(
        IN PDRIVER_OBJECT                DriverObject
        )
{
        unhook();
}

#ifdef __cplusplus
extern "C" {
#endif
NTSTATUS DriverEntry(
        IN OUT PDRIVER_OBJECT   DriverObject,
        IN PUNICODE_STRING      RegistryPath
        )
{
        hook();
        DriverObject->DriverUnload = SSDT_DriverUnload;
        return STATUS_SUCCESS;
}
void hook()
{
        ULONG address;
        address = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0x7A * 4;
        yuanNtOpenProcess = *(ULONG*)address;
        mynt = (MYNTOPENPROCESS)yuanNtOpenProcess;
        __asm
     {
         cli
         mov     eax, cr0
         and     eax, not 10000h
         mov     cr0, eax
     }
        *((ULONG*)address) = (ULONG)MyNtOP;
        __asm
     {
         mov     eax, cr0
         or     eax, 10000h
         mov     cr0, eax
         sti
     }
}
void unhook()
{
        ULONG address;
        address = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0x7A * 4;
        __asm
     {
         cli
         mov     eax, cr0
         and     eax, not 10000h
         mov     cr0, eax
     }
        *((ULONG*)address) = (ULONG)yuanNtOpenProcess;
        __asm
     {
         mov     eax, cr0
         or     eax, 10000h
         mov     cr0, eax
         sti
     }
}
NTSTATUS MyNtOP()
{
        return (NTSTATUS)0;
}

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 1
支持
分享
最新回复 (12)
雪    币: 7651
活跃值: (523)
能力值: ( LV9,RANK:610 )
在线值:
发帖
回帖
粉丝
2
先看到很多函数原型都不对
2009-3-18 23:23
0
雪    币: 225
活跃值: (10)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
3
改完也得蓝
2009-3-18 23:48
0
雪    币: 342
活跃值: (55)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
4
哪儿不对,就说出来吧,反正我们都是在学习…
2009-3-19 08:24
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
5
哪里都不对,
2009-3-19 08:47
0
雪    币: 290
活跃值: (20)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
6
哈哈真牛比~~

把NtOpenProcess的原型声明对吧
你要HOOK的代理函数也需要和原函数原型一样
2009-3-19 09:27
0
雪    币: 419
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
可以参考下

堕落天才



代码

#include<ntddk.h>

typedef struct _SERVICE_DESCRIPTOR_TABLE
{
  PVOID   ServiceTableBase;
  PULONG  ServiceCounterTableBase;
  ULONG   NumberOfService;
  ULONG   ParamTableBase;
}SERVICE_DESCRIPTOR_TABLE,*PSERVICE_DESCRIPTOR_TABLE; //由于KeServiceDescriptorTable只有一项,这里就简单点了
extern PSERVICE_DESCRIPTOR_TABLE    KeServiceDescriptorTable;//KeServiceDescriptorTable为导出函数

/////////////////////////////////////
VOID Hook();
VOID Unhook();
VOID OnUnload(IN PDRIVER_OBJECT DriverObject);
//////////////////////////////////////
ULONG JmpAddress;//跳转到NtOpenProcess里的地址
ULONG OldServiceAddress;//原来NtOpenProcess的服务地址
//////////////////////////////////////
__declspec(naked) NTSTATUS __stdcall MyNtOpenProcess(PHANDLE ProcessHandle,
               ACCESS_MASK DesiredAccess,
               POBJECT_ATTRIBUTES ObjectAttributes,
               PCLIENT_ID ClientId)
{
  DbgPrint("NtOpenProcess() called");
  __asm{
    push    0C4h
    push    804eb560h  //共十个字节
    jmp     [JmpAddress]     
  }
}
///////////////////////////////////////////////////
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
  DriverObject->DriverUnload = OnUnload;
  DbgPrint("Unhooker load");
  Hook();
  return STATUS_SUCCESS;
}
/////////////////////////////////////////////////////
VOID OnUnload(IN PDRIVER_OBJECT DriverObject)
{
  DbgPrint("Unhooker unload!");
  Unhook();
}
/////////////////////////////////////////////////////
VOID Hook()
{
  ULONG  Address;
  Address = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0x7A * 4;//0x7A为NtOpenProcess服务ID
  DbgPrint("Address:0x%08X",Address);

  OldServiceAddress = *(ULONG*)Address;//保存原来NtOpenProcess的地址
  DbgPrint("OldServiceAddress:0x%08X",OldServiceAddress);

  DbgPrint("MyNtOpenProcess:0x%08X",MyNtOpenProcess);

  JmpAddress = (ULONG)NtOpenProcess + 10; //跳转到NtOpenProcess函数头+10的地方,这样在其前面写的JMP都失效了
  DbgPrint("JmpAddress:0x%08X",JmpAddress);
   
  __asm{//去掉内存保护
    cli
         mov  eax,cr0
    and  eax,not 10000h
    mov  cr0,eax
  }

  *((ULONG*)Address) = (ULONG)MyNtOpenProcess;//HOOK SSDT

  __asm{//恢复内存保护  
          mov  eax,cr0
    or   eax,10000h
    mov  cr0,eax
    sti
  }
}
//////////////////////////////////////////////////////
VOID Unhook()
{
  ULONG  Address;
  Address = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0x7A * 4;//查找SSDT

  __asm{
    cli
          mov  eax,cr0
    and  eax,not 10000h
    mov  cr0,eax
  }

  *((ULONG*)Address) = (ULONG)OldServiceAddress;//还原SSDT

  __asm{  
         mov  eax,cr0
    or   eax,10000h
    mov  cr0,eax
    sti
  }

  DbgPrint("Unhook");
}
2009-3-19 09:37
0
雪    币: 0
活跃值: (954)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
8
楼主ring3 inline hook 估计都没玩熟。。。

代理函数那边,参数有很多都不对!
2009-3-19 09:43
0
雪    币: 342
活跃值: (55)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
9
还是不行
提示:error LNK2001: unresolved external symbol "struct _SERVICE_DESCRIPTOR_TABLE * KeServiceDescriptorTable" (?KeServiceDescriptorTable@@3PAU_SERVICE_DESCRIPTOR_TABLE@@A)
2009-3-19 18:53
0
雪    币: 419
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
是我给你那代码?

DDK 2000 完全可以编译
2009-3-19 20:36
0
雪    币: 222
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
11
编译环境不对
2009-6-5 19:01
0
雪    币: 129
活跃值: (31)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
牛瓣......
2009-6-6 13:23
0
雪    币: 222
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
13
把cpp改C编译就会成功,堕落天使是用C写的,非cpp
2009-6-20 14:45
0
游客
登录 | 注册 方可回帖
返回
//