Top Banner
Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore USENIX Security Symposium 2015, Washington, D.C., USA
23

Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Dec 31, 2015

Download

Documents

Lynne Dean
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Automatic Generation of Data-Oriented Exploits

Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang

National University of Singapore

USENIX Security Symposium 2015, Washington, D.C., USA

Page 2: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Control Flow Attacks Are Getting Harder

• State-of-the-art exploits– Code injection • heap spray / JIT spray

– Code reuse • ret2libc, ROP

• control-flow bending

• Defenses– Data Execution

Prevention

– Control Flow Integrity

Page 3: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

•St

at-o

f-the

-art

expl

oits

from

mem

ory e

rrors

–Co

de in

jecti

on (e

.g.,

heap

spra

y / JI

T sp

ray)

–Co

de re

use

(e.g

., re

t2lib

c, RO

P)

•De

fens

es

–DE

P, CF

I, AS

LR

–Bl

ock c

ontro

l flow

hija

ckin

g in

prin

ciple

CONTROL PLANE

DATA PLANE

Page 4: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

// set root privilegeseteuid(0);...... // set normal user privilegeseteuid(pw->pw_uid); // execute user’s command

Data-Oriented Exploits• State-of-the-art: Corrupt security-critical data– leave control flow as the same– Exhibit “significant” damage

IE SafeMode Bypass+

+ Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014

//0x1D4, 0x1E4 or 0x1F4 in JScript 9, //0x188 or 0x184 in JScript 5.8, safemode = *(DWORD *)(jsobj + 0x188);if( safemode & 0xB == 0 ) { Turn_on_God_Mode(); }Wu-ftpd setuid operation*

* Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar, and Ravishankar K. Iyer. Non-Control-Data Attacks Are Realistic Threats. In USENIX 2005.

Page 5: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Contributions

• Data Flow Stitching– Systematic search for data-oriented exploits– Works on binary directly

• Results– Concrete exploits on real web/file servers– 19 exploits (16 new) from 8 vulnerabilities

• New class of Data-Oriented Exploits– Reuses existing data flows in normal execution– Agnostic to CFI, DEP and often ASLR

Page 6: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

1 int server() { 2 char *userInput, *fileName; 3 char *privKey, *result, output[BUFSIZE]; 4 char fullPath[BUFSIZE]="/path/to/root/"; 5 6 privKey=loadPrivKey("/path/to/privKey"); 7 GetConnection(privKey, ...); 8 userInput = read_socket(); 9 if (checkInput(userInput)) {10 fileName = getFileName(userInput);11 strcat(fullPath, fileName);12 result = retrieve(fullPath);13 sprintf(output, “%s:%s”, fileName, result);14 sendOut(output);15 } 16 }

• SSL-enabled web server

Motivating Example

privKey

PsVNXi…

userInput

fileName

GET /index.html HTTP/1.1

index.html

index.html : <html> …</html>

PsVNXi…

/path/to/root

/path/to/root/index.html

fullPath

<html> …</html>

result

output

PsVNXi… : <html> …</html

PsVNXi… : <html> …</html>

Page 7: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Data-Flow Stitching• Manipulate data flows for exploits • Enables systematic way to search for exploits

– Input: binary & error-exhibiting input– Output: data-oriented exploits

• Goal:– Information Leakage (e.g., password, keys)– Privilege Escalation (e.g., setuid, access priv. files)

• Constraints:– Keep the control-flow same– No knowledge of randomized values (CFI tags, ASLR addresses)

– Prevent abrupt termination

Page 8: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Challenges• Time-consuming search

– The search-space: Cartesian product |SrcFlow| X |TgtFlow| – Heavy analysis for each candidate

• Our solution:– Filter out candidates with memory error influence – Use an SMT solver to verify candidates

Target flow

t0 execution

Source flow

v2 VT

v1VS

Page 9: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Single-Edge Stitch

0

address

time

&arg

a1

&uid

3 4 9

• Corrupt data vertex

100

100100

100

1 struct passwd {uid_t pw_uid; ... } pw; 2 ... 3 int uid = getuid(); 4 pw->pw_uid = uid; 5 printf(...); //format string error 6 ... 7 seteuid(0); //set root uid 8 ... 9 seteuid(pw->pw_uid); //set normal uid10 ...

5

I

100

0

00

Attack

0

Page 10: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Pointer Stitch• Corrupt pointers to connect data flows

– Pointers decide data movement direction

0

0

0

address

b1

b2

time

source flow

&arg

a1 100

100

a1

target flow

&pw

4 92

100

a1

5

I

0

Page 11: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Pointer Stitch

0

0

0

b1

b2

time

source flow

&arg

a1 100

100

a1

target flow

&pw

4 92

100

a1

5

I

b2 b2

0

0

address

• Corrupt pointers to connect data flows– Pointers decide data movement direction

Page 12: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Pointer Stitch

Attack0

0

0

b1

b2

time

source flow

&arg

a1 100

a1

target flow

&pw

4 92 5

I

b2 b2

0

0

address

• Corrupt pointers to connect data flows– Pointers decide data movement direction

• Pointer Stitch corrupts pointer vp– *(vp) ---> target / source vertex

Page 13: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Pointer Stitch

time

100

a1

target flow

4 92 5

• Pointer Stitch corrupts pointer vp– *(vp) ---> target / source vertex

