Studied for 1 days this ... MSDN isn't very clear.
NTSTATUS Pscreatesystemthread (
_out_ Phandle Threadhandle,
_in_ ULONG desiredaccess,
_in_opt_ Pobject_attributes Objectattributes,
_in_opt_ HANDLE ProcessHandle,
_out_opt_ pclient_id ClientId,
_in_ Pkstart_routine Startroutine,
_in_opt_ PVOID Startcontext
);
The function is used to create a system thread, the ProcessHandle parameter receives NULL, Ntcurrentprocess () (-1), or a process handle three cases can be ended with Psterminatesystemthread
Example:
[C + +]Plain Text view copy code
01 |
VOIDMyThread(PVOIDStartContext) |
03 |
PEPROCESS pp=IoGetCurrentProcess(); |
04 |
NTSTATUS status=PsTerminateSystemThread(0); |
06 |
if(status == STATUS_INVALID_PARAMETER) |
08 |
KdPrint(("not systemthread")); |
12 |
HANDLEOpenProcess(HANDLEProcessid) |
15 |
PEPROCESS Process = NULL; |
16 |
HANDLEhProcess = NULL; |
17 |
UNICODE_STRING Unicode; |
18 |
status = PsLookupProcessByProcessId(Processid, &Process); |
19 |
if(NT_SUCCESS(status))//判断进程号是否存在 |
21 |
RtlInitUnicodeString(&Unicode, L"PsProcessType"); |
22 |
//得到系统导出函数的地址和用户态的GetProcessAddress雷同 |
23 |
PsProcessType = (POBJECT_TYPE*)MmGetSystemRoutineAddress(&Unicode); |
26 |
status = ObOpenObjectByPointer(Process,0,NULL,PROCESS_ALL_ACCESS,(POBJECT_TYPE) * PsProcessType, |
27 |
KernelMode,&hProcess); |
28 |
if(NT_SUCCESS(status)) |
31 |
ObfDereferenceObject(Process); |
35 |
ObfDereferenceObject(Process); |
40 |
HANDLEoutthread1,,outthread2,outthread3,outthread4,hproc; |
42 |
PsCreateSystemThread(&outthread1,THREAD_ALL_ACCESS,NULL,NULL,NULL,MyThread,NULL); |
43 |
PsCreateSystemThread(&outthread2,THREAD_ALL_ACCESS,NULL,NtCurrentProcess(),NULL,MyThread,NULL); |
46 |
CLIENT_ID ci={(HANDLE)1472,0};//注意是进程ID! |
47 |
RtlZeroMemory(&oa,sizeof(oa)); |
49 |
ZwOpenProcess(&hproc,PROCESS_ALL_ACCESS,&oa,&ci); |
50 |
PsCreateSystemThread(&outthread3,THREAD_ALL_ACCESS,NULL,hproc,NULL,MyThread,NULL); |
52 |
hproc=OpenProcess((HANDLE)1472);//注意是进程ID! |
53 |
PsCreateSystemThread(&outthread4,THREAD_ALL_ACCESS,NULL,hproc,NULL,MyThread,NULL); |
The function creates a thread whose Pethrad property Crossthreadflags has a Ps_cross_thread_flags_system property, does not allow the thread to be created in suspend mode, and the other and ordinary ntcreatethread differ little!
However, in Microsoft's official source code, the Ps_cross_thread_flags_system attribute is systemthread, although the process it belongs to may be Explorer.exe
Https://www.0xaa55.com/forum.php?mod=viewthread&tid=1376&extra=page%3D6
About the Pscreatesystemthread function