-
-
[原创]Windows内核学习笔记之线程(上)
-
发表于: 2021-12-20 17:18 15206
-
在操作系统中,进程只是提供资源,它并没有执行指令的作用。真正来执行指令的是线程,线程是一个指令执行序列,它可以直接访问所属进程中的资源。每个进程至少要有一个线程,这样才可以使用进程的资源来执行各种指令,而每个线程在任一时刻一定属于某一特定的进程。
线程不仅仅是一个控制流,它还有更多的内容。线程的调用栈记录了它作为控制流的状态信息,包括每一层函数调用和返回指令地址。线程一定隶属于某个进程,其控制流可以访问这个进程中的资源,包括所有的内存数据以及系统分配给此进程的其他资源。一个进程可以有多个线程,由于这些线程隶属于同一进程,所以它们之间相互通信要方便很多,毕竟几乎所有的资源(不是全部)对它们来说都是共享的。因此,线程概念的引入有时候也称为轻量进程。
为了保存线程的各种信息,在用户层和内核层都有相应的数据结构用来存储线程的信息。
与描述进程用户空间信息的PEB类型,NT内核定义了线程环境块(TEB)来描述线程的用户空间信息,包括用户栈,异常处理,错误码,线程局部存储等,该结构定义如下:
其中NtTib的结构如下:
在用户层fs:[0]保存的就是TEB的地址,但由于TEB偏移0x18处的指针也是指针自己。所以,会在代码中看到fs:[0x18],此时获得的依然是TEB的地址,而fs:[0x30]获得的则是PEB的地址
与创建进程类似,当成功创建了一个线程的时候,Windows内核中就会创建相应的线程内核对象,该内核对象保存了线程的各种信息。
Windows内核的执行体层负责与管理策略相关的功能,而内核层(或微内核)实现了操作系统的核心机制,线程在这两个层上都有相应的数据结构。
保存在微内核层的KTHREAD是线程最基本的数据结构,每个KTHREAD对象都代表了一个线程,反之也成立,即每个线程都有一个KTHREAD对象。
由于在Windows中,线程是系统处理器调度的基本单元,而且线程调度是在内核层完成的,所以,KTHREAD的许多域都和Windows线程调度机制有关。
KTHREAD结构定义如下:
ETHREAD是保存在执行体的数据结构,它侧重于提供各自管理策略,同时为上层应用程序提供基本的功能接口。所以,在执行层的数据结构中,有些成员直接对应于上层应用程序中所看到的功能,该结构定义如下:
最简单的线程创建函数就是CreateThread,该函数可以在当前进程中创建一个线程。
可以看到该函数是通过调用CreateRemoteThread函数,而传入的第一个进程句柄参数通过使用-1来表示当前进程
在CreateRemoteThread中首先会对局部变量进程初始化
接下来需要调用BaseCreateStack来创建线程栈
调用BaseInitializeContext来初始化线程CONTEXT
通过系统调用NtCreateThread在内核中创建线程内核对象,此时是以挂起的方式来创建线程
调用CsrClientCallServer来给Windows子系统(Csrss)发送消息
判断是否带有CREATE_SUSPENDED标志,如果没有,则会调用NtResumeThread来恢复线程的执行
在NtCreateThread中会首先判断是否是内核模式传递的调用
如果是内核模式,则直接参数InitialTeb赋值给ebx
如果不是内核模式,就会对输出参数ThreadHandle, ClientId和输入参数ThreadContext以及InitialTeb进行可写检查
把传入的参数InitialTeb赋值给局部变量
调用PspCreateThread来完成创建,再次之前edx被清0,所以最后两个参数都为NULL
线程是属于进程的,所以参数中必须得有个进程句柄。参数ClientId和ThradHandle是用来返回CID和句柄的。参数ThreadContext用来给定一个线程的原始上下文,实际上就是各个寄存器的初值。另一个参数CreateSuspended则说明新创的线程是否要被挂起,等到对其调用NtResumeThread时才开始运行。
相比于NtCreateThread,PspCreateThread多了三个参数,这三个参数是为创建内核线程而设的,内核线程都属于系统初始进程PsInitialSystemProcess,但是这个进程没有句柄,所以只好使用EPROCESS结构指针ProcessPointer。同样,StartRoutine和StartContext也是用来给定内核线程的程序入口和上下文。非内核线程的程序入口是有ThreadContext寄存器中的EIP来决定的,所以对于来自用户空间的系统调用这三个参数都是NULL。
在PspCreateThraed中首先会判断是否存在StartRoutine,如果存在就会对局部变量var_PreviousMode赋值为0
如果不存在,则取出当前线程的PreviousMode赋值给局部变量
对局部变量进程赋值,判断是否存在进程句柄
如果存在进程句柄,就会调用ObReferenceObjectByHandle来获得进程EPROCESS,将其解析得到的EPROCESS赋给局部变量var_Process和寄存器ebx
如果不存在进程句柄,则会继续判断是否存在StartRoutine
如果不存在,则返回句柄错误的返回值,结束函数
如果存在则调用函数ObfReferenceObject来获得EPROCESS并将其赋值给局部变量var_Process
继续判断先前模式是否是内核模式
如果不是内核模式,则会判断是否是系统进程
如果是的话,则返回句柄错误
如果不是系统进程或者先前模式是内核模式,则会调用ObCreateObject来创建线程内核对象
将ETHREAD结构地址清0
为线程对象的一些成员赋值
调用ExCreateHandle在全局句柄表中插入线程对象
继续为线程ETHREAD对象赋值
获得进程的RundownProtect锁,以免再创建过程中进程被停掉
判断传入的ThreadContext是否为NULL
如果不为NULL,说明此次创建的是用户模式的进程,接下来就会调用MmCreateTeb来创建一个TEB并用InitialTeb来对其进行初始化
用ThreadContext中的Eip和eax为线程对象赋值
调用KeInitThread来初始化线程对象,此时第三个参数是PspUserThreadStartup函数的地址,第六个参数是ThreadContext
如果ThreadContext为NULL,则说明此次创建的是内核模式的线程,函数首先先对局部变量var_Teb清0以后,对线程对象的CrossThreadFlags位进行或操作,然后再用传入的StartRoutine来赋值线程对象中的StartAddress
接下来也是调用KeInitThread来初始化线程对象,但是此时第三个参数已经变成了PspSystemThreadStartup函数地址,第5个参数是StartContext
当KeInitThread函数返回的时候,就说明新创建的线程的状态是"已初始化"状态,接下来保存进程的活动线程到局部变量,随后将进程的活动线程数量加1
并且将新建的线程加入到进程的线程链表中
调用KeStartThread初始化剩余的域,尤其是跟调度相关的域,比如优先级,时限设置,处理器亲和性等等
判断传入的标志中是否有挂起标志
如果有就调用KeSuspendThread挂起线程
调用ObInsertObject将创建的线程插入到句柄表中
最后调用KeReadyThread让线程进入"就绪"状态
在执行体层上,线程终止函数是NtTerminateThread,而系统线程终止函数则是PsTerminateSystemThread,这两个函数最终都是通过调用PspTerminateThreadByPointer来完成操作的。
在该函数中,首先将当前线程结构体取出赋给esi,判断传入的线程句柄是否为NULL
如果为空,接下来取出当前线程对应的进程对象,判断进程对象是否有活跃线程
如果有活跃线程则跳转到loc_4ADB07调用PspTerminateThreadPointer来结束线程
如果传入的线程句柄不为NULL,则接下来判断线程句柄是否是当前线程句柄(-2)
如果是当前线程句柄就会跳转到上面说的loc_4ADB07地址结束线程
如果不是当前线程的句柄,接下来就会通过ObReferenceObjectByHandle来通过线程句柄获取线程对象
接着在调用PspTerminateThreadPointer来结束线程
PsTerminateSystemThread函数则非常简单,它就直接取出线程对象以后调用函数结束线程
该函数首先判断结束的线程的CrossTheadFlags是否等于0x40,以及要结束的线程是否是当前线程对象,如果都是的话就会调用PspExitThread来结束线程
kd> dt _TEB
nt!_TEB
+
0x000
NtTib : _NT_TIB
+
0x01c
EnvironmentPointer : Ptr32 Void
+
0x020
ClientId : _CLIENT_ID
+
0x028
ActiveRpcHandle : Ptr32 Void
+
0x02c
ThreadLocalStoragePointer : Ptr32 Void
+
0x030
ProcessEnvironmentBlock : Ptr32 _PEB
+
0x034
LastErrorValue : Uint4B
+
0x038
CountOfOwnedCriticalSections : Uint4B
+
0x03c
CsrClientThread : Ptr32 Void
+
0x040
Win32ThreadInfo : Ptr32 Void
+
0x044
User32Reserved : [
26
] Uint4B
+
0x0ac
UserReserved : [
5
] Uint4B
+
0x0c0
WOW32Reserved : Ptr32 Void
+
0x0c4
CurrentLocale : Uint4B
+
0x0c8
FpSoftwareStatusRegister : Uint4B
+
0x0cc
SystemReserved1 : [
54
] Ptr32 Void
+
0x1a4
ExceptionCode : Int4B
+
0x1a8
ActivationContextStack : _ACTIVATION_CONTEXT_STACK
+
0x1bc
SpareBytes1 : [
24
] UChar
+
0x1d4
GdiTebBatch : _GDI_TEB_BATCH
+
0x6b4
RealClientId : _CLIENT_ID
+
0x6bc
GdiCachedProcessHandle : Ptr32 Void
+
0x6c0
GdiClientPID : Uint4B
+
0x6c4
GdiClientTID : Uint4B
+
0x6c8
GdiThreadLocalInfo : Ptr32 Void
+
0x6cc
Win32ClientInfo : [
62
] Uint4B
+
0x7c4
glDispatchTable : [
233
] Ptr32 Void
+
0xb68
glReserved1 : [
29
] Uint4B
+
0xbdc
glReserved2 : Ptr32 Void
+
0xbe0
glSectionInfo : Ptr32 Void
+
0xbe4
glSection : Ptr32 Void
+
0xbe8
glTable : Ptr32 Void
+
0xbec
glCurrentRC : Ptr32 Void
+
0xbf0
glContext : Ptr32 Void
+
0xbf4
LastStatusValue : Uint4B
+
0xbf8
StaticUnicodeString : _UNICODE_STRING
+
0xc00
StaticUnicodeBuffer : [
261
] Uint2B
+
0xe0c
DeallocationStack : Ptr32 Void
+
0xe10
TlsSlots : [
64
] Ptr32 Void
+
0xf10
TlsLinks : _LIST_ENTRY
+
0xf18
Vdm : Ptr32 Void
+
0xf1c
ReservedForNtRpc : Ptr32 Void
+
0xf20
DbgSsReserved : [
2
] Ptr32 Void
+
0xf28
HardErrorsAreDisabled : Uint4B
+
0xf2c
Instrumentation : [
16
] Ptr32 Void
+
0xf6c
WinSockData : Ptr32 Void
+
0xf70
GdiBatchCount : Uint4B
+
0xf74
InDbgPrint : UChar
+
0xf75
FreeStackOnTermination : UChar
+
0xf76
HasFiberData : UChar
+
0xf77
IdealProcessor : UChar
+
0xf78
Spare3 : Uint4B
+
0xf7c
ReservedForPerf : Ptr32 Void
+
0xf80
ReservedForOle : Ptr32 Void
+
0xf84
WaitingOnLoaderLock : Uint4B
+
0xf88
Wx86Thread : _Wx86ThreadState
+
0xf94
TlsExpansionSlots : Ptr32 Ptr32 Void
+
0xf98
ImpersonationLocale : Uint4B
+
0xf9c
IsImpersonating : Uint4B
+
0xfa0
NlsCache : Ptr32 Void
+
0xfa4
pShimData : Ptr32 Void
+
0xfa8
HeapVirtualAffinity : Uint4B
+
0xfac
CurrentTransactionHandle : Ptr32 Void
+
0xfb0
ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME
+
0xfb4
SafeThunkCall : UChar
+
0xfb5
BooleanSpare : [
3
] UChar
kd> dt _TEB
nt!_TEB
+
0x000
NtTib : _NT_TIB
+
0x01c
EnvironmentPointer : Ptr32 Void
+
0x020
ClientId : _CLIENT_ID
+
0x028
ActiveRpcHandle : Ptr32 Void
+
0x02c
ThreadLocalStoragePointer : Ptr32 Void
+
0x030
ProcessEnvironmentBlock : Ptr32 _PEB
+
0x034
LastErrorValue : Uint4B
+
0x038
CountOfOwnedCriticalSections : Uint4B
+
0x03c
CsrClientThread : Ptr32 Void
+
0x040
Win32ThreadInfo : Ptr32 Void
+
0x044
User32Reserved : [
26
] Uint4B
+
0x0ac
UserReserved : [
5
] Uint4B
+
0x0c0
WOW32Reserved : Ptr32 Void
+
0x0c4
CurrentLocale : Uint4B
+
0x0c8
FpSoftwareStatusRegister : Uint4B
+
0x0cc
SystemReserved1 : [
54
] Ptr32 Void
+
0x1a4
ExceptionCode : Int4B
+
0x1a8
ActivationContextStack : _ACTIVATION_CONTEXT_STACK
+
0x1bc
SpareBytes1 : [
24
] UChar
+
0x1d4
GdiTebBatch : _GDI_TEB_BATCH
+
0x6b4
RealClientId : _CLIENT_ID
+
0x6bc
GdiCachedProcessHandle : Ptr32 Void
+
0x6c0
GdiClientPID : Uint4B
+
0x6c4
GdiClientTID : Uint4B
+
0x6c8
GdiThreadLocalInfo : Ptr32 Void
+
0x6cc
Win32ClientInfo : [
62
] Uint4B
+
0x7c4
glDispatchTable : [
233
] Ptr32 Void
+
0xb68
glReserved1 : [
29
] Uint4B
+
0xbdc
glReserved2 : Ptr32 Void
+
0xbe0
glSectionInfo : Ptr32 Void
+
0xbe4
glSection : Ptr32 Void
+
0xbe8
glTable : Ptr32 Void
+
0xbec
glCurrentRC : Ptr32 Void
+
0xbf0
glContext : Ptr32 Void
+
0xbf4
LastStatusValue : Uint4B
+
0xbf8
StaticUnicodeString : _UNICODE_STRING
+
0xc00
StaticUnicodeBuffer : [
261
] Uint2B
+
0xe0c
DeallocationStack : Ptr32 Void
+
0xe10
TlsSlots : [
64
] Ptr32 Void
+
0xf10
TlsLinks : _LIST_ENTRY
+
0xf18
Vdm : Ptr32 Void
+
0xf1c
ReservedForNtRpc : Ptr32 Void
+
0xf20
DbgSsReserved : [
2
] Ptr32 Void
+
0xf28
HardErrorsAreDisabled : Uint4B
+
0xf2c
Instrumentation : [
16
] Ptr32 Void
+
0xf6c
WinSockData : Ptr32 Void
+
0xf70
GdiBatchCount : Uint4B
+
0xf74
InDbgPrint : UChar
+
0xf75
FreeStackOnTermination : UChar
+
0xf76
HasFiberData : UChar
+
0xf77
IdealProcessor : UChar
+
0xf78
Spare3 : Uint4B
+
0xf7c
ReservedForPerf : Ptr32 Void
+
0xf80
ReservedForOle : Ptr32 Void
+
0xf84
WaitingOnLoaderLock : Uint4B
+
0xf88
Wx86Thread : _Wx86ThreadState
+
0xf94
TlsExpansionSlots : Ptr32 Ptr32 Void
+
0xf98
ImpersonationLocale : Uint4B
+
0xf9c
IsImpersonating : Uint4B
+
0xfa0
NlsCache : Ptr32 Void
+
0xfa4
pShimData : Ptr32 Void
+
0xfa8
HeapVirtualAffinity : Uint4B
+
0xfac
CurrentTransactionHandle : Ptr32 Void
+
0xfb0
ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME
+
0xfb4
SafeThunkCall : UChar
+
0xfb5
BooleanSpare : [
3
] UChar
偏移 | 名称 | 作用 |
---|---|---|
0x000 | NtTib | 包含异常,线程栈等信息 |
0x020 | ClientId | 线程所属进程的PID |
0x030 | ProcessEnvironmentPointer | 保存了进程PEB地址 |
kd> dt _NT_TIB
ntdll!_NT_TIB
+
0x000
ExceptionList : Ptr32 _EXCEPTION_REGISTRATION_RECORD
+
0x004
StackBase : Ptr32 Void
+
0x008
StackLimit : Ptr32 Void
+
0x00c
SubSystemTib : Ptr32 Void
+
0x010
FiberData : Ptr32 Void
+
0x010
Version : Uint4B
+
0x014
ArbitraryUserPointer : Ptr32 Void
+
0x018
Self : Ptr32 _NT_TIB
kd> dt _NT_TIB
ntdll!_NT_TIB
+
0x000
ExceptionList : Ptr32 _EXCEPTION_REGISTRATION_RECORD
+
0x004
StackBase : Ptr32 Void
+
0x008
StackLimit : Ptr32 Void
+
0x00c
SubSystemTib : Ptr32 Void
+
0x010
FiberData : Ptr32 Void
+
0x010
Version : Uint4B
+
0x014
ArbitraryUserPointer : Ptr32 Void
+
0x018
Self : Ptr32 _NT_TIB
偏移 | 名称 | 作用 |
---|---|---|
0x000 | ExceptionList | 执行当前线程用户异常链表 |
0x004 | StackBase | 用户栈基址 |
0x008 | StackLimit | 用户栈边界 |
0x018 | Self | 指向本身NtTib地址 |
kd> dt _KTHREAD
nt!_KTHREAD
+
0x000
Header : _DISPATCHER_HEADER
+
0x010
MutantListHead : _LIST_ENTRY
+
0x018
InitialStack : Ptr32 Void
+
0x01c
StackLimit : Ptr32 Void
+
0x020
Teb : Ptr32 Void
+
0x024
TlsArray : Ptr32 Void
+
0x028
KernelStack : Ptr32 Void
+
0x02c
DebugActive : UChar
+
0x02d
State : UChar
+
0x02e
Alerted : [
2
] UChar
+
0x030
Iopl : UChar
+
0x031
NpxState : UChar
+
0x032
Saturation : Char
+
0x033
Priority : Char
+
0x034
ApcState : _KAPC_STATE
+
0x04c
ContextSwitches : Uint4B
+
0x050
IdleSwapBlock : UChar
+
0x051
VdmSafe : UChar
+
0x052
Spare0 : [
2
] UChar
+
0x054
WaitStatus : Int4B
+
0x058
WaitIrql : UChar
+
0x059
WaitMode : Char
+
0x05a
WaitNext : UChar
+
0x05b
WaitReason : UChar
+
0x05c
WaitBlockList : Ptr32 _KWAIT_BLOCK
+
0x060
WaitListEntry : _LIST_ENTRY
+
0x060
SwapListEntry : _SINGLE_LIST_ENTRY
+
0x068
WaitTime : Uint4B
+
0x06c
BasePriority : Char
+
0x06d
DecrementCount : UChar
+
0x06e
PriorityDecrement : Char
+
0x06f
Quantum : Char
+
0x070
WaitBlock : [
4
] _KWAIT_BLOCK
+
0x0d0
LegoData : Ptr32 Void
+
0x0d4
KernelApcDisable : Uint4B
+
0x0d8
UserAffinity : Uint4B
+
0x0dc
SystemAffinityActive : UChar
+
0x0dd
PowerState : UChar
+
0x0de
NpxIrql : UChar
+
0x0df
InitialNode : UChar
+
0x0e0
ServiceTable : Ptr32 Void
+
0x0e4
Queue : Ptr32 _KQUEUE
+
0x0e8
ApcQueueLock : Uint4B
+
0x0f0
Timer : _KTIMER
+
0x118
QueueListEntry : _LIST_ENTRY
+
0x120
SoftAffinity : Uint4B
+
0x124
Affinity : Uint4B
+
0x128
Preempted : UChar
+
0x129
ProcessReadyQueue : UChar
+
0x12a
KernelStackResident : UChar
+
0x12b
NextProcessor : UChar
+
0x12c
CallbackStack : Ptr32 Void
+
0x130
Win32Thread : Ptr32 Void
+
0x134
TrapFrame : Ptr32 _KTRAP_FRAME
+
0x138
ApcStatePointer : [
2
] Ptr32 _KAPC_STATE
+
0x140
PreviousMode : Char
+
0x141
EnableStackSwap : UChar
+
0x142
LargeStack : UChar
+
0x143
ResourceIndex : UChar
+
0x144
KernelTime : Uint4B
+
0x148
UserTime : Uint4B
+
0x14c
SavedApcState : _KAPC_STATE
+
0x164
Alertable : UChar
+
0x165
ApcStateIndex : UChar
+
0x166
ApcQueueable : UChar
+
0x167
AutoAlignment : UChar
+
0x168
StackBase : Ptr32 Void
+
0x16c
SuspendApc : _KAPC
+
0x19c
SuspendSemaphore : _KSEMAPHORE
+
0x1b0
ThreadListEntry : _LIST_ENTRY
+
0x1b8
FreezeCount : Char
+
0x1b9
SuspendCount : Char
+
0x1ba
IdealProcessor : UChar
+
0x1bb
DisableBoost : UChar
kd> dt _KTHREAD
nt!_KTHREAD
+
0x000
Header : _DISPATCHER_HEADER
+
0x010
MutantListHead : _LIST_ENTRY
+
0x018
InitialStack : Ptr32 Void
+
0x01c
StackLimit : Ptr32 Void
+
0x020
Teb : Ptr32 Void
+
0x024
TlsArray : Ptr32 Void
+
0x028
KernelStack : Ptr32 Void
+
0x02c
DebugActive : UChar
+
0x02d
State : UChar
+
0x02e
Alerted : [
2
] UChar
+
0x030
Iopl : UChar
+
0x031
NpxState : UChar
+
0x032
Saturation : Char
+
0x033
Priority : Char
+
0x034
ApcState : _KAPC_STATE
+
0x04c
ContextSwitches : Uint4B
+
0x050
IdleSwapBlock : UChar
+
0x051
VdmSafe : UChar
+
0x052
Spare0 : [
2
] UChar
+
0x054
WaitStatus : Int4B
+
0x058
WaitIrql : UChar
+
0x059
WaitMode : Char
+
0x05a
WaitNext : UChar
+
0x05b
WaitReason : UChar
+
0x05c
WaitBlockList : Ptr32 _KWAIT_BLOCK
+
0x060
WaitListEntry : _LIST_ENTRY
+
0x060
SwapListEntry : _SINGLE_LIST_ENTRY
+
0x068
WaitTime : Uint4B
+
0x06c
BasePriority : Char
+
0x06d
DecrementCount : UChar
+
0x06e
PriorityDecrement : Char
+
0x06f
Quantum : Char
+
0x070
WaitBlock : [
4
] _KWAIT_BLOCK
+
0x0d0
LegoData : Ptr32 Void
+
0x0d4
KernelApcDisable : Uint4B
+
0x0d8
UserAffinity : Uint4B
+
0x0dc
SystemAffinityActive : UChar
+
0x0dd
PowerState : UChar
+
0x0de
NpxIrql : UChar
+
0x0df
InitialNode : UChar
+
0x0e0
ServiceTable : Ptr32 Void
+
0x0e4
Queue : Ptr32 _KQUEUE
+
0x0e8
ApcQueueLock : Uint4B
+
0x0f0
Timer : _KTIMER
+
0x118
QueueListEntry : _LIST_ENTRY
+
0x120
SoftAffinity : Uint4B
+
0x124
Affinity : Uint4B
+
0x128
Preempted : UChar
+
0x129
ProcessReadyQueue : UChar
+
0x12a
KernelStackResident : UChar
+
0x12b
NextProcessor : UChar
+
0x12c
CallbackStack : Ptr32 Void
+
0x130
Win32Thread : Ptr32 Void
+
0x134
TrapFrame : Ptr32 _KTRAP_FRAME
+
0x138
ApcStatePointer : [
2
] Ptr32 _KAPC_STATE
+
0x140
PreviousMode : Char
+
0x141
EnableStackSwap : UChar
+
0x142
LargeStack : UChar
+
0x143
ResourceIndex : UChar
+
0x144
KernelTime : Uint4B
+
0x148
UserTime : Uint4B
+
0x14c
SavedApcState : _KAPC_STATE
+
0x164
Alertable : UChar
+
0x165
ApcStateIndex : UChar
+
0x166
ApcQueueable : UChar
+
0x167
AutoAlignment : UChar
+
0x168
StackBase : Ptr32 Void
+
0x16c
SuspendApc : _KAPC
+
0x19c
SuspendSemaphore : _KSEMAPHORE
+
0x1b0
ThreadListEntry : _LIST_ENTRY
+
0x1b8
FreezeCount : Char
+
0x1b9
SuspendCount : Char
+
0x1ba
IdealProcessor : UChar
+
0x1bb
DisableBoost : UChar
偏移 | 名称 | 作用 |
---|---|---|
0x000 | Header | 说明了内核层的线程对象是一个分发器对象,线程可以被等待,当线程结束时,在该对象上的等待可被满足 |
0x018 | InitialStack | 记录了原始栈的位置(高地址) |
0x01C | StackLimit | 记录了栈的低地址 |
0x020 | Teb | 指向线程的TEB地址 |
0x028 | KernelStack | 记录了真正内核调用栈的开始位置,由于在内核栈的顶部区域还记录了浮点处理器保存区和一个异常陷阱帧,所以,KernelStack的位置比InitialStack要低一些 |
0x02C | DedugActive | 如果值为-1不能使用调试寄存器 |
0x02D | State | 反映当前线程的状态 |
0x030 | Priority | 说明线程优先级,这里是指它的动态优先级,即执行过程中可能由于某些原因而调整过的优先级 |
0x034 | ApcState | 指定一个线程的APC信息 |
0x06C | BasePriority | 线程的静态优先级,其初始值是所属进程的BasePriority值,以后可通过KeSetBasePriorityThread函数重新设定 |
0x70 | WaitBlock | 指定等待的对象 |
0x0E0 | ServiceTable | 指向系统服务表基址 |
0x0E8 | ApcQueueable | 自旋锁,用户保护APC |
0x134 | TrapFrame | 线程中最关键的部分,记录了控制流状态 |
0x138 | ApcStatePointer | 两个元数的数组,指向KAPC_STATE指针,两个元数分别指向线程对象的ApcState和SavedApcState |
0x140 | PreviousMode | 用于内核函数判断程序是用户层调用还是内核层调用 |
0x14C | SavedApcState | 保存的APC |
0x164 | Alertable | 说明一个线程是否可以被唤醒 |
0x165 | ApcStateIndex | 索引值,表明当前APC状态在ApcStatePointer域中的索引 |
0x168 | StateBase | 记录当前栈的基址。当线程初始化时,InitialStack和StackBase是相等的 |
0x1B0 | ThreadListEntry | 双向链表,将一个进程中的所有线程全部连接起来 |
kd> dt _ETHREAD
nt!_ETHREAD
+
0x000
Tcb : _KTHREAD
+
0x1c0
CreateTime : _LARGE_INTEGER
+
0x1c0
NestedFaultCount : Pos
0
,
2
Bits
+
0x1c0
ApcNeeded : Pos
2
,
1
Bit
+
0x1c8
ExitTime : _LARGE_INTEGER
+
0x1c8
LpcReplyChain : _LIST_ENTRY
+
0x1c8
KeyedWaitChain : _LIST_ENTRY
+
0x1d0
ExitStatus : Int4B
+
0x1d0
OfsChain : Ptr32 Void
+
0x1d4
PostBlockList : _LIST_ENTRY
+
0x1dc
TerminationPort : Ptr32 _TERMINATION_PORT
+
0x1dc
ReaperLink : Ptr32 _ETHREAD
+
0x1dc
KeyedWaitValue : Ptr32 Void
+
0x1e0
ActiveTimerListLock : Uint4B
+
0x1e4
ActiveTimerListHead : _LIST_ENTRY
+
0x1ec
Cid : _CLIENT_ID
+
0x1f4
LpcReplySemaphore : _KSEMAPHORE
+
0x1f4
KeyedWaitSemaphore : _KSEMAPHORE
+
0x208
LpcReplyMessage : Ptr32 Void
+
0x208
LpcWaitingOnPort : Ptr32 Void
+
0x20c
ImpersonationInfo : Ptr32 _PS_IMPERSONATION_INFORMATION
+
0x210
IrpList : _LIST_ENTRY
+
0x218
TopLevelIrp : Uint4B
+
0x21c
DeviceToVerify : Ptr32 _DEVICE_OBJECT
+
0x220
ThreadsProcess : Ptr32 _EPROCESS
+
0x224
StartAddress : Ptr32 Void
+
0x228
Win32StartAddress : Ptr32 Void
+
0x228
LpcReceivedMessageId : Uint4B
+
0x22c
ThreadListEntry : _LIST_ENTRY
+
0x234
RundownProtect : _EX_RUNDOWN_REF
+
0x238
ThreadLock : _EX_PUSH_LOCK
+
0x23c
LpcReplyMessageId : Uint4B
+
0x240
ReadClusterSize : Uint4B
+
0x244
GrantedAccess : Uint4B
+
0x248
CrossThreadFlags : Uint4B
+
0x248
Terminated : Pos
0
,
1
Bit
+
0x248
DeadThread : Pos
1
,
1
Bit
+
0x248
HideFromDebugger : Pos
2
,
1
Bit
+
0x248
ActiveImpersonationInfo : Pos
3
,
1
Bit
+
0x248
SystemThread : Pos
4
,
1
Bit
+
0x248
HardErrorsAreDisabled : Pos
5
,
1
Bit
+
0x248
BreakOnTermination : Pos
6
,
1
Bit
+
0x248
SkipCreationMsg : Pos
7
,
1
Bit
+
0x248
SkipTerminationMsg : Pos
8
,
1
Bit
+
0x24c
SameThreadPassiveFlags : Uint4B
+
0x24c
ActiveExWorker : Pos
0
,
1
Bit
+
0x24c
ExWorkerCanWaitUser : Pos
1
,
1
Bit
+
0x24c
MemoryMaker : Pos
2
,
1
Bit
+
0x250
SameThreadApcFlags : Uint4B
+
0x250
LpcReceivedMsgIdValid : Pos
0
,
1
Bit
+
0x250
LpcExitThreadCalled : Pos
1
,
1
Bit
+
0x250
AddressSpaceOwner : Pos
2
,
1
Bit
+
0x254
ForwardClusterOnly : UChar
+
0x255
DisablePageFaultClustering : UChar
+
0x258
KernelStackReference : Uint4B
kd> dt _ETHREAD
nt!_ETHREAD
+
0x000
Tcb : _KTHREAD
+
0x1c0
CreateTime : _LARGE_INTEGER
+
0x1c0
NestedFaultCount : Pos
0
,
2
Bits
+
0x1c0
ApcNeeded : Pos
2
,
1
Bit
+
0x1c8
ExitTime : _LARGE_INTEGER
+
0x1c8
LpcReplyChain : _LIST_ENTRY
+
0x1c8
KeyedWaitChain : _LIST_ENTRY
+
0x1d0
ExitStatus : Int4B
+
0x1d0
OfsChain : Ptr32 Void
+
0x1d4
PostBlockList : _LIST_ENTRY
+
0x1dc
TerminationPort : Ptr32 _TERMINATION_PORT
+
0x1dc
ReaperLink : Ptr32 _ETHREAD
+
0x1dc
KeyedWaitValue : Ptr32 Void
+
0x1e0
ActiveTimerListLock : Uint4B
+
0x1e4
ActiveTimerListHead : _LIST_ENTRY
+
0x1ec
Cid : _CLIENT_ID
+
0x1f4
LpcReplySemaphore : _KSEMAPHORE
+
0x1f4
KeyedWaitSemaphore : _KSEMAPHORE
+
0x208
LpcReplyMessage : Ptr32 Void
+
0x208
LpcWaitingOnPort : Ptr32 Void
+
0x20c
ImpersonationInfo : Ptr32 _PS_IMPERSONATION_INFORMATION
+
0x210
IrpList : _LIST_ENTRY
+
0x218
TopLevelIrp : Uint4B
+
0x21c
DeviceToVerify : Ptr32 _DEVICE_OBJECT
+
0x220
ThreadsProcess : Ptr32 _EPROCESS
+
0x224
StartAddress : Ptr32 Void
+
0x228
Win32StartAddress : Ptr32 Void
+
0x228
LpcReceivedMessageId : Uint4B
+
0x22c
ThreadListEntry : _LIST_ENTRY
+
0x234
RundownProtect : _EX_RUNDOWN_REF
+
0x238
ThreadLock : _EX_PUSH_LOCK
+
0x23c
LpcReplyMessageId : Uint4B
+
0x240
ReadClusterSize : Uint4B
+
0x244
GrantedAccess : Uint4B
+
0x248
CrossThreadFlags : Uint4B
+
0x248
Terminated : Pos
0
,
1
Bit
+
0x248
DeadThread : Pos
1
,
1
Bit
+
0x248
HideFromDebugger : Pos
2
,
1
Bit
+
0x248
ActiveImpersonationInfo : Pos
3
,
1
Bit
+
0x248
SystemThread : Pos
4
,
1
Bit
+
0x248
HardErrorsAreDisabled : Pos
5
,
1
Bit
+
0x248
BreakOnTermination : Pos
6
,
1
Bit
+
0x248
SkipCreationMsg : Pos
7
,
1
Bit
+
0x248
SkipTerminationMsg : Pos
8
,
1
Bit
+
0x24c
SameThreadPassiveFlags : Uint4B
+
0x24c
ActiveExWorker : Pos
0
,
1
Bit
+
0x24c
ExWorkerCanWaitUser : Pos
1
,
1
Bit
+
0x24c
MemoryMaker : Pos
2
,
1
Bit
+
0x250
SameThreadApcFlags : Uint4B
+
0x250
LpcReceivedMsgIdValid : Pos
0
,
1
Bit
+
0x250
LpcExitThreadCalled : Pos
1
,
1
Bit
+
0x250
AddressSpaceOwner : Pos
2
,
1
Bit
+
0x254
ForwardClusterOnly : UChar
+
0x255
DisablePageFaultClustering : UChar
+
0x258
KernelStackReference : Uint4B
偏移 | 名称 | 作用 |
---|---|---|
0x000 | Tcb | 内嵌的KTHREAD结构体 |
0x1D0 | ExitStatus | 线程退出状态 |
0x1EC | Cid | 线程ID |
0x220 | ThreadsProcess | 指向线程所属的进程 |
0x22C | ThreadListEntry | 双向链表,一个进程中的所有链表都通过该链表进行连接 |
.text:
7C8106D7
; HANDLE __stdcall CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
.text:
7C8106D7
public _CreateThread@
24
.text:
7C8106D7
_CreateThread@
24
proc near ; DATA XREF: .text:off_7C802654↑o
.text:
7C8106D7
.text:
7C8106D7
lpThreadAttributes
=
dword ptr
8
.text:
7C8106D7
dwStackSize
=
dword ptr
0Ch
.text:
7C8106D7
lpStartAddress
=
dword ptr
10h
.text:
7C8106D7
lpParameter
=
dword ptr
14h
.text:
7C8106D7
dwCreationFlags
=
dword ptr
18h
.text:
7C8106D7
lpThreadId
=
dword ptr
1Ch
.text:
7C8106D7
.text:
7C8106D7
mov edi, edi
.text:
7C8106D9
push ebp
.text:
7C8106DA
mov ebp, esp
.text:
7C8106DC
push [ebp
+
lpThreadId] ; lpThreadId
.text:
7C8106DF
push [ebp
+
dwCreationFlags] ; dwCreationFlags
.text:
7C8106E2
push [ebp
+
lpParameter] ; lpParameter
.text:
7C8106E5
push [ebp
+
lpStartAddress] ; lpStartAddress
.text:
7C8106E8
push [ebp
+
dwStackSize] ; dwStackSize
.text:
7C8106EB
push [ebp
+
lpThreadAttributes] ; lpThreadAttributes
.text:
7C8106EE
push
0FFFFFFFFh
; 当前进程
.text:
7C8106F0
call _CreateRemoteThread@
28
; CreateRemoteThread(x,x,x,x,x,x,x)
.text:
7C8106F5
pop ebp
.text:
7C8106F6
retn
18h
.text:
7C8106F6
_CreateThread@
24
endp
.text:
7C8106D7
; HANDLE __stdcall CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
.text:
7C8106D7
public _CreateThread@
24
.text:
7C8106D7
_CreateThread@
24
proc near ; DATA XREF: .text:off_7C802654↑o
.text:
7C8106D7
.text:
7C8106D7
lpThreadAttributes
=
dword ptr
8
.text:
7C8106D7
dwStackSize
=
dword ptr
0Ch
.text:
7C8106D7
lpStartAddress
=
dword ptr
10h
.text:
7C8106D7
lpParameter
=
dword ptr
14h
.text:
7C8106D7
dwCreationFlags
=
dword ptr
18h
.text:
7C8106D7
lpThreadId
=
dword ptr
1Ch
.text:
7C8106D7
.text:
7C8106D7
mov edi, edi
.text:
7C8106D9
push ebp
.text:
7C8106DA
mov ebp, esp
.text:
7C8106DC
push [ebp
+
lpThreadId] ; lpThreadId
.text:
7C8106DF
push [ebp
+
dwCreationFlags] ; dwCreationFlags
.text:
7C8106E2
push [ebp
+
lpParameter] ; lpParameter
.text:
7C8106E5
push [ebp
+
lpStartAddress] ; lpStartAddress
.text:
7C8106E8
push [ebp
+
dwStackSize] ; dwStackSize
.text:
7C8106EB
push [ebp
+
lpThreadAttributes] ; lpThreadAttributes
.text:
7C8106EE
push
0FFFFFFFFh
; 当前进程
.text:
7C8106F0
call _CreateRemoteThread@
28
; CreateRemoteThread(x,x,x,x,x,x,x)
.text:
7C8106F5
pop ebp
.text:
7C8106F6
retn
18h
.text:
7C8106F6
_CreateThread@
24
endp
.text:
7C8104CC
; HANDLE __stdcall CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
.text:
7C8104CC
public _CreateRemoteThread@
28
.text:
7C8104CC
_CreateRemoteThread@
28
proc near ; CODE XREF: CreateThread(x,x,x,x,x,x)
+
19
↓p
.text:
7C8104CC
; BaseCreateThreadPoolThread(x,x,x)
+
3F
↓p
.text:
7C8104CC
; DATA XREF: ...
.text:
7C8104CC
.text:
7C8104CC
var_420
=
byte ptr
-
420h
.text:
7C8104CC
ThreadInformation
=
byte ptr
-
408h
.text:
7C8104CC
Teb
=
dword ptr
-
404h
.text:
7C8104CC
Cookie
=
dword ptr
-
3ECh
.text:
7C8104CC
var_3E8
=
dword ptr
-
3E8h
.text:
7C8104CC
SuspendCount
=
dword ptr
-
3E4h
.text:
7C8104CC
UserStack
=
_INITIAL_TEB ptr
-
3E0h
.text:
7C8104CC
var_lpParameter
=
dword ptr
-
3CCh
.text:
7C8104CC
var_lpThreadId
=
dword ptr
-
3C8h
.text:
7C8104CC
ClientId
=
_CLIENT_ID ptr
-
3C4h
.text:
7C8104CC
ProcessHandle
=
dword ptr
-
3BCh
.text:
7C8104CC
pvBuffer
=
dword ptr
-
3B8h
.text:
7C8104CC
var_3B4
=
byte ptr
-
3B4h
.text:
7C8104CC
ThreadHandle
=
dword ptr
-
3B0h
.text:
7C8104CC
ExitStatus
=
dword ptr
-
3ACh
.text:
7C8104CC
ThreadContext
=
CONTEXT ptr
-
3A8h
.text:
7C8104CC
ApiMessage
=
byte ptr
-
0DCh
.text:
7C8104CC
var_BC
=
dword ptr
-
0BCh
.text:
7C8104CC
var_ThreadHandle
=
dword ptr
-
0B4h
.text:
7C8104CC
var_UniqueProcess
=
dword ptr
-
0B0h
.text:
7C8104CC
var_UniqueThread
=
dword ptr
-
0ACh
.text:
7C8104CC
var_Cookie
=
dword ptr
-
1Ch
.text:
7C8104CC
ms_exc
=
CPPEH_RECORD ptr
-
18h
.text:
7C8104CC
hProcess
=
dword ptr
8
.text:
7C8104CC
lpThreadAttributes
=
dword ptr
0Ch
.text:
7C8104CC
dwStackSize
=
dword ptr
10h
.text:
7C8104CC
lpStartAddress
=
dword ptr
14h
.text:
7C8104CC
lpParameter
=
dword ptr
18h
.text:
7C8104CC
dwCreationFlags
=
dword ptr
1Ch
.text:
7C8104CC
lpThreadId
=
dword ptr
20h
.text:
7C8104CC
push
410h
.text:
7C8104D1
push offset stru_7C8106A8
.text:
7C8104D6
call __SEH_prolog
.text:
7C8104DB
mov eax, ___security_cookie
.text:
7C8104E0
mov [ebp
+
var_Cookie], eax
.text:
7C8104E3
mov ecx, [ebp
+
hProcess] ; 将进程句柄赋给ecx
.text:
7C8104E6
mov [ebp
+
ProcessHandle], ecx
.text:
7C8104EC
mov esi, [ebp
+
lpThreadAttributes]
.text:
7C8104EF
mov ebx, [ebp
+
lpStartAddress]
.text:
7C8104F2
mov eax, [ebp
+
lpParameter]
.text:
7C8104F5
mov [ebp
+
var_lpParameter], eax
.text:
7C8104FB
mov eax, [ebp
+
lpThreadId]
.text:
7C8104FE
mov [ebp
+
var_lpThreadId], eax
.text:
7C810504
xor edx, edx
.text:
7C810506
mov [ebp
+
pvBuffer], edx
.text:
7C81050C
xor eax, eax
.text:
7C81050E
lea edi, [ebp
+
var_3B4]
.text:
7C810514
stosd
.text:
7C8104CC
; HANDLE __stdcall CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
.text:
7C8104CC
public _CreateRemoteThread@
28
.text:
7C8104CC
_CreateRemoteThread@
28
proc near ; CODE XREF: CreateThread(x,x,x,x,x,x)
+
19
↓p
.text:
7C8104CC
; BaseCreateThreadPoolThread(x,x,x)
+
3F
↓p
.text:
7C8104CC
; DATA XREF: ...
.text:
7C8104CC
.text:
7C8104CC
var_420
=
byte ptr
-
420h
.text:
7C8104CC
ThreadInformation
=
byte ptr
-
408h
.text:
7C8104CC
Teb
=
dword ptr
-
404h
.text:
7C8104CC
Cookie
=
dword ptr
-
3ECh
.text:
7C8104CC
var_3E8
=
dword ptr
-
3E8h
.text:
7C8104CC
SuspendCount
=
dword ptr
-
3E4h
.text:
7C8104CC
UserStack
=
_INITIAL_TEB ptr
-
3E0h
.text:
7C8104CC
var_lpParameter
=
dword ptr
-
3CCh
.text:
7C8104CC
var_lpThreadId
=
dword ptr
-
3C8h
.text:
7C8104CC
ClientId
=
_CLIENT_ID ptr
-
3C4h
.text:
7C8104CC
ProcessHandle
=
dword ptr
-
3BCh
.text:
7C8104CC
pvBuffer
=
dword ptr
-
3B8h
.text:
7C8104CC
var_3B4
=
byte ptr
-
3B4h
.text:
7C8104CC
ThreadHandle
=
dword ptr
-
3B0h
.text:
7C8104CC
ExitStatus
=
dword ptr
-
3ACh
.text:
7C8104CC
ThreadContext
=
CONTEXT ptr
-
3A8h
.text:
7C8104CC
ApiMessage
=
byte ptr
-
0DCh
.text:
7C8104CC
var_BC
=
dword ptr
-
0BCh
.text:
7C8104CC
var_ThreadHandle
=
dword ptr
-
0B4h
.text:
7C8104CC
var_UniqueProcess
=
dword ptr
-
0B0h
.text:
7C8104CC
var_UniqueThread
=
dword ptr
-
0ACh
.text:
7C8104CC
var_Cookie
=
dword ptr
-
1Ch
.text:
7C8104CC
ms_exc
=
CPPEH_RECORD ptr
-
18h
.text:
7C8104CC
hProcess
=
dword ptr
8
.text:
7C8104CC
lpThreadAttributes
=
dword ptr
0Ch
.text:
7C8104CC
dwStackSize
=
dword ptr
10h
.text:
7C8104CC
lpStartAddress
=
dword ptr
14h
.text:
7C8104CC
lpParameter
=
dword ptr
18h
.text:
7C8104CC
dwCreationFlags
=
dword ptr
1Ch
.text:
7C8104CC
lpThreadId
=
dword ptr
20h
.text:
7C8104CC
push
410h
.text:
7C8104D1
push offset stru_7C8106A8
.text:
7C8104D6
call __SEH_prolog
.text:
7C8104DB
mov eax, ___security_cookie
.text:
7C8104E0
mov [ebp
+
var_Cookie], eax
.text:
7C8104E3
mov ecx, [ebp
+
hProcess] ; 将进程句柄赋给ecx
.text:
7C8104E6
mov [ebp
+
ProcessHandle], ecx
.text:
7C8104EC
mov esi, [ebp
+
lpThreadAttributes]
.text:
7C8104EF
mov ebx, [ebp
+
lpStartAddress]
.text:
7C8104F2
mov eax, [ebp
+
lpParameter]
.text:
7C8104F5
mov [ebp
+
var_lpParameter], eax
.text:
7C8104FB
mov eax, [ebp
+
lpThreadId]
.text:
7C8104FE
mov [ebp
+
var_lpThreadId], eax
.text:
7C810504
xor edx, edx
.text:
7C810506
mov [ebp
+
pvBuffer], edx
.text:
7C81050C
xor eax, eax
.text:
7C81050E
lea edi, [ebp
+
var_3B4]
.text:
7C810514
stosd
.text:
7C810515
lea eax, [ebp
+
UserStack]
.text:
7C81051B
push eax ;
int
.text:
7C81051C
test byte ptr [ebp
+
dwCreationFlags
+
2
],
1
; 是否带有STACK_SIZE_PARAM_IS_A_RESERVATION标志
.text:
7C810520
jnz loc_7C83AB6E
.text:
7C810526
push edx ; RegionSize
.text:
7C810527
push [ebp
+
dwStackSize] ; UINT_PTR
.text:
7C81052A
.text:
7C81052A
loc_7C81052A: ; CODE XREF: CreateRemoteThread(x,x,x,x,x,x,x)
+
2A6A6
↓j
.text:
7C81052A
push ecx ; ProcessHandle
.text:
7C81052B
call _BaseCreateStack@
16
.text:
7C810515
lea eax, [ebp
+
UserStack]
.text:
7C81051B
push eax ;
int
.text:
7C81051C
test byte ptr [ebp
+
dwCreationFlags
+
2
],
1
; 是否带有STACK_SIZE_PARAM_IS_A_RESERVATION标志
.text:
7C810520
jnz loc_7C83AB6E
.text:
7C810526
push edx ; RegionSize
.text:
7C810527
push [ebp
+
dwStackSize] ; UINT_PTR
.text:
7C81052A
.text:
7C81052A
loc_7C81052A: ; CODE XREF: CreateRemoteThread(x,x,x,x,x,x,x)
+
2A6A6
↓j
.text:
7C81052A
push ecx ; ProcessHandle
.text:
7C81052B
call _BaseCreateStack@
16
.text:
7C810538
xor edi, edi
.text:
7C81053A
inc edi
.text:
7C81053B
push edi
.text:
7C81053C
push [ebp
+
UserStack.StackBase]
.text:
7C810542
push ebx
.text:
7C810543
push [ebp
+
var_lpParameter]
.text:
7C810549
lea eax, [ebp
+
ThreadContext]
.text:
7C81054F
push eax
.text:
7C810550
call _BaseInitializeContext@
20
.text:
7C810538
xor edi, edi
.text:
7C81053A
inc edi
.text:
7C81053B
push edi
.text:
7C81053C
push [ebp
+
UserStack.StackBase]
.text:
7C810542
push ebx
.text:
7C810543
push [ebp
+
var_lpParameter]
.text:
7C810549
lea eax, [ebp
+
ThreadContext]
.text:
7C81054F
push eax
.text:
7C810550
call _BaseInitializeContext@
20
.text:
7C810565
push edi ; CreateSuspended
.text:
7C810566
lea ecx, [ebp
+
UserStack]
.text:
7C81056C
push ecx ; UserStack
.text:
7C81056D
lea ecx, [ebp
+
ThreadContext]
.text:
7C810573
push ecx ; ThreadContext
.text:
7C810574
lea ecx, [ebp
+
ClientId]
.text:
7C81057A
push ecx ; ClientId
.text:
7C81057B
mov esi, [ebp
+
ProcessHandle]
.text:
7C810581
push esi ; ProcessHandle
.text:
7C810582
push eax ; ObjectAttributes
.text:
7C810583
push THREAD_ALL_ACCESS ; DesiredAccess
.text:
7C810588
lea eax, [ebp
+
ThreadHandle]
.text:
7C81058E
push eax ; ThreadHandle
.text:
7C81058F
call ds:__imp__NtCreateThread@
32
; NtCreateThread(x,x,x,x,x,x,x,x)
.text:
7C810595
mov [ebp
+
ExitStatus], eax
.text:
7C810565
push edi ; CreateSuspended
.text:
7C810566
lea ecx, [ebp
+
UserStack]
.text:
7C81056C
push ecx ; UserStack
.text:
7C81056D
lea ecx, [ebp
+
ThreadContext]
.text:
7C810573
push ecx ; ThreadContext
.text:
7C810574
lea ecx, [ebp
+
ClientId]
.text:
7C81057A
push ecx ; ClientId
.text:
7C81057B
mov esi, [ebp
+
ProcessHandle]
.text:
7C810581
push esi ; ProcessHandle
.text:
7C810582
push eax ; ObjectAttributes
.text:
7C810583
push THREAD_ALL_ACCESS ; DesiredAccess
.text:
7C810588
lea eax, [ebp
+
ThreadHandle]
.text:
7C81058E
push eax ; ThreadHandle
.text:
7C81058F
call ds:__imp__NtCreateThread@
32
; NtCreateThread(x,x,x,x,x,x,x,x)
.text:
7C810595
mov [ebp
+
ExitStatus], eax
.text:
7C81060B
mov eax, [ebp
+
ThreadHandle]
.text:
7C810611
mov [ebp
+
var_ThreadHandle], eax
.text:
7C810617
mov eax, [ebp
+
ClientId.UniqueProcess]
.text:
7C81061D
mov [ebp
+
var_UniqueProcess], eax
.text:
7C810623
mov eax, [ebp
+
ClientId.UniqueThread]
.text:
7C810629
mov [ebp
+
var_UniqueThread], eax
.text:
7C81062F
push
0Ch
; DataLength
.text:
7C810631
push
10001h
; ApiNumber
.text:
7C810636
push ebx ; CaptureBuffer
.text:
7C810637
lea eax, [ebp
+
ApiMessage]
.text:
7C81063D
push eax ; ApiMessage
.text:
7C81063E
call ds:__imp__CsrClientCallServer@
16
.text:
7C81060B
mov eax, [ebp
+
ThreadHandle]
.text:
7C810611
mov [ebp
+
var_ThreadHandle], eax
.text:
7C810617
mov eax, [ebp
+
ClientId.UniqueProcess]
.text:
7C81061D
mov [ebp
+
var_UniqueProcess], eax
.text:
7C810623
mov eax, [ebp
+
ClientId.UniqueThread]
.text:
7C810629
mov [ebp
+
var_UniqueThread], eax
.text:
7C81062F
push
0Ch
; DataLength
.text:
7C810631
push
10001h
; ApiNumber
.text:
7C810636
push ebx ; CaptureBuffer
.text:
7C810637
lea eax, [ebp
+
ApiMessage]
.text:
7C81063D
push eax ; ApiMessage
.text:
7C81063E
call ds:__imp__CsrClientCallServer@
16
.text:
7C81066E
test byte ptr [ebp
+
dwCreationFlags],
4
; 是否带有CREATESUSPENDED
.text:
7C810672
jnz short loc_7C810687
.text:
7C810674
lea eax, [ebp
+
SuspendCount]
.text:
7C81067A
push eax ; SuspendCount
.text:
7C81067B
push [ebp
+
ThreadHandle] ; ThreadHandle
.text:
7C810681
call ds:__imp__NtResumeThread@
8
.text:
7C81066E
test byte ptr [ebp
+
dwCreationFlags],
4
; 是否带有CREATESUSPENDED
.text:
7C810672
jnz short loc_7C810687
.text:
7C810674
lea eax, [ebp
+
SuspendCount]
.text:
7C81067A
push eax ; SuspendCount
.text:
7C81067B
push [ebp
+
ThreadHandle] ; ThreadHandle
.text:
7C810681
call ds:__imp__NtResumeThread@
8
PAGE:
004ADD59
; NTSTATUS __stdcall NtCreateThread(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, HANDLE ProcessHandle, PCLIENT_ID ClientId, PCONTEXT ThreadContext, PINITIAL_TEB InitialTeb, BOOLEAN CreateSuspended)
PAGE:
004ADD59
_NtCreateThread@
32
proc near ; DATA XREF: .text:
0040D8F4
↑o
PAGE:
004ADD59
PAGE:
004ADD59
var_InitialTeb
=
dword ptr
-
38h
PAGE:
004ADD59
var_34
=
dword ptr
-
34h
PAGE:
004ADD59
var_ClientId
=
dword ptr
-
24h
PAGE:
004ADD59
var_CurETHREAD
=
dword ptr
-
20h
PAGE:
004ADD59
var_1C
=
dword ptr
-
1Ch
PAGE:
004ADD59
ms_exc
=
CPPEH_RECORD ptr
-
18h
PAGE:
004ADD59
ThreadHandle
=
dword ptr
8
PAGE:
004ADD59
DesiredAccess
=
dword ptr
0Ch
PAGE:
004ADD59
ObjectAttributes
=
dword ptr
10h
PAGE:
004ADD59
ProcessHandle
=
dword ptr
14h
PAGE:
004ADD59
ClientId
=
dword ptr
18h
PAGE:
004ADD59
ThreadContext
=
dword ptr
1Ch
PAGE:
004ADD59
InitialTeb
=
dword ptr
20h
PAGE:
004ADD59
CreateSuspended
=
byte ptr
24h
PAGE:
004ADD59
push
28h
PAGE:
004ADD5B
push offset stru_423B30
PAGE:
004ADD60
call __SEH_prolog
PAGE:
004ADD65
and
[ebp
+
ms_exc.registration.TryLevel],
0
PAGE:
004ADD69
mov eax, large fs:
124h
PAGE:
004ADD6F
mov [ebp
+
var_CurETHREAD], eax
PAGE:
004ADD72
cmp
byte ptr [eax
+
140h
],
0
; 判断PreviousMode是否为
0
PAGE:
004ADD79
jz loc_4E902E
PAGE:
004ADD59
; NTSTATUS __stdcall NtCreateThread(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, HANDLE ProcessHandle, PCLIENT_ID ClientId, PCONTEXT ThreadContext, PINITIAL_TEB InitialTeb, BOOLEAN CreateSuspended)
PAGE:
004ADD59
_NtCreateThread@
32
proc near ; DATA XREF: .text:
0040D8F4
↑o
PAGE:
004ADD59
PAGE:
004ADD59
var_InitialTeb
=
dword ptr
-
38h
PAGE:
004ADD59
var_34
=
dword ptr
-
34h
PAGE:
004ADD59
var_ClientId
=
dword ptr
-
24h
PAGE:
004ADD59
var_CurETHREAD
=
dword ptr
-
20h
PAGE:
004ADD59
var_1C
=
dword ptr
-
1Ch
PAGE:
004ADD59
ms_exc
=
CPPEH_RECORD ptr
-
18h
PAGE:
004ADD59
ThreadHandle
=
dword ptr
8
PAGE:
004ADD59
DesiredAccess
=
dword ptr
0Ch
PAGE:
004ADD59
ObjectAttributes
=
dword ptr
10h
PAGE:
004ADD59
ProcessHandle
=
dword ptr
14h
PAGE:
004ADD59
ClientId
=
dword ptr
18h
PAGE:
004ADD59
ThreadContext
=
dword ptr
1Ch
PAGE:
004ADD59
InitialTeb
=
dword ptr
20h
PAGE:
004ADD59
CreateSuspended
=
byte ptr
24h
PAGE:
004ADD59
push
28h
PAGE:
004ADD5B
push offset stru_423B30
PAGE:
004ADD60
call __SEH_prolog
PAGE:
004ADD65
and
[ebp
+
ms_exc.registration.TryLevel],
0
PAGE:
004ADD69
mov eax, large fs:
124h
PAGE:
004ADD6F
mov [ebp
+
var_CurETHREAD], eax
PAGE:
004ADD72
cmp
byte ptr [eax
+
140h
],
0
; 判断PreviousMode是否为
0
PAGE:
004ADD79
jz loc_4E902E
PAGE:
004E902E
loc_4E902E: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
20
↑j
PAGE:
004E902E
mov ebx, [ebp
+
InitialTeb]
PAGE:
004E9031
jmp loc_4ADDF3
PAGE:
004E902E
loc_4E902E: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
20
↑j
PAGE:
004E902E
mov ebx, [ebp
+
InitialTeb]
PAGE:
004E9031
jmp loc_4ADDF3
PAGE:
004ADD7F
mov eax, _MmUserProbeAddress
PAGE:
004ADD84
mov ecx, [ebp
+
ThreadHandle]
PAGE:
004ADD87
cmp
ecx, eax
PAGE:
004ADD89
jnb loc_52E0D8
PAGE:
004ADD8F
PAGE:
004ADD8F
loc_4ADD8F: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
80385
↓j
PAGE:
004ADD8F
mov eax, [ecx]
PAGE:
004ADD91
mov [ecx], eax
PAGE:
004ADD93
mov ebx, [ebp
+
ClientId]
PAGE:
004ADD96
test ebx, ebx
PAGE:
004ADD98
jz short loc_4ADDBD
PAGE:
004ADD9A
mov [ebp
+
var_ClientId], ebx
PAGE:
004ADD9D
mov eax, _MmUserProbeAddress
PAGE:
004ADDA2
cmp
ebx, eax
PAGE:
004ADDA4
jnb loc_52E0E3
PAGE:
004ADDAA
PAGE:
004ADDAA
loc_4ADDAA: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
8038D
↓j
PAGE:
004ADDAA
test bl,
3
PAGE:
004ADDAD
jnz loc_52E0EB
PAGE:
004ADDB3
PAGE:
004ADDB3
loc_4ADDB3: ; CODE XREF: PAGE:
0052E0F0
↓j
PAGE:
004ADDB3
mov al, [ebx]
PAGE:
004ADDB5
mov [ebx], al
PAGE:
004ADDB7
mov al, [ebx
+
4
]
PAGE:
004ADDBA
mov [ebx
+
4
], al
PAGE:
004ADDBD
PAGE:
004ADDBD
loc_4ADDBD: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
3F
↑j
PAGE:
004ADDBD
cmp
[ebp
+
ThreadContext],
0
PAGE:
004ADDC1
jz loc_52E129
PAGE:
004ADDC7
test byte ptr [ebp
+
ThreadContext],
3
PAGE:
004ADDCB
jnz loc_52E0F5
PAGE:
004ADDD1
PAGE:
004ADDD1
loc_4ADDD1: ; CODE XREF: PAGE:
0052E0FA
↓j
PAGE:
004ADDD1
mov eax, _MmUserProbeAddress
PAGE:
004ADDD6
cmp
[ebp
+
ThreadContext], eax
PAGE:
004ADDD9
jnb loc_52E0FF
PAGE:
004ADDDF
PAGE:
004ADDDF
loc_4ADDDF: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
803B1
↓j
PAGE:
004ADDDF
mov ebx, [ebp
+
InitialTeb] ; 将InitialTeb赋给ebx
PAGE:
004ADDE2
test bl,
3
PAGE:
004ADDE5
jnz loc_52E10F
PAGE:
004ADDEB
PAGE:
004ADDEB
loc_4ADDEB: ; CODE XREF: PAGE:
0052E119
↓j
PAGE:
004ADDEB
cmp
ebx, eax
PAGE:
004ADDED
jnb loc_52E11E
PAGE:
004ADD7F
mov eax, _MmUserProbeAddress
PAGE:
004ADD84
mov ecx, [ebp
+
ThreadHandle]
PAGE:
004ADD87
cmp
ecx, eax
PAGE:
004ADD89
jnb loc_52E0D8
PAGE:
004ADD8F
PAGE:
004ADD8F
loc_4ADD8F: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
80385
↓j
PAGE:
004ADD8F
mov eax, [ecx]
PAGE:
004ADD91
mov [ecx], eax
PAGE:
004ADD93
mov ebx, [ebp
+
ClientId]
PAGE:
004ADD96
test ebx, ebx
PAGE:
004ADD98
jz short loc_4ADDBD
PAGE:
004ADD9A
mov [ebp
+
var_ClientId], ebx
PAGE:
004ADD9D
mov eax, _MmUserProbeAddress
PAGE:
004ADDA2
cmp
ebx, eax
PAGE:
004ADDA4
jnb loc_52E0E3
PAGE:
004ADDAA
PAGE:
004ADDAA
loc_4ADDAA: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
8038D
↓j
PAGE:
004ADDAA
test bl,
3
PAGE:
004ADDAD
jnz loc_52E0EB
PAGE:
004ADDB3
PAGE:
004ADDB3
loc_4ADDB3: ; CODE XREF: PAGE:
0052E0F0
↓j
PAGE:
004ADDB3
mov al, [ebx]
PAGE:
004ADDB5
mov [ebx], al
PAGE:
004ADDB7
mov al, [ebx
+
4
]
PAGE:
004ADDBA
mov [ebx
+
4
], al
PAGE:
004ADDBD
PAGE:
004ADDBD
loc_4ADDBD: ; CODE XREF: NtCreateThread(x,x,x,x,x,x,x,x)
+
3F
↑j
PAGE:
004ADDBD
cmp
[ebp
+
ThreadContext],
0
PAGE:
004ADDC1
jz loc_52E129
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
赞赏
- [原创]CVE-2022-21882提权漏洞学习笔记 16383
- [原创]CVE-2021-1732提权漏洞学习笔记 19489
- [原创]CVE-2014-1767提权漏洞学习笔记 15192
- [原创]CVE-2018-8453提权漏洞学习笔记 18526
- [原创]CVE-2020-1054提权漏洞学习笔记 13542