systematic methods for memory error detection and ...turn_on_god_mode(); } + yang yu. write once,...

103
Data-Oriented Programming On the Expressiveness of Non-Control Data Attacks Hong Hu, Shweta Shinde, Sendroiu Adrian, Zheng Leong Chua, Prateek Saxena, Zhenkai Liang Department of Computer Science National University of Singapore

Upload: others

Post on 28-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Programming On the Expressiveness of Non-Control Data Attacks

Hong Hu, Shweta Shinde, Sendroiu Adrian, Zheng Leong Chua,

Prateek Saxena, Zhenkai Liang

Department of Computer Science National University of Singapore

Page 2: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Control Attacks are Getting Harder

2

Page 3: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Control Attacks are Getting Harder

3

Memory space

Code

Data

CFG

Page 4: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Control Attacks are Getting Harder • Code injection

4

Memory space

Code

Data

CFG

Page 5: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Control Attacks are Getting Harder • Code injection

5

Memory space

Code

Data Data w/ DEP

Data Execution Prevention

CFG

Page 6: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Control Attacks are Getting Harder • Code injection • Code reuse – return-to-libc – return-oriented programming (ROP)

6

Memory space

Code

Data Data w/ DEP

Data Execution Prevention

CFG

Page 7: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Control Attacks are Getting Harder • Code injection • Code reuse – return-to-libc – return-oriented programming (ROP)

7

Memory space

Code

Data Data w/ DEP

Data Execution Prevention Control Flow Integrity

CFG w/ CFI

Page 8: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

A New Attack Class • Assume: conform to CFI & DEP

8

Memory space

Code

Data w/ DEP

CFG w/ CFI

Page 9: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

A New Attack Class • Assume: conform to CFI & DEP • Attackers’ capability on arbitrary vul. programs?

9

Memory space

Code

Data w/ DEP

CFG

Nothing Turing-complete Specific computation

w/ CFI

Page 10: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Non-Control Data Attacks

10

• Corrupt/leak several bytes of security-critical data

Page 11: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Non-Control Data Attacks

11

• Corrupt/leak several bytes of security-critical data //set root privilege *

seteuid(0);

......

//set normal user privilege

seteuid(pw->pw_uid);

//execute user’s command

//offset depends on IE version +

safemode = *(DWORD *)

(jsobj + offset);

if(safemode & 0xB == 0) {

Turn_on_God_Mode();

}

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

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

Page 12: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Non-Control Data Attacks

12

• Special cases relying on particular data/functions – user id, safemode, private key, etc – interpreter – printf() (with “%n”), etc

//set root privilege *

seteuid(0);

......

//set normal user privilege

seteuid(pw->pw_uid);

//execute user’s command

//offset depends on IE version +

safemode = *(DWORD *)

(jsobj + offset);

if(safemode & 0xB == 0) {

Turn_on_God_Mode();

}

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

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

• Corrupt/leak several bytes of security-critical data

Nothing Turing-complete Specific computation

Page 13: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Contributions

13

• Non-control data attacks can be Turing-complete

Page 14: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Contributions

14

• Non-control data attacks can be Turing-complete

• Data-Oriented Programming (DOP) – build expressive non-control data attacks – independent of any specific data / functions

Page 15: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Contributions

15

• Non-control data attacks can be Turing-complete

• Data-Oriented Programming (DOP) – build expressive non-control data attacks – independent of any specific data / functions

• DOP builds attacks on real-world programs – bypass ASLR w/o address leakage – simulate a network bot – enable code injection

Page 16: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

16

Vulnerable Program

Page 17: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

17

Vulnerable Program

Page 18: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

18

Vulnerable Program

Page 19: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

19

1 struct Obj {struct Obj *next; int prop;}

2

3 void updateList(struct Obj *list, int addend){

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

6 }

Vulnerable Program

Malicious Computation

Page 20: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

20

1 struct Obj {struct Obj *next; int prop;}

2

3 void updateList(struct Obj *list, int addend){

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

6 }

Vulnerable Program

Malicious Computation

CFG w/ CFI

6

7

8

9

10 12

13 14

