标签:
PsActiveProcessHead的定义:
在windows系统中,所有的活动进程都是连在一起的,构成一个双链表,表头是全局变量PsActiveProcessHead,当一个进程被创建时,其ActiveProcessList域将被作为节点加入到此链表中;当进程被删除时,则从此链表中移除,如果windows需要枚举所有的进程,直接操纵此链表即可。
ULONG FindPsActiveProcessHead1() { //1.从KdEnableDebugger地址找到KdInitSystem地址 //nt!KdEnableDebugger 804f7810 //804f7837 6a00 push 0 //804f7839 6a00 push 0 //804f783b c605ecab558001 mov byte ptr [nt!PoHiberInProgress (8055abec)],1 //804f7842 e8f7951600 call nt!KdInitSystem (80660e3e) //804f7847 e8649a1600 call nt!KdpRestoreAllBreakpoints (806612b0) ULONG i; PCALL_CODE pCall; PUCHAR pKdInitSystem=NULL; PUCHAR p=(PUCHAR)GetExportFuncAddress(L"KdEnableDebugger"); KdPrint(("KdEnableDebugger地址=%x\n",p)); if (!p) { KdPrint(("获取KdEnableDebugger地址失败\n")); return 0; } for (i=0;i<100;i++,p++) { if ((*p==0x6a)&& (*(p+1)==0x00)&& (*(p+2)==0x6a)&& (*(p+3)==0x00)&& (*(p+4)==0xc6)&& (*(p+5)==0x05)&& (*(p+0xb)==0xe8)&& (*(p+0x10)==0xe8) ) { pCall=(PCALL_CODE)(p+0xb); pKdInitSystem=p+0xb+pCall->address+5; KdPrint(("KdInitSystem地址=%x\n",pKdInitSystem)); break; } } if (!pKdInitSystem) { KdPrint(("获取KdInitSystem地址失败\n")); return 0; } //2.从KdInitSystem地址找到KdDebuggerDataBlock地址 //nt!KdInitSystem 80660e3e //80660e8e 6890020000 push 290h //80660e93 68606b5480 push offset nt!KdDebuggerDataBlock (80546b60) //80660e98 be74926780 mov esi,offset nt!KdpDebuggerDataListHead (80679274) p=pKdInitSystem; for (i=0;i<100;i++,p++) { if ((*p==0x68)&& (*(p+5)==0x68)&& (*(p+0xA)==0xbe)) { pCall=(PCALL_CODE)(p+5); KdPrint(("KdDebuggerDataBlock地址=%x\n",pCall->address)); KdPrint(("PsActiveProcessHead地址=%x\n",((PKDDEBUGGER_DATA64)pCall->address)->PsActiveProcessHead)); return ((PKDDEBUGGER_DATA64)pCall->address)->PsActiveProcessHead; } } KdPrint(("获取KdDebuggerDataBlock地址失败\n")); return 0; }
NTSTATUS FindPsActiveProcessHead(ULONG *pPsActiveProcessHead) { PEPROCESS process; PLIST_ENTRY pList=NULL; NTSTATUS status=PsLookupProcessByProcessId((HANDLE)4,&process); if (!NT_SUCCESS(status)) { KdPrint(("获取process失败\n")); return status; } //xp _EPROCESS +0x088 ActiveProcessLinks : _LIST_ENTRY pList=(PLIST_ENTRY)((PUCHAR)process+0x88); KdPrint(("PsActiveProcessHead地址=%x\n",pList->Blink)); *pPsActiveProcessHead=(ULONG)pList->Blink; ObDereferenceObject(process); return status; }
ULONG FindPsActiveProcessHead3() { ULONG addr=*(PULONG)PsInitialSystemProcess; //xp _EPROCESS +0x088 ActiveProcessLinks : _LIST_ENTRY PLIST_ENTRY pList=(PLIST_ENTRY)(addr+0x88); KdPrint(("PsActiveProcessHead地址=%x\n",pList->Blink)); return (ULONG)pList->Blink; }
ULONG FindPsActiveProcessHead4() { PLIST_ENTRY pList; PKDDEBUGGER_DATA64 pKdDebuggerData; PDBGKD_GET_VERSION64 pKdVersionBlock=(PDBGKD_GET_VERSION64)(*(PULONG)(0xffdff000+0x34)); KdPrint(("获取到DebuggerDataList地址=%x\n",pKdVersionBlock->DebuggerDataList)); pList=(PLIST_ENTRY)pKdVersionBlock->DebuggerDataList; KdPrint(("pList->Flink=%x,pList->Blink地址=%x\n",pList->Flink,pList->Blink)); pKdDebuggerData=(PKDDEBUGGER_DATA64)pList->Flink; KdPrint(("PsActiveProcessHead地址=%x\n",pKdDebuggerData->PsActiveProcessHead)); return pKdDebuggerData->PsActiveProcessHead; }
ULONG FindPsActiveProcessHead5() { PLIST_ENTRY pList; DBGKD_GET_VERSION64 KdVersionBlock; PKDDEBUGGER_DATA64 pKdDebuggerData; ZwSystemDebugControl NtSystemDebugControl; NtSystemDebugControl=(ZwSystemDebugControl)GetSSDTAddrFromIndex(255); KdPrint(("NtSystemDebugControl函数地址=%x\n",NtSystemDebugControl)); NtSystemDebugControl(SysDbgSysGetVersion,NULL,0,&KdVersionBlock,sizeof(DBGKD_GET_VERSION64),NULL); KdPrint(("DebuggerDataList=%x\n",KdVersionBlock.DebuggerDataList)); pList=(PLIST_ENTRY)KdVersionBlock.DebuggerDataList; KdPrint(("获取到KdDebuggerDataBlock地址=%x\n",pList->Flink)); pKdDebuggerData=(PKDDEBUGGER_DATA64)pList->Flink; KdPrint(("PsActiveProcessHead地址=%x\n",pKdDebuggerData->PsActiveProcessHead)); return pKdDebuggerData->PsActiveProcessHead; }
驱动中获取PsActiveProcessHead变量地址的五种方法也可以获取KdpDebuggerDataListHead
标签:
原文地址:http://www.cnblogs.com/kuangke/p/5597020.html