阅读:4625回复:17
难道就没有人给出个PspTerminateProcess具体的说法?
PspTerminateProcess怎么用
|
|
|
沙发#
发布于:2007-07-17 17:06
怎么用很简单的,怎么得到它倒是个麻烦事
在VISTA上是个thiscall,ECX=PEPROCESS,只有一个参数是退出码 |
|
板凳#
发布于:2007-07-18 14:17
PspTerminateProcess 函数 NTOSKRNL 没导出,得到它可以用查找特征码的方法或直接使用硬编码(要加版本检测). 这个函数的实现比较简单,在实际应用中可以模拟NT 源码自己写一个 PspTerminateProcess 函数来结束进程. 为了演示这个函数我写了个结束 explorer.exe 进程的示例.希望下面的代码对你有所帮助(由于只是演示 PspTerminateProcess 函数的用法,所以函数地址我用硬编码..).
#include "ntddk.h" #include "string.h" NTSTATUS NtQuerySystemInformation(ULONG SystemInformationClass, PVOID SystemInformation,ULONG SystemInformationLength,PULONG ReturnLength); NTSTATUS PsLookupProcessByProcessId(ULONG ProcessId,PEPROCESS *Process); typedef NTSTATUS (*PSPTERPROC) ( PEPROCESS Process, NTSTATUS ExitStatus ); PSPTERPROC MyPspTerminateProcess ; WCHAR expname[] = L"explorer.exe" ; struct _SYSTEM_THREADS { LARGE_INTEGER KernelTime; LARGE_INTEGER UserTime; LARGE_INTEGER CreateTime; ULONG WaitTime; PVOID StartAddress; CLIENT_ID ClientIs; KPRIORITY Priority; KPRIORITY BasePriority; ULONG ContextSwitchCount; ULONG ThreadState; KWAIT_REASON WaitReason; }; typedef struct _SYSTEM_PROCESSES { ULONG NextEntryDelta; ULONG ThreadCount; ULONG Reserved[6]; LARGE_INTEGER CreateTime; LARGE_INTEGER UserTime; LARGE_INTEGER KernelTime; UNICODE_STRING ProcessName; KPRIORITY BasePriority; ULONG ProcessId; ULONG InheritedFromProcessId; ULONG HandleCount; ULONG Reserved2[2]; VM_COUNTERS VmCounters; IO_COUNTERS IoCounters; //windows 2000 only struct _SYSTEM_THREADS Threads[1]; } SYSPROCESS,*PSYSPROCESS ; #define MAX_INFO_BUF_LEN 0x100000 VOID OnUnload(IN PDRIVER_OBJECT DriverObject) { DbgPrint("ROOTKIT: OnUnload called\n"); } NTSTATUS DriverEntry(IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath) { PEPROCESS process1; PSYSPROCESS plst; NTSTATUS status; PVOID p1; ULONG expid; char* procname; MyPspTerminateProcess =(PSPTERPROC)0x805d23a0; theDriverObject->DriverUnload = OnUnload; p1 = ExAllocatePool (PagedPool ,MAX_INFO_BUF_LEN); if((ULONG)p1 != 0) { status = NtQuerySystemInformation( 5, p1 , MAX_INFO_BUF_LEN , 0); if(status == STATUS_SUCCESS) { plst = (PSYSPROCESS)p1; while(plst) { procname = (char*)(plst -> ProcessName.Buffer); if(procname) if( _strnicmp (procname,(char*)expname,24) == 0) { expid = plst -> ProcessId; if( PsLookupProcessByProcessId(expid,&process1)==STATUS_SUCCESS) return MyPspTerminateProcess(process1,0); } if(plst -> NextEntryDelta) (char *)plst +=plst -> NextEntryDelta; else plst = NULL; } } } return STATUS_UNSUCCESSFUL; } |
|
地板#
发布于:2007-07-18 14:18
奇怪...
好好的代码,贴一下怎么成这样了... |
|
地下室#
发布于:2007-07-18 14:25
在 DDK2K3 下编译通过,SP2 下测试通过...
|
|
5楼#
发布于:2007-07-18 18:18
硬编码说?应该是5.1.2600.2853版本能够通过
|
|
驱动小牛
|
6楼#
发布于:2007-07-18 21:08
还是硬编码吧.
|
7楼#
发布于:2007-07-18 21:48
写的仓促,分配的内存忘记把它 FREE 了...
呵呵,这是完内核最低级的错误,我竟然也犯.....,汗............ |
|
8楼#
发布于:2007-07-19 12:31
怎么得到硬编码啊
|
|
|
9楼#
发布于:2007-07-21 14:11
windbg
|
|
10楼#
发布于:2007-07-23 17:41
PspTerminateProcess的函数实现看上去比较简单,从
EPROCESS结构里的ThreadListEntry列举进程的ETHREAD,然后调用PspTerminateThreadByPointer结束之。 但自己实现起来还是不容易,因为该死的EPROCESS结构2k,XP,NET都不一样,faint! |
|
11楼#
发布于:2007-07-23 18:17
PspTerminateThreadByPointer也很不够强,随便kdom一下就能让其失效
所以还是自己XX了 |
|
|
12楼#
发布于:2007-07-24 15:39
对乐,自己列举的话还得记得先用ExfAcquirePushLockShared()函数先Lock Process,然后ExfReleasePushLock()函数ReleaseLock,这两个该死的函数在IDA中能看见名字,却没有被导出,真是见鬼,又自己编吧,祝你们编得开心。
|
|
13楼#
发布于:2007-07-24 18:05
引用第11楼WQXNETQIQI于2007-07-23 18:17发表的 : 你的意思就是进程从PsActiveProcessList上摘除后,不能找到对应的EPROCESS,就没有办法进一步获取线程ID,因此就不能调用PspTerminateThreadByPointer来结束其所有的线程了? |
|
14楼#
发布于:2007-07-24 18:09
引用第13楼galihoo于2007-07-24 18:05发表的 : 哦..PsLookupProcessByProcessId好像是从PspCidTable上得到EPROCESS的 |
|
15楼#
发布于:2007-07-25 17:23
引用第12楼zjjmj2002于2007-07-24 15:39发表的 : 运行之前download symbol下来吧 哈哈 |
|
|
16楼#
发布于:2007-07-27 09:07
如函数所示,ExAcquirePushLockShared这两个函数是必须的。
不过俺闲着没事反了一下这两个函数,居然只有几十行代码,就自己比着写了一个,不过反正没有头文件也编译不了,就给个OBJ自己连接吧,使用前自己声明一下就可以了,ONLY FOR WINXP:) 本来想一鼓作气把PspTerminateThreadByPointer()给反了,没想到前面容易后面难,最后俺悲壮地被卡死在PspExitThread()上,KAO。大家还是自己搜吧,就在PsTerminateSystemThread里,应该不难? PETHREAD NTAPI PsGetNextProcessThread(IN PEPROCESS Process, IN PETHREAD Thread ) { PETHREAD FoundThread = NULL; PLIST_ENTRY ListHead, Entry; KeEnterCriticalRegion(); ExAcquirePushLockShared(&Process->ProcessLock); if (Thread) { Entry = Thread->ThreadListEntry.Flink; } else { Entry = Process->ThreadListHead.Flink; } ListHead = &Process->ThreadListHead; while (ListHead != Entry) { FoundThread = (PETHREAD)((ULONG)Entry - ThreadListEntry); if (ObReferenceObjectSafe(FoundThread)) break; FoundThread = NULL; Entry = Entry->Flink; } ExReleasePushLockShared(&Process->ProcessLock); KeLeaveCriticalRegion(); if (Thread) ObDereferenceObject(Thread); return FoundThread; } |
|
|
17楼#
发布于:2009-03-22 00:44
引用第2楼yangtengfei于2007-07-18 14:17发表的 : 一次就BSOD |
|