修改内核服务描述表SSDT实现API HOOK(汇编版)

.386
.model flat, stdcall
option casemap:none

include JmDriver.inc

Target_NtOpenProcess  typedef proto :dword,:dword,:dword
PTarget_NtOpenProcess typedef ptr Target_NtOpenProcess

 


.data
dwFunctionIDs     dd           07Ah   ;NTOpenProcess
                  dd           00h


dwOldAddress      PTarget_NtOpenProcess            ?
                  dd            ?
                  dd            ?
                 

dwHookAddress     dd            _NtOpenProcess
                  dd            ?             

 

.code

 


_NtOpenProcess proc dwDesiredAccess:dword , bInheritHandle:dword ,dwProcessID:dword
        
           
  invoke dwOldAddress[0] , dwDesiredAccess , bInheritHandle , dwProcessID
 ret

_NtOpenProcess endp

 

 

Hook proc
   
   LOCAL @lpServiceTable:dword
   LOCAL @lplpFunc:dword
  
    mov  eax , KeServiceDescriptorTable ;现在eax指向ntosknrl.exe导出的SericeDescriptorTable
    m2m  @lpServiceTable , [eax]        ;@lpServiceTable 指向ntoskrnl.exe系统服务表
   
  
    cli
    mov  eax , cr0
    and  eax , not 10000h              ;去掉内存写保护
    mov  cr0 , eax

   
    xor ecx ,ecx
    .while TRUE
         mov eax , dwFunctionIDs[ecx*4]  ;函数ID
         .if eax == 0      
          .break                  
         .endif
        
         add eax , @lpServiceTable        ;
         m2m dwOldAddress[ecx*4] ,[eax]   ;保存目标函数地址。
         m2m [eax] , dwHookAddress[ecx*4] ;写入相应的钩子函数地址
         inc ecx
     
    .endw
   
   mov  eax,cr0
   or   eax,10000h          ;恢复内存写保护
   mov  cr0,eax
   sti

   
   
         
 
 ret

Hook endp


UnHook proc
        
   cli
   mov  eax , cr0
   and  eax , not 10000h    ;去掉内存写保护
   mov  cr0 , eax

 
   mov  eax,cr0
   or   eax,10000h          ;恢复内存写保护
   mov  cr0,eax
   sti

     
 ret

UnHook endp

 

DriverEntry proc pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING
    assume eax:ptr DRIVER_OBJECT
    mov eax , pDriverObject
    m2m [eax].DriverUnload , offset DriverUnload  ;注册驱动卸载函数
  
    invoke Hook
   
   
   
    mov eax , STATUS_SUCCESS
    ret

DriverEntry endp


DriverUnload proc
 invoke UnHook
 
 ret

DriverUnload endp

 

 

end DriverEntry

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值