Page 21: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

21

1 struct Obj {struct Obj *next; int prop;}

2

3 void updateList(struct Obj *list, int addend){

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

6 }

Vulnerable Program

Malicious Computation

CFG w/ CFI

6

7

8

9

10 12

13 14

Page 22: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

1 struct server{int *cur_max, total, typ;} *srv;

2 int quota = MAXCONN; int *size, *type;

3 char buf[MAXLEN];

4 size = &buf[8]; type = &buf[12]

5 ...

6 while (quota--) {

7 readData(sockfd, buf); // stack bof

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(following code skipped)...

15 }

Motivating Example

22

1 struct Obj {struct Obj *next; int prop;}

2

3 void updateList(struct Obj *list, int addend){

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

6 }

Vulnerable Program

Malicious Computation

CFG w/ CFI

6

7

8

9

10 12

13 14

Page 23: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

23

? simulate vulnerable program

malicious computation

Page 24: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

24

Memory space

? simulate vulnerable program

malicious computation

Page 25: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

25

Memory space

? simulate vulnerable program

malicious computation

next prop next prop

list addend

heap

Page 26: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

26

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 27: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

27

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 28: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

28

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 29: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

29

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 30: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

30

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 31: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

31

Memory space

next prop next prop

list addend

cur_ max total typ

? simulate vulnerable program

malicious computation

heap

Page 32: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

32

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 33: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

33

Memory space

next prop next prop

list addend

?

cur_ max total typ

simulate vulnerable program

malicious computation

heap

Page 34: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

34

Memory space

next prop next prop

list addend

?

cur_ max total typ

simulate vulnerable program

malicious computation

heap

Page 35: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

35

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

Page 36: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

36

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

STREAM

Page 37: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

37

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

STREAM

Page 38: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

38

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

STREAM

Page 39: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

39

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

STREAM

cur_ max cur_ max total typ

Page 40: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

40

Memory space

next prop next prop

list addend

? simulate vulnerable program

malicious computation

heap

STREAM

Page 41: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

4 for(; list != NULL; list = list->next)

5 list->prop += addend;

stack srv quota size type buf[]

cur_ max total typ

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 }

15 }

Motivating Example (cont.)

41

Memory space

next prop next prop

list addend STREAM

9 simulate vulnerable program

malicious computation

heap

Page 42: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Programming

A Generic Technique

42

Page 43: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• General construction – w/o dependency on specific data / functions

Data-Oriented Programming (DOP)

43

Page 44: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• General construction – w/o dependency on specific data / functions

• Expressive attacks – towards Turing-complete computation

Data-Oriented Programming (DOP)

44

Page 45: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• General construction – w/o dependency on specific data / functions

• Expressive attacks – towards Turing-complete computation

• Elements – data-oriented gadgets – gadget dispatchers

Data-Oriented Programming (DOP)

45

Page 46: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Gadgets • x86 instruction sequence – show in normal execution (CFI)

46

CFG 6

7

8

9

10 12

13 14

Page 47: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Gadgets • x86 instruction sequence – show in normal execution (CFI)

Addition: srv->total += *size;

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 add %ebx, %eax //addition

4 mov %eax, (%edi) //store micro-op

47

CFG 6

7

8

9

10 12

13 14

Page 48: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Gadgets • x86 instruction sequence – show in normal execution (CFI) – save results in memory – load micro-op --> semantics

micro-op --> store micro-op Addition: srv->total += *size;

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 add %ebx, %eax //addition

4 mov %eax, (%edi) //store micro-op

48

CFG 6

7

8

9

10 12

13 14

Page 49: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Gadgets • x86 instruction sequence – show in normal execution (CFI) – save results in memory – load micro-op --> semantics

micro-op --> store micro-op Addition: srv->total += *size;

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 add %ebx, %eax //addition

4 mov %eax, (%edi) //store micro-op

49

CFG 6

7

8

9

10 12

13 14

Memory space

Page 50: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Gadgets • x86 instruction sequence – show in normal execution (CFI) – save results in memory – load micro-op --> semantics

micro-op --> store micro-op Addition: srv->total += *size;

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 add %ebx, %eax //addition