100

&pw

a1b2

0

0

0b2 b2

0

&arg

a1

&pw

address

Page 14: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

More Ways of Stitches• 2-level stitch corrupts pointer vp2

– *(*(vp2)) ---> *(vp) ---> target / source vertex

• N-level stitch corrupts pointer vpN

– *(*(…(vpN)…)) ---> target / source vertex – Recursively invoke pointer stitch N times– Stitch Alignment

• vpN ---> vpN’ so that *(*(…(vpN

’)…)) is the source / target vertex

• Multi-flow stitching– Intermediate data flows – Source flow -> flow 1 -> flow 2 -> … -> Target flow

Page 15: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Defeat ASLR --- Address Reuse• Partial resue: offset is fixed

• Complete reuse: – randomized address in memory//attacker controls %eaxmov (%esi, %eax, 4), %ebxmov (%ebx), %ecx

//attackers control %eaxmov (%esi,%eax,4), %ebx

mov %ecx, (%edi,%eax,4)

0 time

address

3 7

&ud.uid

&arg

5

100

100

I

0

Attack 0

stack area

vsprintf… …. %X$n

&ud.uid

mov %ecx, (%ebx)

Page 16: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Stitch with ASLR• Target deterministic addresses– non-PIE binaries on Linux

– msvcr71.dll, hxds.dll on Windows

0> 1> 8

> 16> 32> 64

> 128> 256> 512

0 10 20 30 40 50 60 70 80

150113147103

/sbin/bin/usr/sbin/usr/bin

Size of fixed space (KB)

# of programs

Page 17: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

FlowStitch

error-exhibiting benign

candidate exploits

constraints,influence

imp. data,data flows

error-exhibiting

trace

benign trace

DOE

Data-Flow Stitching

SMTSolver

Page 18: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Evaluation --- Generated ExploitsID Vul. bin Vulnerability Data-Oriented Exploits ASLR

CVE-2013-2028 nginx Stack bofL0 : private key

M0: http root dirCVE-2012-0809 sudo Format string M0: user id

CVE-2009-4769 httpdx Format string

L0: admin’s passwd M0: admin;s passwd

M1: anon.’s permissionM2: anon.’s root dirM3: CGI root dir

bugtraq ID: 41956 orzhttpd Format string

L0: randomized addr M0: http root dir

CVE-2002-1496 * nullhttpd Heap overflowM0: http root dirM1: CGI root dir

CVE-2001-0820 * ghttpd Stack bof M0: CGI root dir

CVE-2001-0144 * SSHD integer overflow

L0: root passwd hashM0: user idM1: authenticated flag

CVE-2000-0573 * wu-ftpd Format stringL0: env variablesM0: user id (single-edge) M1: user id (pointer stitch) * CVEs discussed in Shuo Chen’s work [1]

• 19 exploits• 16 prev. unknown• 7 advanced stitch

2-level stitch

• 10 bypass ASLR 8 fixed addresses 2 address reuse

Page 19: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Evaluation --- Performance

• 6.5 min/exploit• Slice takes long

– faster version is available (binary version)

nginx:L

0

nginx:M

0

sudo:M

0

httpdx:L0

httpdx:M0

httpdx:M1

httpdx:M2

httpdx:M3

orzhttpd:L0

orzhttpd:M

0

null httpd:M

0

null httpd:M

1

ghttpd:M

0

SSHD:L0

SSHD:M

0

SSHD:M

1

wu-ftpd:L0

wu-ftpd:M

0

wu-ftpd:M

1

Averag

e0.00

2.00

4.00

6.00

8.00

10.00

12.00

14.00 slice-benign

slice-error

trace-benign

trace-error

Page 20: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Case Study – 2-Level Stitch• ghttpd web server: stack buffer overflow

• Previous exploit[1]

– Corrupt pointer ptr: *(ptr) -> url

• We build a 2-level stitch – Corrupt pointer saved ebp: *(*(saved ebp)) -> *ptr -> url

//serveconnection(): char *ptr; //URL pointer //esi is allocated for it1: if(strstr(ptr,”/..”)) reject the request; 2: log(...); 3: exec(ptr);

Assembly of log(...) push %ebp push %esi // stack overflow pop %esi pop %ebp ret

Assembly of line 3: push %esi … call <exec@plt>

mov -0xc(%ebp), %esi

does not work any more

Page 21: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Case Study – Sensitive Data Lifespan• SSHD hashed key info leak• getspnam() in glibc gets hashed key (heap copy)

– endspent() in glibc releases memory, not clears it!– Still alive for stitching

• SSHD copies hashed key to local stack (stack copy)– Overwritten by later usage

• Challenging to make lifespan correct!

Page 22: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Conclusion• Rich Category: Data-Oriented Exploits– Single-edge stitch, Pointer stitch – N-level stitch, Multi-flow stitch

• Data Flow Stitching– Systematic way to generate data-oriented exploits– Agnostic to CFI, DEP and often ASLR

• Automatic construction is feasible

Page 23: Automatic Generation of Data-Oriented Exploits Hong Hu, Zheng Leong Chua, Sendroiu Adrian, Prateek Saxena, Zhenkai Liang National University of Singapore.

Thanks!

Hong [email protected]

http://www.comp.nus.edu.sg/~huhong/