+ All Categories
Home > Documents > Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic...

Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic...

Date post: 30-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
73
University of California, Santa Barbara (UCSB) HITCON Pacific December 2nd, 2016 Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish Antonio Bianchi [email protected]
Transcript
Page 1: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

University of California, Santa Barbara (UCSB)

HITCON PacificDecember 2nd, 2016

Automatic Binary Exploitation and Patching

using Mechanical [Shell]Phish

Antonio Bianchi [email protected]

Page 2: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

2Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● A team of security enthusiasts■ Do research in system security

■ Play security competitions (CTF)

■ Mainly students fromUniversity of California, Santa Barbara

■ More info:● “A Dozen Years of Shellphish”

https://youtu.be/APY2SsBde1U

Shellphish

Page 3: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

3Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC

● A fully automated CTF competition

● Organized by DARPA

● No Human intervention

Page 4: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

4Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – Timeline

2014

Shellphish

signs u

p!

Qualification!

Online eve

nt, June 2015

Finals!

Live eve

nt, August

2016

Open source release!

Page 5: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

5Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Page 6: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

6Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – How the game worked

● Round-based game● Organizers’ servers

provide:○ Binaries

■ Linux-like, Intel x86, limited syscalls

■ Console (stdin/stdout)■ Compiled C programs →

no source code■ Contain one or more

vulnerabilities

○ Network traffic■ Collected during

previous rounds

Page 7: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

7Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – How the game worked

● Teams provide○ Patched binaries○ Attacks

Page 8: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

8Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – How the game worked

● Organizers’s servers evaluate○ Attacks

vs.Patched binary

Page 9: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

9Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – How the game worked

● Organizers’ servers send back○ Scores○ Patched binaries

from adversarial teams

Page 10: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

10Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – How the game worked

● Before the game○ Teams can set up

their servers

Page 11: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

11Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – How the game worked

● During the game (10h)○ “Certified air gap”○ Scores are the only

data exiting

Page 12: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 13: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

13Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

How to play?

Automatic BinaryExploitation

Automatic BinaryPatching

Infrastructure

Page 14: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

14Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

How to play?

Automatic BinaryExploitation

Page 15: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

15Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Two types of exploits

Type 1 Type 2

control general purpose register

control instruction pointer

leak memory from flag page

eax, ebx, ecx, edx, esi, edi, esp

FLAG0x4347c0000x4347d000

eip

4 consecutive bytes needed

● Arbitrary code execution ● Information leak (Heartbleed, ASLR base address leak, ...)

Page 16: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

16Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Exploitation pipeline (simplified)

Driller(fuzzing +

symbolic execution)

Colorguard(Type2 exploits)

Rex(Type1 exploits)

Exploit Compiler

Network Traffic

VulnerableBinaries

Testcases

Exploit

Page 17: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

17Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Driller

Try many different inputs:“1”, “2”, “3”, “4”, “5”, “7”, “8”, ...

● Execute “the most” of the program → Find good inputs to the binary

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Page 18: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

18Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● Execute “the most” of the program → Find good inputs to the binary

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Driller

“3” and “7” are “good” testcases:they reach new code locations

Page 19: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

19Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Driller

This is hard to reach randomly

● Execute “the most” of the program → Find good inputs to the binary

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Page 20: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

20Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Driller

We can use “symbolic tracing”

● Execute “the most” of the program → Find good inputs to the binary

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Target

Page 21: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

21Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Driller

We can use “symbolic tracing”Contraints:

- v1 = user_input1()

● Execute “the most” of the program → Find good inputs to the binary

Target

Page 22: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

22Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Driller

We can use “symbolic tracing”Contraints:

- v1 = user_input1- not (v1 < 10)

● Execute “the most” of the program → Find good inputs to the binary

Target

Page 23: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

23Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Driller

We can use “symbolic tracing”Contraints:

- v1 = user_input1()- not (v1 < 10)- v1^2 - 19087925*v1 == 57263784