4 mov %eax, (%edi) //store micro-op

Load: *size = *(srv ->cur_max);

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 mov 0xb(%ebx), %eax //load

4 mov %eax, (%edx) //store micro-op 50

CFG 6

7

8

9

10 12

13 14

Memory space

Page 51: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Data-Oriented Gadgets • x86 instruction sequence – show in normal execution (CFI) – save results in memory – load micro-op --> semantics

micro-op --> store micro-op Addition: srv->total += *size;

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 add %ebx, %eax //addition

4 mov %eax, (%edi) //store micro-op

Load: *size = *(srv ->cur_max);

1 mov (%esi), %ebx //load micro-op

2 mov (%edi), %eax //load micro-op

3 mov 0xb(%ebx), %eax //load

4 mov %eax, (%edx) //store micro-op 51

CFG 6

7

8

9

10 12

13 14

Memory space

Page 52: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher round1

round2

round3

roundN ……

corruptible by mem-err

52

loop selector

Page 53: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher round1

round2

round3

roundN ……

corruptible by mem-err

53

loop selector

• Chain data-oriented gadgets “legitimately” – loop ---> repeatedly invoke gadgets – selector ---> selectively activate gadgets

Page 54: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher

• Chain data-oriented gadgets “legitimately” – loop ---> repeatedly invoke gadgets – selector ---> selectively activate gadgets

round1

round2

round3

roundN ……

corruptible by mem-err

54

loop selector

1 2 3 4

Page 55: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher

• Chain data-oriented gadgets “legitimately” – loop ---> repeatedly invoke gadgets – selector ---> selectively activate gadgets

round1

round2

round3

roundN ……

corruptible by mem-err

55

loop selector

1 2 3

5 6

4

7

Page 56: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher

• Chain data-oriented gadgets “legitimately” – loop ---> repeatedly invoke gadgets – selector ---> selectively activate gadgets

round1

round2

round3

roundN ……

corruptible by mem-err

56

loop selector

1 2 3

5 6

4

7

1 2 3 4

Page 57: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher

• Chain data-oriented gadgets “legitimately” – loop ---> repeatedly invoke gadgets – selector ---> selectively activate gadgets

round1

round2

round3

roundN ……

corruptible by mem-err

57

loop selector

1 2 3

5 6

4

7

1 2 3 4

Page 58: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Gadget Dispatcher

• Chain data-oriented gadgets “legitimately” – loop ---> repeatedly invoke gadgets – selector ---> selectively activate gadgets

round1

round2

round3

roundN ……

corruptible by mem-err

58

loop selector

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM) *size = *(srv->cur_max);

10 else{ srv->typ = *type; srv->total += *size; }

14 }

// loop // selector

1 2 3

5 6

4

7

1 2 3 4

Page 59: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Turing-completeness • DOP emulates a minimal language MINDOP – MINDOP is Turing-complete

59

Semantics Statements In C

Data-Oriented Gadgets in DOP

arithmetic / logical a op b *p op *q assignment a = b *p = *q load a = *b *p = **q store *a = b **p = *q jump goto L vpc = &input conditional jump if (a) goto L vpc = &input if *p

p – &a; q – &b; op – any arithmetic / logical operation

Page 60: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Attack Construction

60

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(code skipped)...

15 }

Page 61: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Attack Construction

• Gadget identification – statically identify load-semantics-store chain from LLVM IR

61

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(code skipped)...

15 }

Page 62: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Attack Construction

• Gadget identification – statically identify load-semantics-store chain from LLVM IR

• Dispatcher identification – static identify loops with gadgets from LLVM IR

62

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(code skipped)...

15 }

Page 63: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Attack Construction

• Gadget identification – statically identify load-semantics-store chain from LLVM IR

• Dispatcher identification – static identify loops with gadgets from LLVM IR

• Gadget stitching – select gadgets and dispatchers (manual) – check stitchability (manual) 63

6 while (quota--) {

7 readData(sockfd, buf);

8 if(*type == NONE ) break;

9 if(*type == STREAM)

10 *size = *(srv->cur_max);

11 else {

12 srv->typ = *type;

13 srv->total += *size;

14 } //...(code skipped)...

15 }

