2021 Sthack Windows Lpe
2021 Sthack Windows Lpe
Sthack 2021
~:$ whoami 2
Fabien Perigaud
@0xf4b on Twitter
2 / 68
Agenda 3
3 / 68
4
5 / 68
Pwn2Own - Rules 6
6 / 68
Pwn2Own – Rules (2) 7
7 / 68
Pwn2Own – Rewards 8
8 / 68
Pwn2Own Vancouver 2021 9
Targets
Desktop browsers (Chrome, Safari, Firefox, Edge)
Enterprise applications (Office, Reader, Zoom, Teams)
Server (RDP, Exchange, SharePoint)
Automotive (Tesla Model 3)
Local Privilege Escalation (Windows, Ubuntu)
9 / 68
Pwn2Own Vancouver 2021 – Windows 10 LPE 10
10 / 68
11
Ntoskrnl
Windows kernel image
Interrupts, memory management, kernel objects (processes, threads, files,
registry, …), syscalls and more
Very interesting target, might be reachable from the hardest sandbox level
Drawback: huge focus from security researchers
Win32k
Huge graphic subsystem, own syscall table
Old code base, many vulnerabilities
Also reachable from some sandbox contexts
Drawback: also a huge focus from security researchers
12 / 68
Kernel Attack Surface - Drivers 13
Drivers
PE loaded in Kernel-land
“.sys” file on the disk
Usually linked to a service
Userland access
Driver create a Device object “XXX”
Userland opens the device through “\\?\GLOBALROOT\Device\
XXX”
13 / 68
Kernel Attack Surface - Devices 14
15 / 68
Check devices access (2) 16
C:\Users\unpriv\Desktop>check_devices.py
...
[*] OK Afd
[*] OK ahcache
[*] OK Beep
[*] OK CNG
[*] OK gpuenergydrv
[*] OK KsecDD
[*] OK LanmanDatagramReceiver
[*] OK Mailslot
[*] OK Mup
[*] OK NamedPipe
[...]
[*] OK Netbios
[...]
[*] OK Null
[*] OK PEAuth
[*] OK RdpBus
[*] OK Spaceport
[*] OK Tdx
[*] OK USBFDO-0
[*] OK USBPDO-0
[*] OK VBoxGuest
[*] OK WindowsTrustedRT
[*] OK WINDRVR6
16 / 68
Pick a victim 17
WinDRV6 WindowsTrustedRT
17 / 68
Pick a victim 18
WinDRV6 WindowsTrustedRT
18 / 68
Pick a victim 19
WinDRV6 WindowsTrustedRT
19 / 68
Pick a victim 20
WinDRV6 WindowsTrustedRT
20 / 68
Find the corresponding driver 21
WinDBG again
21 / 68
Find the corresponding driver 22
22 / 68
23
Vulnerability Discovery
Driver interaction 24
24 / 68
Driver interaction – Major Functions 25
25 / 68
Driver interaction – Major Functions 26
26 / 68
SpControlDeviceControl 27
58 handled IOCTLs
Manual review
Focus on “SpIoctl[Create|Set].*”
Ignore when privileges are checked (“SpAccessCheck.*”)
27 / 68
SpControlDeviceControl 28
28 / 68
SpIoctlSetControlWork 29
No permission check
Buffer overflow 101
Controlled memcpy size
Controlled content
29 / 68
SpIoctlSetControlWork 30
No permission check
Buffer overflow 101
Controlled memcpy size
Controlled content
Dest:
pool (heap)
buffer
30 / 68
SpIoctlSetControlWork 31
No permission check
Buffer overflow 101
Controlled memcpy size
Controlled content
Source:
user controlled
buffer
31 / 68
SpIoctlSetControlWork 32
No permission check
Buffer overflow 101
Controlled memcpy size
Controlled content
Size:
from user
controlled
buffer
32 / 68
SpIoctlSetControlWork – Reaching the bug 33
33 / 68
Workflow 34
What’s happening?
34 / 68
Usual workflow 35
xxx.exe
Sp
Io
ct l
At
tac
hS
p ac
eR
em
ot
e
spaceport.sys
35 / 68
Usual workflow 36
xxx.exe spaceman.exe
Sp
Io
ct l
)
NF
At
tac
(W
hS
ns
p
aw
ac
eR
Sp
em
ot
e
spaceport.sys
36 / 68
Usual workflow 37
xxx.exe spaceman.exe
Sp
SpIoctlGetControlWork
Io
ct l
)
NF
At
tac
(W
hS
ns
p
aw
ac
eR
Sp
em
ot
e
spaceport.sys
37 / 68
38 / 68
38
SpIoctlSetControlWork
spaceman.exe
Usual workflow
SpIoctlGetControlWork
spaceport.sys
)
NF
(W
ns
aw
Sp
e
ot
em
eR
p ac
hS
tac
xxx.exe
At
ct l
Io
Sp
Usual Workflow 39
However…
… meet asynchronous DeviceIoControl!
Call SpIoctlGetControlWork before SpIoctlAttachSpaceRemote
List is empty, driver puts the request on hold
IRP is queued, and dequeued when SP_CONTROL_WORK::Run is
executed
When spaceman.exe is executed, it has been raced by us :)
39 / 68
PoC 40
40 / 68
PoC - BSOD 41
spaceport!memcpy+0x203:
fffff804`65dfa343 0f104411f0 movups xmm0,xmmword ptr [rcx+rdx-10h]
ds:ffffaf07`ee1c6292=????????????????????????????????
41 / 68
42
Pool overflow
The pool is the Windows Kernel heap
Target allocation
SP_WORK_INFO allocation is made in the NonPagedPoolNx
Size is 0x160 bytes
Lies in the LFH (Low Fragmentation Heap)
Overflow constraints
None :)
We control content and size
43 / 68
Mitigations 44
kASLR
Not a problem, Medium integrity level
Various kernel APIs to get objects and modules addresses
SMAP?
Only in a few contexts, not in ours :)
44 / 68
Exploitation strategy 45
Data only
We want to run an elevated cmd.exe
45 / 68
La French Tech – SSTIC 2020 46
46 / 68
La French Tech – SSTIC 2020 47
Requirements
Shape the pool to control the chunk after the vulnerable one
47 / 68
Pool massaging 48
48 / 68
Pool massaging 49
49 / 68
Pool massaging 50
50 / 68
Creating an overlapping chunk 51
51 / 68
Creating an overlapping chunk - Graphics 52
Pool Pool
Header
Vuln Chunk Header
PipeQueueEntry
Pool Pool
Header
Vuln Chunk Header
PipeQueueEntry
Overflow
New
Pool
Header
Free Chunk Pool PipeQueueEntry
Header
Fake New
Pool
Header
New PipeQueueEntry Pool Pool PipeQueueEntry
Header Header
52 / 68
Creating an overlapping chunk – Next steps 53
We can now make a new allocation of 0x260 bytes to reuse the fake
chunk!
53 / 68
Creating an overlapping chunk – Result 54
Pool
Header
PipeQueueEntry
Pool
Header
PipeQueueEntry
Overlapping chunks
54 / 68
PipeQueueEntry structure 55
55 / 68
Arbitrary Read Primitive 56
SystemBuffer
Userland
Kernel
PipeQueueEntry
56 / 68
Attacking the ProcessBilled pointer 57
57 / 68
Finding ExpPoolQuotaCookie 58
58 / 68
Arbitrary decrement to privilege escalation 59
59 / 68
SeDebugPrivileges 60
Strategy
Open winlogon.exe
Inject shellcode
Spawn a SYSTEM cmd.exe
Quick demo!
60 / 68
61
Partial Win :(
62 / 68
Timeline 63
63 / 68
Fix 64
64 / 68
Free 0day? 65
65 / 68
Additional fix... 66
66 / 68
Final words 67
Try Pwn2Own!
Some targets do not require so much effort
Attack surface is quite huge!
67 / 68
68
https://www.linkedin.com/company/synacktiv
https://twitter.com/synacktiv
Nos publications sur : https://synacktiv.com