● Execute “the most” of the program → Find good inputs to the binary

Target

Page 24: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

24Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● Execute “the most” of the program → Find good inputs to the binary

Driller

v1 = user_input1()v2 = user_input2()

if(v1 < 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

We can use “symbolic tracing”Contraints:

- v1 = user_input1()- not (v1 < 10)- v1^2 - 19087925*v1 == 57263784

Solve:- user_input1 = 0x1234238Target

Page 25: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

25Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Driller – AFL + angr

Fuzzing:AFL

good at finding solutions for general

inputs

Symbolic Execution:

angr

good at find solutions for specific inputs

Driller: Augmenting fuzzing through selective symbolic execution.N. Stephens, J. Grosen, C. Salls, A. Dutcher, R. Wang, J. Corbetta, Y. Shoshitaishvili, C. Kruegel, and G. Vigna. at NDSS 2016

Page 26: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

26Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex

Binary

Crashing Input

Symbolic Tracingand

Crash Triaging

ROP

Shellcode

Circumstance

Explore

...

Generate exploit C code

Techniques

Page 27: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

27Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex – Crash Triaging

Last BB contain a

write?

Last BB contain a

read?

Is the target address

symbolic?

Is instruction pointer

symbolic?

Instruction pointer

overwrite

Arbitrary writeArbitrary read

Page 28: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

28Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● Understand “how” to control the crash

Rex – Symbolic Tracing

v1 = user_input1()v2 = user_input2()

if(v1 > 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

If this instruction is reached the program crashes

Page 29: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

29Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● Understand “how” to control the crash

Rex – Symbolic Tracing

v1 = user_input1()v2 = user_input2()

if(v1 > 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Using symbolic tracing, we know:instruction_pointer =

function_pointer = v2 + 300 =user_input2 + 300

Page 30: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

30Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● Understand “how” to control the crash

Rex – Symbolic Tracing

v1 = user_input1()v2 = user_input2()

if(v1 > 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Using symbolic tracing, we know:instruction_pointer = user_input2 + 300

Therefore:- By controlling the user input

we control the instruction pointer

Page 31: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

31Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

● Understand “how” to control the crash

Rex – Symbolic Tracing

v1 = user_input1()v2 = user_input2()

if(v1 > 10){ if (v1 == 3){ foo() }else if(v1 == 7){ bar() }}else{ if((v1^2 - 19087925*v1)==57263784){ function_pointer = v2 + 300 function_pointer() }}

Using symbolic tracing, we know:instruction_pointer = user_input2 + 300

Therefore:- By controlling the user input

we control the instruction pointer- If we want:

instruction_pointer = Xwe have to set:

user_input2 = X - 300

Page 32: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

32Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex – Techniques

Instruction pointer control

Jump to Shellcode

Pivot to ROP chain

“Circumstantial”

Point-to-Flag

Point-to-Data

Point-to-Data

Explore for Exploit

Arbitrary ReadArbitrary Write

● Crashing input → Exploit

Page 33: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

33Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex – Technique: Jump to Shellcode● We want to place shellcode in buffer and jump to it

v1 = user_input1()buffer = base64_decode(user_input2())

//…

function_pointer = v1 + 300function_pointer()

Page 34: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

34Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex – Technique: Jump to Shellcode● We want to place shellcode in buffer and jump to it

Using symbolic tracing, we know:instruction_pointer = user_input1 + 300

buffer = base64_decode(user_input2)

v1 = user_input1()buffer = base64_decode(user_input2())

//…

function_pointer = v1 + 300function_pointer()

Page 35: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

35Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex – Technique: Jump to Shellcode● We want to place shellcode in buffer and jump to it

Using symbolic tracing, we know:instruction_pointer = user_input1 + 300

buffer = base64_decode(user_input2)

We want:instruction_pointer = &(buffer)buffer = shellcode

v1 = user_input1()buffer = base64_decode(user_input2())

//…

function_pointer = v1 + 300function_pointer()

Page 36: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

36Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Rex – Technique: Jump to Shellcode● We want to place shellcode in buffer and jump to it

Using symbolic tracing, we know:instruction_pointer = user_input1 + 300

buffer = base64_decode(user_input2)

We want:instruction_pointer = &(buffer)buffer = shellcode

Therefore:user_input1 = &(buffer) - 300user_input2 = base64_encode(shellcode)

v1 = user_input1()buffer = base64_decode(user_input2())

//…

function_pointer = v1 + 300function_pointer()

Page 37: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

37Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Colorguard

● Memory-leak (Type 2) exploits

● Use symbolic tracing

● Analyze all inputs

Page 38: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

38Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Colorguard● Memory-leak (Type 2) exploits are also generated

using symbolic tracing

v1 = user_input1()

//…

printed_value = array[v1]print(printed_value)

Using symbolic tracing, we know:printed_value = *(&array + v1)

v1 = user_input1

We want:printed_value = flag_page[0]

Therefore:user_input1 = (&flag_page) - (&array)

Page 39: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

39Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Colorguard – Unicorn Engine● Every testcase can potentially leak the flag page

● Full symbolic tracing of every testcase is too slow

● angr + unicorn engine (QEMU wrapper)○ Execute “most” of the code in QEMU

angr unicorn engine QEMU

3,000,000 times slower than a real CPU

2~5 times slower than a real CPU

Page 40: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

40Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

How to play?

Automatic BinaryPatching

Page 41: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

41Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Automatic Patching

● Prevent binary form being exploit

● Preserve binary functionality

● Preserve binary performance○ speed○ memory usage○ disk space

● Prevent analysis from other teams

Page 42: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

42Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex

Patching Backends

Patching Techniques

Patches

Patched Binary

Original Binary

Page 43: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

43Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex

● Defensive Techniques

○ Return pointer encryption

○ Protect indirect calls/jmps

○ Extended Malloc allocations

○ Randomly shift the stack (ASLR)

○ ...

Page 44: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

44Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex

● Adversarial Techniques

○ Detect QEMUmov eax, 0x1push eaxpush eaxpush eaxfld TBYTE PTR [esp]fsqrt

○ Backdoor

○ ...

Page 45: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

45Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex

● Making the original binary faster →

Our patches can be slower!

● Optimization Techniques:

○ Constant Propagation

○ Dead Assignment Elimination

○ ...

Page 46: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

46Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex – Backends

● Patching Backends

○ Inject code/data in an existing binary

○ No source code

○ No symbols

Page 47: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

47Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex – Backends

● How to inject code without breaking functionality?

0x0 : mov eax, 0x11

0x5 : jmp eax

0x7 : mov edx, 0x11223344

0xc : mov ebx, 0x55667788

0x11: mov ecx, ebx

0x0 : mov eax, 0x11

0x5 : jmp eax

0x7: call inserted_function

0xc : mov edx, 0x11223344

0x11: mov ebx, 0x55667788

0x16: mov ecx, ebx

Page 48: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

48Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex – Backends

● Detour Backend

○ Try to add code without moving the original one

○ Not always possible

○ Slow (requires a lot of additional jmp instructions)

0x0 : mov eax, 0x11

0x5 : jmp eax

0x7 : mov edx, 0x11223344

0xc : mov ebx, 0x55667788

0x11: mov ecx, ebx

0x0 : mov eax, 0x11

0x5 : jmp eax

0x7 : jmp out1

0xc : mov ebx, 0x55667788

0x11: mov ecx, ebx

mov edx, 0x11223344

call inserted_function

jmp 0xc

Page 49: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

49Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex – Backends

● Reassemler Backend

○ Recover original “program symbols”

○ More efficient code

○ (Slightly) less reliable

Ramblr: Making Reassembly Great Again.R. Wang, Y. Shoshitaishvili, A. Bianchi, A. Machiry, J. Grosen, P. Grosen, C. Kruegel, G. VignaIn NDSS 2017

Page 50: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

50Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Patcherex – Backends 0x0 : mov eax, 0x11

0x5 : jmp eax

0x7 : mov edx, 0x11223344

0xc : mov ebx, 0x55667788

0x11: mov ecx, ebx

mov eax, _label1

jmp eax

mov edx, 0x11223344

mov ebx, 0x55667788

_label1:

mov ecx, ebx

mov eax, _label1

jmp eax

call inserted_function

mov edx, 0x11223344

mov ebx, 0x55667788

_label1:

mov ecx, ebx0x0 : mov eax, 0x16

0x5 : jmp eax

0x7 : call inserted _function

0xc : mov edx, 0x11223344

0x11: mov ebx, 0x55667788

0x16: mov ecx, ebx

Page 51: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

51Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

How to play?

Infrastructure

Page 52: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

52Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Infrastructure

● Our code had to run for 10 hours on:

64 servers, 16TB of RAM, 2560 cores

● No human intervention →

No possibility of failure!

● Extremely hard to test the full system

○ A lot of test cases

○ Testing after every single git push

Page 53: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

53Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Infrastructure

● Separate and (mostly) independent tasks

● Every task run in a separate container

○ Docker

● Tasks are distributed “transparently” among servers

○ Kubernetes

Page 54: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

54Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

What Happened?

Page 55: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

55Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Results● Exploitation

○ 2442 Exploits generated

○ 1709 Exploits for 14/82 challenges with 100% Reliability

○ Longest exploit: 3791 lines of C code ○ crackaddr: 517 lines of C code

○ Shellphish exploited the most binaries!

● Defense○ Only 12/82 services were compromised○ Second best team in terms of defense points

Page 56: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

56Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Third Place! ::\OwO/::

● Third Place!

● Happiness!

● First among University-only teams

● First among unfunded teams

Page 57: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

57Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Results

Page 58: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

58Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

$$$

750,000 $ + 750,000 $ =

1,500,000 $

Page 59: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

59Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

What went wrong

● Our strategy was not ideal ~~ 囧

○ Patch everything!

○ Score penalty

○ Only 20/82 binaries were exploited in total

Page 60: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

60Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Open source release

● Open source all the code!

Page 61: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

61Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Open source release

● About 100,000 lines of Python code

● github.com/shellphish

○ Core, independent components: REX, Patcherex, ...

● github.com/mechaphish

○ Infrastructure, utilities, and documentation

● github.com/angr

○ Binary analysis framework, symbolic execution, ...

Page 62: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

62Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Standing on the shoulders of giants

AFL

Unicorn Engine

Capstone EngineVEX

Page 63: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

63Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

Future Directions

● Human-assisted automatic exploitation and defense

● You can contribute

○ Port code to non-CGC architecture

○ Are you a student?Looking for an internship?Master thesis? Wanting to do a PhD?Want a free Shellphish Tshirt/sticker?

Page 64: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 65: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

65Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

CGC – Timeline

2014

Shellphish

signs u

p!

Qualification!

Online eve

nt, June 2015

Finals!

Live eve

nt, August

2016

Open source release!

Two crazy months!

Page 66: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 67: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 68: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 69: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 70: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 71: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 72: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security
Page 73: Antonio Bianchi Automatic Binary University of California, Santa … · 2016-12-13 · Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish 2 A team of security

73Automatic Binary Exploitation and Patching using Mechanical [Shell]Phish

References:- all the technical details: “very soon” published in a “popular security ezine”- this presentation: goo.gl/RvDbxS- CGC final event show: youtu.be/n0kn4mDXY6I - Twitter:@shellphish- Twitter team: @anton00b - @caovc - @giovanni_vigna - @jac_arc - @ltFish_

@machiry_msdic - @nebirhos - @rhelmot - @zardus- email: [email protected] - [email protected] Github: github.com/shellphish - github.com/mechaphish - github.com/angr

The END

Questions?


Recommended