Page 64: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Evaluation

64

Page 65: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Evaluation – Feasibility 9 x86 programs with 9 vulnerabilities – Nginx, ProFTPD, Wu-FTPD, sshd, Bitcoind, – Wireshark, sudo, musl libc, mcrypt

65

Page 66: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Evaluation – Feasibility 9 x86 programs with 9 vulnerabilities – Nginx, ProFTPD, Wu-FTPD, sshd, Bitcoind, – Wireshark, sudo, musl libc, mcrypt

• x86 Gadgets – 7518 in total, 1273 reachable via selected CVEs – 8 programs can simulate all MINDOP operations

• x86 Dispatchers – 1443 in total, 110 reachable from selected CVEs

66

Page 67: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Evaluation – Feasibility 9 x86 programs with 9 vulnerabilities – Nginx, ProFTPD, Wu-FTPD, sshd, Bitcoind, – Wireshark, sudo, musl libc, mcrypt

• x86 Gadgets – 7518 in total, 1273 reachable via selected CVEs – 8 programs can simulate all MINDOP operations

• x86 Dispatchers – 1443 in total, 110 reachable from selected CVEs

• 2 programs can build Turing-complete attack • 3 end-to-end attacks

67

Page 68: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization • Previous methods – information leakage to network

• Defeat ASLR w/o address leakage to network?

68

Page 69: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization • Previous methods – information leakage to network

• Defeat ASLR w/o address leakage to network? • Vulnerable ProFTPD – use OpenSSL for authentication – a dereference chain to the private key

69

Page 70: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization • Previous methods – information leakage to network

• Defeat ASLR w/o address leakage to network? • Vulnerable ProFTPD – use OpenSSL for authentication – a dereference chain to the private key

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

70

Page 71: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization • Gadgets

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

MOV ADD LOAD

*p = *q *X = *X + offset *Z = **Y

71

Page 72: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization • Gadgets • Dispatcher

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

MOV ADD LOAD

*p = *q *X = *X + offset *Z = **Y

while (1) {

user_request =

get_user_request();

dispatch(user_request);

}

func1() { memory_error; MOV;}

func2() { ADD; }

func3() { LOAD; }

72

Page 73: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

MOV ADD MOV LOAD MOV

*X = *0x080dbc28 (ssl_ctx) *X = *X + offset1 *Y = *X *Z = **Y *0x080dbc28 = *Z (cert)

73

Page 74: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

MOV ADD MOV LOAD MOV

*X = *0x080dbc28 (ssl_ctx) *X = *X + offset1 *Y = *X *Z = **Y *0x080dbc28 = *Z (cert)

74

ssl_ctx

@0x080dbc28

cert

Page 75: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

75

d2

@0x080dbc28

MOV ADD MOV LOAD MOV

*X = *0x080dbc28 (ssl_ctx) *X = *X + offset1 *Y = *X *Z = **Y *0x080dbc28 = *Z (cert)

Page 76: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

76

d2

@0x080dbc28

write(outsock, buf, strlen(buf));

buf

MOV ADD MOV LOAD MOV

*X = *0x080dbc28 (ssl_ctx) *X = *X + offset1 *Y = *X *Z = **Y *0x080dbc28 = *Z (cert)

Page 77: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

77

d2

@0x080dbc28

write(outsock, buf, strlen(buf));

buf

MOV ADD MOV LOAD MOV

*X = *0x080dbc28 (ssl_ctx) *X = *X + offset1 *Y = *X *Z = **Y *0x080dbc28 = *Z (cert)

Page 78: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Bypassing Randomization

Private Key

BN_ULONG * d2 BIGNUM * d1

struct rsa_st * rsa

EVP_PKEY*privatekey CERT_PKEY * key

struct cert_st * cert

@0x080dbc28 SSL_CTX * ssl_ctx

78

d2

@0x080dbc28

write(outsock, buf, strlen(buf));

buf

MOV ADD MOV LOAD MOV

