Module 06 Mitigation Techniques Part2
Module 06 Mitigation Techniques Part2
Exploitation
SEC-300-01/CSI-301-02
Ali Hadi
@binaryz0ne
Exploit Mitigation
Preventing memory corruption techniques!!!
W^X
Defeating Exploits using DEP
• No-eXecute CPU technology
– Intel eXecute Disable (XD bit)
– AMD Enhanced Virus Protection
– ARM eXecute Never (XN)
https://support.microsoft.com/en-ca/help/875352/a-detailed-description-of-the-data-execution-prevention-dep-feature-in
www.ashemery.com 5
Defeating Exploits – Past.
buffer
Padding
Shellcode
www.ashemery.com 6
Data Execution Prevention (DEP)
Mark stack as
non-
executable
using NX bit buffer
Padding
www.ashemery.com 7
Data Execution Prevention – Cont.
Worst Case:
DoS ? buffer
Padding
Shellcode
Crash
www.ashemery.com 8
Data Execution Prevention – Cont.
Cited [1]
Software DEP
• Makes sure that SEH exception handlers point to non-
writable memory (weak)
Hardware DEP
• Enforces that processor does not execute instructions from
data memory pages (stack, heap)
• Make page permission bits meaningful
– R != X
www.ashemery.com 9
Bypassing DEP
Cited [1]
www.ashemery.com 10
Return-to-libc (ret2libc)
Cited [1]
www.ashemery.com 11
Return-to-libc (ret2libc) – Cont.
Cited [1]
Buffer
(# of bytes)
www.ashemery.com 12
Return Chaining
Cited [1]
www.ashemery.com 13
A: Address
S: Space
L: Layout
R: Randomization
…
ASLR
Cited [1]
www.ashemery.com 15
Address Space
addr of buf Layout addr of buf
(0xffffd5d8) Randomization (0xffffd5d8)
caller’s ebp caller’s ebp
buf[63] buf
Shellcode 0xffffd618 buf 0xffffe428
Shellcode
buf[0] 0xffffd5d8 0xffffe3f8
Oops… 0xffffd5d8
www.ashemery.com 16
ASLR
Traditional exploits need precise addresses
– stack-based overflows: location of shell code
– return2libc: library addresses
www.ashemery.com 17
Memory
www.ashemery.com 18
ASLR Randomization
• Poor entropy
– Sometimes the randomization isn’t random enough or the attacker
may try as many times as needed
• Memory address disclosure
– Some vulnerabilities or other tricks can be used to reveal memory
addresses in the target process
• Using non-ASLR enabled module
www.ashemery.com 20
www.ashemery.com 21
Return-Oriented Programming
Cited [1]
www.ashemery.com 22
23
Image by Dino Dai Zovi www.ashemery.com
Return-Oriented Programming
Cited [1]
Requirements:
• vulnerability + gadgets + some un-randomized code
(addresses of gadgets must be known)
www.ashemery.com 24
ROP Programming
Cited [1]
1. Disassemble code
2. Identify useful code sequences as gadgets
3. Assemble gadgets into desired shellcode
www.ashemery.com 25
Return-Oriented Gadgets
Cited [1]
mov STORE
pop eax
ret + pop ecx
ret + [ecx],eax
ret
= IMMEDIATE
VALUE
www.ashemery.com 26
After all that…
• Bypassing DEP & ASLR makes you Mohammad Ali of Software
Exploitation
www.ashemery.com 27
Summary
• Explained exploit mitigation techniques (Compiler/System)
• Explained different mitigation techniques such as DEP and
ASLR
• What is Ret2libc
• What is Return-Oriented Programming and how to benefit
from it for software exploitation
www.ashemery.com 28
References
• Memory Corruption 101, NYU Poly, Dino Dai Zovi
• DEP Evasion Techniques, http://woct-
blog.blogspot.com/2005/01/dep-evasion-technique.html
• SEHOP, http://www.sysdream.com/articles/sehop_en.pdf
• Shellcode Storm, http://shell-storm.org/shellcode/
• Stack /GS, https://msdn.microsoft.com/en-
us/library/8dbf701c%28VS.80%29.aspx?f=255&MSPPError=-
2147217396
www.ashemery.com 29