Automatic Exploit Generation
an Odyssey Sophia D’Antoine
CanSecWest 2016
Automatic Exploit Generation an Odyssey Sophia DAntoine - - PowerPoint PPT Presentation
Automatic Exploit Generation an Odyssey Sophia DAntoine CanSecWest 2016 Introduction Programs have become increasingly difficult to exploit larger, changing surface area mitigations more bytes to siphon through 10/22/2015
an Odyssey Sophia D’Antoine
CanSecWest 2016
Introduction
Programs have become increasingly difficult to exploit
10/22/2015 Program Analysis to Find Vulnerabilities 2/45
Introduction
Reaction: people get smarter and tools get better
10/22/2015 Program Analysis to Find Vulnerabilities 3/45
CTF & Wargames A Binary PWN It A Flag
10/22/2015 Program Analysis to Find Vulnerabilities 4/45
The Past
Manual labor
10/22/2015 Program Analysis to Find Vulnerabilities 5/45
Dynamic Analysis
Definition:
Popular Uses:
10/22/2015 Program Analysis to Find Vulnerabilities 6/45
Dynamic Analysis
Common tools:
10/22/2015 Program Analysis to Find Vulnerabilities 7/45
step... step... step... step... step... step... step... step... step... step... step... step... step... step... step... step... step... step... step...
Example: Dynamic Analysis
10/22/2015 Program Analysis to Find Vulnerabilities 8/45
Automated Exploitation
Agenda
10/22/2015 Automatic Exploit Generation 10/45
primitives
Some Background
What is Automated Exploitation? The ability to generate a successful computer attack with reduced or entirely without human interaction.
– Sean Heelan’s “Automatic Generation of Control Flow Hijacking Exploits for Software Vulnerabilities” – David Brumley (@ Carnegie Mellon) et al. (AEG, MAYHEM, etc) – Cyber Grand Challenge! (CGC)
primitives
primitives
10/22/2015 Program Analysis to Find Vulnerabilities 11/45
Break up AEG into 2 parts:
Automating Exploitation
both areas
first problem
10/22/2015 Program Analysis to Find Vulnerabilities 12/45
github.com/programa-stic/ropc-llvm
10/22/2015 Automatic Exploit Generation 13/45
Automating Exploitation
AEG - pwnable.kr
Program Operations
Get random binary, pwn it in 10 seconds. 1) Takes input at argv[1] 2) Does some decode & operations on it 3) Calls sequence of 16 functions 4) Each function checks 3 characters of input sequentially 5) If you pass them all, you get to the exploitable memcpy! Automated Exploit Generation 1) Generate input to get to vulnerability 2) Generate payload to exploit and get shell
10/22/2015 Program Analysis to Find Vulnerabilities 14/45
AEG - pwnable.kr
fail ... input argv[1] 3 checks ... 15 more functions ... memcpy fail ...
10/22/2015 Program Analysis to Find Vulnerabilities 15/45
How can AEG solve for this path in the CFG?
Software Program Analysis!
Agenda
10/22/2015 Automatic Exploit Generation 18/45
The process of automatically analyzing the behavior of applications
What is program analysis
10/22/2015 Program Analysis to Find Vulnerabilities 19/45
How This Helps with AEG
Analysis helps us hunt for bugs automatically.
==> Pro move: combine analyses
10/22/2015 Program Analysis to Find Vulnerabilities 20/45
Types we care about.
Dynamic Binary Instrumentation
Definition:
Popular Uses:
10/22/2015 Program Analysis to Find Vulnerabilities 22/45
Example: DBI
$pin -t inscount0.so -- binary [BINARY LEVEL]
[STILL BRUTE FORCE]
(the possible CFG space may be very large)
10/22/2015 Program Analysis to Find Vulnerabilities 23/45
icount++ sub $0xff, %edx icount++ cmp %esi, %edx icount++ jle icount++ mov $0x1, %edi icount++ add $0x10, %eax sub $0xff, %edx cmp %esi, %edx jle mov $0x1, %edi add $0x10, %eax
Example: DBI
10/22/2015 Program Analysis to Find Vulnerabilities 24/45
Symbolic Execution
Definition:
(could still be extremely expensive)
Popular Uses:
10/22/2015 Program Analysis to Find Vulnerabilities 25/45
Example: Symbolic Execution
[INT] a, b, c [INT] x, y, z = 0;
fun( int a, b, c ) { if (a) { x = -2; } if (b < 5) { if (!a && c) { y = 1; } z = 2; } assert(x+y+z!=3) } . . . fun( 0, 3, 1 ); . . . Old Method: Try all inputs until assert [WARNING] inputs unbounded!
10/22/2015 Program Analysis to Find Vulnerabilities 26/45
Example: Symbolic Execution
[SYMBOL] a, b, c [INT] x, y, z = 0;
if (a) { x = -2; } if (b < 5) { if (!a && c) { y = 1; } z = 2; } assert(x+y+z!=3)
10/22/2015 Program Analysis to Find Vulnerabilities 27/45
Concolic Execution
Definition:
underneath symbolic variables Popular Uses:
(replace symbols with values to satisfy path condition)
10/22/2015 Program Analysis to Find Vulnerabilities 28/45
Example: Concolic Execution
[INT] a, b, c [INT] x, y, z = 0;
fun( int a, b, c ) { if (a) { x = -2; } if (b < 5) { if (!a && c) { y = 1; } z = 2; } assert(x+y+z!=3) } . . . fun( 0, 3, 1 ); . . . Old Method: Try all inputs until assert [WARNING] inputs unbounded!
10/22/2015 Program Analysis to Find Vulnerabilities 29/45
Example: Concolic Execution
[INT & SYMBOL] a, b, c [INT] x, y, z = 0;
if (a) { x = -2; } if (b < 5) { if (!a && c) { y = 1; } z = 2; } assert(x+y+z!=3)
STEPS
[ONE] concrete execution of function [TWO] while building symbolic path model [THREE] constraints on input are modeled [FOUR] models used to generate concrete input
10/22/2015 Program Analysis to Find Vulnerabilities 30/45
Creating a Feedback Loop
In practice using the results of different analyses finds bugs quicker. Example Pairing:
10/22/2015 Program Analysis to Find Vulnerabilities 31/45
Agenda
10/22/2015 Automatic Exploit Generation 32/45
Common tools:
10/22/2015 Program Analysis to Find Vulnerabilities 33/45
Dynamic Binary Instrumentation
Example: Flare-on Challenge 9
[ http://blog.trailofbits.com/2015/09/09/flare-on-reversing- challenges-2015/ ]
10/22/2015 Program Analysis to Find Vulnerabilities 34/45
Input: FLAGAAAA... Input: AAAAAAAA...
Symbolic Execution
Common tools:
feed it to z3 to solve
10/22/2015 Program Analysis to Find Vulnerabilities 35/45
Concolic Execution
Common tools:
10/22/2015 Program Analysis to Find Vulnerabilities 36/45
AEG Demo: Assumptions
[ Assumptions ]
– Target memory corrupt (memcpy)
[ Dynamically Acquire ]
[ Statically (Pre) Acquired ]
10/22/2015 Program Analysis to Find Vulnerabilities 37/45
LLVM Pass
Using the structure of the binary:
– Longest path of CFG is the “winning” path
– Each cmp of this path comprises the “constraints” ⇒ “Flow-sensitive constraint analysis"
LLVM:
10/22/2015 Program Analysis to Find Vulnerabilities 38/45
LLVM Pass
Download tool: [ https://github.com/trailofbits/domtresat ]
10/22/2015 Program Analysis to Find Vulnerabilities 38/45
Angr Script
… acquire binary & some conditions ….
b = angr.Project("aeg") ss = b.factory.blank_state(addr=entry_func) ss.options.discard("LAZY_SOLVES") ss.se._solver.timeout=10000 ss.memory.store(argv1_buff, ss.BV("input", 50*8)) pg = b.factory.path_group(ss, immutable=False) angr.path_group.l.setLevel("DEBUG") pg.explore(find=vuln_addr[0], avoid=fail_bbs) argv1_win = pg.found[0].state.se.any_str(pg.found[0].state.memory.load(argv1_buff, 50))
#setup env #fake input with no value #target & bad branches, 4 speed #solved for path to target, dump memory
10/22/2015 Program Analysis to Find Vulnerabilities 39/45
Demo
[ What We are (still) Working With ] – Binaries – Source is nice
Conclusion: The Future
[ Difficulty ]
10/22/2015 Program Analysis to Find Vulnerabilities 41/45
Automatic program analysis
goal: proving existence or absence
Finding (More) Bugs
10/22/2015 Program Analysis to Find Vulnerabilities 42/45
Acknowledgements
10/22/2015 Automatic Exploit Generation 43/45
References
[Good Course Material]
https://www.cs.umd.edu/class/spring2013/cmsc631/lectures/symbolic-exec.pdf https://www.utdallas.edu/~zxl111930/spring2012/public/lec4.pdf http://web.mit.edu/16.399/www/lecture_01-intro/Cousot_MIT_2005_Course_01_4-1.pdf http://homepage.cs.uiowa.edu/~tinelli/classes/seminar/Cousot.pdf
[Site for Tool Documentation]
https://github.com/angr/angr-doc https://github.com/llvm-mirror/llvm https://github.com/trailofbits/domtresat [ Tool built on concepts in this talk ]
[Other Good Resources]
http://www.grammatech.com/blog/hybrid-concolic-execution-part-1 http://openwall.info/wiki/_media/people/jvanegue/files/aegc_vanegue.pdf
10/22/2015 Automatic Exploit Generation 44/45
Any Questions?
IRC: quend email: sophia@trailofbits.com
10/22/2015 Automatic Exploit Generation 45/45