*X = *0x080dbc28 (ssl_ctx) *X = *X + offset1 *Y = *X *Z = **Y *0x080dbc28 = *Z (cert)

leak private key to network

Page 79: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

dlopen() – Dynamic Linking Interface • Load the dynamic library into memory space – resolve symbols based on binary metadata – patch program due to relocation – like LoadLibrary() on Windows

79

Page 80: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

dlopen() – Dynamic Linking Interface • Load the dynamic library into memory space – resolve symbols based on binary metadata – patch program due to relocation – like LoadLibrary() on Windows

• Dynamic loader can do arbitrary computation*

80 * R. Shapiro, S. Bratus, and S. W. Smith, ““Weird Machines” in ELF: A Spotlight on the Underappreciated Metadata,” in WOOT 2013.

exec() sysexec ld.so bin

libc.so

RTLD_ START()

_start()

bin ld.so libc.so file access before run

Page 81: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

dlopen() – Dynamic Linking Interface • Load the dynamic library into memory space – resolve symbols based on binary metadata – patch program due to relocation – like LoadLibrary() on Windows

• Dynamic loader can do arbitrary computation*

• The same to dlopen()

81 * R. Shapiro, S. Bratus, and S. W. Smith, ““Weird Machines” in ELF: A Spotlight on the Underappreciated Metadata,” in WOOT 2013.

exec() sysexec ld.so bin

libc.so

RTLD_ START()

_start()

bin ld.so libc.so file access before run

Page 82: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• Attacks with dlopen

82

dlopen() { } head …… dynamic library list link_map

Case Study: Simulating A Network Bot

Page 83: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• Attacks with dlopen – send malicious payload

ProFTPD’s memory Malicious payload

83

dlopen() { } head …… dynamic library list link_map

Case Study: Simulating A Network Bot

Page 84: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• Attacks with dlopen – send malicious payload – corrupt link list & call dlopen

ProFTPD’s memory Malicious payload

84

dlopen() { } head …… dynamic library list link_map

Case Study: Simulating A Network Bot

Page 85: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• Attacks with dlopen – send malicious payload – corrupt link list & call dlopen

ProFTPD’s memory Malicious payload

85

dlopen() { } head …… dynamic library list link_map

invalid input

Case Study: Simulating A Network Bot

Page 86: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

• Attacks with dlopen – send malicious payload – corrupt link list & call dlopen

ProFTPD’s memory Malicious payload

86

dlopen() { } head …… dynamic library list link_map

invalid input no call to dlopen

Case Study: Simulating A Network Bot

Page 87: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

ProFTPD’s memory Malicious payload

Case Study: Simulating A Network Bot

87

dlopen() { } head …… dynamic library list link_map

• dlopen allows arbitrary computation – send malicious payload – corrupt link list & call dlopen

• DOP attack addresses the problems invalid input no call to dlopen

Page 88: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

ProFTPD’s memory Malicious payload

Case Study: Simulating A Network Bot

88

dlopen() { } head …… dynamic library list link_map

• dlopen allows arbitrary computation – send malicious payload – corrupt link list & call dlopen

• DOP attack addresses the problems – construct payload in memory invalid input

no call to dlopen

(1) Payload prepare

MOV MOV

Page 89: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

ProFTPD’s memory Malicious payload

Case Study: Simulating A Network Bot

89

dlopen() { } head …… dynamic library list link_map

• dlopen allows arbitrary computation – send malicious payload – corrupt link list & call dlopen

• DOP attack addresses the problems – construct payload in memory invalid input

no call to dlopen

(1) Payload prepare

MOV MOV

Page 90: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

if (flag) { }

ProFTPD’s memory Malicious payload

Case Study: Simulating A Network Bot

90

dlopen() { } head …… dynamic library list link_map

• dlopen allows arbitrary computation – send malicious payload – corrupt link list & call dlopen

• DOP attack addresses the problems – construct payload in memory – force call to dlopen

invalid input no call to dlopen

(1) Payload prepare

MOV MOV

Page 91: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

if (flag) { }

ProFTPD’s memory Malicious payload

Case Study: Simulating A Network Bot

91

(2) Trigger MOV

