Windows SMEP Bypass U Equals S - 0
Windows SMEP Bypass U Equals S - 0
U=S
Nicolas A. Economou
Enrique E. Nissim
PA G E
Schedule
- Reviewing Modern Kernel Protections
- Introducing SMEP
- Windows SMEP bypass techniques – Part 1
- Windows Paging Mechanism
- Windows SMEP bypass techniques – Part 2
- DEMO
- Conclusions
PA G E 2
Reviewing Modern Protections
- DEP/NX: is a security feature included in modern operating
systems. It marks areas of memory as either "executable" or
"nonexecutable".
PA G E 3
Reviewing Modern Protections
- Integrity Levels: call restrictions for applications running in
low integrity level – since Windows 8.1.
PA G E 4
Reviewing Modern Protections
- SMAP: allows pages to be protected from supervisor-mode
data accesses. If SMAP = 1, software operating in supervisor
mode cannot access data at linear addresses that are
accessible in user mode.
PA G E 5
SMEP
PA G E
What is SMEP?
- Aka: “Supervisor Mode Execution Prevention”
PA G E 8
How does it work?
- Feature enabled by the OS
PA G E 9
SMEP CPU support
- Desktop processors
- Intel Core: Lastest models of i3, i5, i7
- Intel Pentium: G20X0(T) and G21X0(T)
- Intel Celeron: G1610(T), G1620(T) and G1630
- Server processors
- Intel Xeon: Lastest models of E3, E5, E7
- Intel Pentium: 1403v3 and 1405v2
PA G E 1 0
SMEP Protection
- We control EIP/RIP = 0x41414141 in Ring-0
- So, we can jump where we want to …
4GB
KERNEL
2GB ?
USER
0
PA G E 1 1
Windows
SMEP bypass
techniques – Part 1
PA G E
Option 0: Jumping to user space
- Jump to user space (to my “code”) 4GB
USER
0
- Error: ATTEMPTED_EXECUTE_OF_NOEXECUTE_MEMORY
PA G E 1 3
Option 1 - x86: Jumping to kernel heap
http://blog.ptsecurity.com/2012/09/intel-smep-overview-and-partial-bypass.html
PA G E 1 4
Option 1 - x64: Jumping to kernel heap
- No longer an option
PA G E 1 5
Option 2: ROPing in kernel space
- Jump to kernel code (win32k.sys):
- Get modules addresses with
NtQuerySystemInformation() (only in Medium
Integrity since Windows 8.1)
PA G E 1 6
Option 2: ROPing to Turn off SMEP
PA G E 1 7
Windows Paging
Mechanism
PA G E
Paging 101
• Paging is a functionality provided by the MMU and used by
the processor to implement virtual memory.
• A virtual address is the one used in processor instructions;
this must be translated into a physical address to actually
refer a memory location.
PA G E 1 9
Windows Paging x64
PA G E 2 0
Canonical Addresses
• With 64bits we can address 264 bytes of memory (16 Exabytes).
Current x64 processors however, limit the number of bits to 48, but
instead of simply disallowing bits 48-63, they set them to be equal
to bit 47.
PA G E 2 1
PxE Structure
63 62:52 51:12 11 10 9 8 7 6 5 4 3 2 1 0
XD I PFN I I I G P D A P P U R P
A C W / /
T D T S W
PA G E 2 2
Self-ref Entry
• Entry 0x1ED = 1 1110 1101
• Since bit 47 is 1, all the bits 48-64 must be 1 to be a
valid canonical address
PA G E 2 3
Self-ref Entry
F F F F F 6 8 0 0 0 0 0 0 0 0 0
1111 1111 1111 1111 1111 0101 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000
PML4 PDPT PD PT
0 0 0
1ED
CR3
PA G E 2 4
Quick Formula
PA G E 2 5
Quick Formula
PA G E 2 7
Windows
SMEP bypass
techniques – Part 2
PA G E
Option 3: Unprotecting HAL.DLL heap
- Using multiple arbitrary writes (ROPing or not)
PA G E 2 9
U=S
PA G E
Option 4: Deceiving SMEP
- If SMEP detects ring-0 code running in USER
SPACE (USER PAGES)
PA G E 3 1
Flipping U/S
- Option 4: “First time somebody mentioned this”
- Conference: NSA - Trusted Computing (2011)
- Speaker: Stephen Fischer
- https://www.ncsi.com/nsatc11/presentations/we
dnesday/emerging_technologies/fischer.pdf
- Slide: 9
PA G E 3 2
Flipping U/S
- Option 4: “… and then …”
- Blog: Windows 8 Kernel Memory Protections Bypass
- Author: MWR LABS - Jérémy Fetiveau
- https://labs.mwrinfosecurity.com/blog/2014/08/1
5/windows-8-kernel-memory-protections-bypass
- Section: “Modifying Paging Structures“
PA G E 3 3
Flipping U/S
- Option 4: “… and finally”
- Conference: Infiltrate 2015
- Speaker: Alex Ionescu
- http://www.alex-ionescu.com/infiltrate2015.pdf
- Slides: 69 and 71 …
PA G E 3 4
A. Ionescu at Infiltrate 2015
PA G E 3 6
Flipping U/S
- Breaking Rules
PDPT 1 PD 1 PT 1 PAGE 1
S S S U
PML4
U U U S
PDPT 2 PD 2 PT 2 PAGE 2
PA G E 3 7
Mapping a Kernel Page in User Space
4GB
KERNEL
2GB !!!
USER
PA G E
CVE-2015-5736
- Exploit:
- “Fortinet Antivirus Multiple Vulnerabilities”
(CVE-2015-5736)
- http://www.coresecurity.com/advisories/forticlien
t-antivirus-multiple-vulnerabilities
PA G E 4 0
Exploit for CVE-2015-5736
- Target:
- “Windows 10” 64 bits + “Forticlient <= 5.2.3” installed
- Scenario:
- We can’t jump directly to USER SPACE (SMEP!)
- No registers poiting to our DATA!
- The only way, Stack Pivoting to USER SPACE
- Objective:
- Write a ROP chain to avoid SMEP!
- Run our RING-0 code in USER SPACE
PA G E 4 1
Exploit for CVE-2015-5736
- Vulnerable Driver: FortiShield.sys
- A filesystem filter driver that hooks several
operations -> IRP_MJ_SET_INFORMATION
PA G E 4 2
Exploit for CVE-2015-5736
- Arbitrary Callback: Invoked via MoveFileEx()
PA G E 4 3
Exploit for CVE-2015-5736
- Gadget finding:
- Tool: Agafi - https://github.com/CoreSecurity/Agafi
- Trick: Many 64 bit instr. are equal to 32 bit instr.
PA G E 4 4
ROP in KernelSpace
- Special gadget: Stack Pivoting to user space
thanks AMD !
PA G E 4 5
ROP in KernelSpace
- Special gadget: Disabling the CPU TLB cache
PA G E 4 6
ROP in KernelSpace
- ROPing to “hal.dll” - “Windows 10” 64 bits
HAL + 0x6bf0 Stack Pivoting to USER SPACE
STACK
in
KERNEL SPACE
PA G E 4 7
Demo time now
PA G E
Conclusions
- The PML entry (0x1ed) should be RANDOMIZED
- 256 entries are available for the OS kernel
- Only ~20 entries are used by Windows
- Virtualization ?
- Enabled by VSM in Windows 10
- Multiples EPTs (Extended Pages Tables - SLAT) could be a
solution
PA G E 4 9
Conclusions
PA G E 5 0
Questions?
PA G E
Thank You
PA G E