STORE

dlopen() { } head …… dynamic library list link_map

• dlopen allows arbitrary computation – send malicious payload – corrupt link list & call dlopen

• DOP attack addresses the problems – construct payload in memory – force call to dlopen

invalid input no call to dlopen

(1) Payload prepare

MOV MOV

Page 92: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

if (flag) { }

ProFTPD’s memory Malicious payload

Case Study: Simulating A Network Bot

92

(2) Trigger MOV

STORE

> 700 requests

dlopen() { } head …… dynamic library list link_map

• dlopen allows arbitrary computation – send malicious payload – corrupt link list & call dlopen

• DOP attack addresses the problems – construct payload in memory – force call to dlopen

invalid input no call to dlopen

(1) Payload prepare

MOV MOV

Page 93: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Altering Memory Permissions • Defenses based on memory permissions – DEP: non-writable code – CFI: non-writable jump tags

93

Page 94: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Altering Memory Permissions • Defenses based on memory permissions – DEP: non-writable code – CFI: non-writable jump tags

• dlopen(): relocation – change any page permission to writable – update page content – change the permission back

94

Page 95: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Altering Memory Permissions • Defenses based on memory permissions – DEP: non-writable code – CFI: non-writable jump tags

• dlopen(): relocation – change any page permission to writable – update page content – change the permission back

• DOP attacks – dlopen(code_addr, shellcode)

95

Page 96: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Case Study: Altering Memory Permissions • Defenses based on memory permissions – DEP: non-writable code – CFI: non-writable jump tags

• dlopen(): relocation – change any page permission to writable – update page content – change the permission back

• DOP attacks – dlopen(code_addr, shellcode)

• Code injection is back! 96

Page 97: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Related Work

97

Techniques Turing Complete?

Preserve CFI?

Independent of specific

data / funcs?

Non-control Data Attacks (Chen et al. 2005) 9 COOP (Schuster et al. 2015) 9 9 FlowStitch (Hu et al. 2015) 9 Printf-Oriented Programming (Carlini et al. 2015) 9 9 Control Jujustu (Evans et al. 2015) 9 Data-Oriented Programming 9 9 9

Page 98: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Potential Defenses • Memory Safety – e.g., Cyclone (Jim et al. 2002), CCured (Necula et al. 2002) ,

SoftBounds+CETS (Nagarakatte et al. 2009, 2010)

– high performance overhead (> 100%)

• Data-flow Integrity – e.g, DFI (Castro et al. 2006) , kernel DFI (Song et al. 2016)

• Fined-grained randomization in data space – e.g., DSR (Bhatkar et al. 2008)

• Hardware & software fault isolation – e.g., HDFI (Song et al. 2016) , MPX

98

Page 99: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Potential Defenses • Memory Safety – e.g., Cyclone (Jim et al. 2002), CCured (Necula et al. 2002) ,

SoftBounds+CETS (Nagarakatte et al. 2009, 2010)

– high performance overhead (> 100%)

• Data-flow Integrity – e.g, DFI (Castro et al. 2006) , kernel DFI (Song et al. 2016)

• Fined-grained randomization in data space – e.g., DSR (Bhatkar et al. 2008)

• Hardware & software fault isolation – e.g., HDFI (Song et al. 2016) , MPX

99 No practical defenses yet !

Page 100: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Conclusion

100

• Non-control data attacks can be Turing-complete

Page 101: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Conclusion

101

• Non-control data attacks can be Turing-complete

• Data-Oriented Programming (DOP) – build expressive non-control data attacks – independent of specific data / functions

Page 102: Systematic Methods for Memory Error Detection and ...Turn_on_God_Mode(); } + Yang Yu. Write Once, Pwn Anywhere. In Black Hat USA 2014 * Shuo Chen, Jun Xu, Emre C. Sezer, Prachi Gauriar,

Conclusion

102

• Non-control data attacks can be Turing-complete

• Data-Oriented Programming (DOP) – build expressive non-control data attacks – independent of specific data / functions

• In real-world programs, DOP can build attacks – bypass ASLR w/o address leakage – simulate a network bot – enable code injection