Lec07: Return-oriented programming Taesoo Kim 2 Scoreboard 3 - - PowerPoint PPT Presentation

lec07 return oriented programming
SMART_READER_LITE
LIVE PREVIEW

Lec07: Return-oriented programming Taesoo Kim 2 Scoreboard 3 - - PowerPoint PPT Presentation

1 Lec07: Return-oriented programming Taesoo Kim 2 Scoreboard 3 Administrivia Please submit both working exploit and write-up on time! Due: Lab04 is due on Oct 11 Due: Lab05 is out and its due on Oct 18 (two weeks)!


slide-1
SLIDE 1

Lec07: Return-oriented programming

Taesoo Kim

1

slide-2
SLIDE 2

Scoreboard

2

slide-3
SLIDE 3

Administrivia

  • Please submit both ‘working exploit’ and write-up on time!
  • Due: Lab04 is due on Oct 11
  • Due: Lab05 is out and its due on Oct 18 (two weeks)!
  • NSA Codebreaker Challenge → Due: Nov 29

3

slide-4
SLIDE 4

Best Write-ups for Lab04

xor gkamuzora3, burak stackshield gkamuzora3, nhicks6 weak-random palai, stong gs-random stong, riya terminator seulbae, stong assassination jwalsh45, nhicks6 mini-heartbleed stong, riya pltgot nhicks6, stong ssp palai, nhicks6 fd palai, fsang 4

slide-5
SLIDE 5

Discussion: Lab04

  • What’s the most “annoying” bug or challenge?
  • What’s the most “interesting” bug or challenge?
  • So, should we use canary or not?
  • So, which one would you like to use?

5

slide-6
SLIDE 6

Take-outs from Stack Canary?

  • Stack Canary indirectly protects the “integrity” of RA, funcptr, etc
  • (e.g., exploitation mitigation → NX, canary)
  • We better prevent buffer overflows at the first place
  • (e.g., code analysis, better APIs)

6

slide-7
SLIDE 7

Subtle Design Choices for the Stack Canary

  • Where to put? (e.g., right above ra? fp? local vars?)
  • Which value should I use? (e.g., secrete? random? per exec? per func?)
  • How to check its integrity? (e.g., xor? cmp?)
  • What to do after you find corrupted? (e.g., crash? report?)

7

slide-8
SLIDE 8

Subtle Design Choices for the Stack Canary

  • Where to put? (e.g., right above ra? fp? local vars?)
  • gs-random, terminator
  • Which value should I use? (e.g., secrete? random? per exec? per func?)
  • xor, weak-random, gs-random, terminator
  • How to check its integrity? (e.g., xor? cmp?)
  • xor
  • What to do after you find corrupted? (e.g., crash? report?)
  • ssp, stackshield
  • Fundaemtnal limitations → stackshield, assassination, gs-random

8

slide-9
SLIDE 9

Discussion: xor

  • How xor canary works?
  • What happens if RA is overwritten (or leaked)?
  • RA ^ canary
  • what happens if RA is overwritten?
  • what if we make it random?

9

slide-10
SLIDE 10

Discussion: xor

@prologue pop %eax xor $0x63736265,%eax push %eax 10

slide-11
SLIDE 11

Discussion: stackshield (safestack)

  • How stackshield works? (can you overwrite ra/fp?)
  • Compared to xor, what’s better?
  • Then, could you control its control flow?

11

slide-12
SLIDE 12

Discussion: weak-random

  • How weak-random is implemented?
  • How did you exploit?
  • What if we use a perfect random value (e.g., /dev/random)?

12

slide-13
SLIDE 13

Discussion: gs-random

  • Near perfect (Microsoft CL):
  • strong randomness: /dev/random
  • protect fp/ra

13

slide-14
SLIDE 14

Discussion: gs-random

void echo(char *msg) { char buf[80]; strcpy(buf, msg); capitalize(buf); strcpy(msg, buf); ... } 14

slide-15
SLIDE 15

Discussion: gs-random (arbitrary overwrite)

15

slide-16
SLIDE 16

Discussion: gs-random

16

slide-17
SLIDE 17

Discussion: terminator

  • Why is the terminator canary special?
  • 0x0d000aff: NULL(0x00), CR (0x0d), LF (0x0a) and EOF (0xff)

17

slide-18
SLIDE 18

Discussion: terminator

  • What’s the vulnerability?

18

slide-19
SLIDE 19

Discussion: terminator (off-by-one)

19

slide-20
SLIDE 20

Discussion: terminator

  • How to prevent this vulnerability?

20

slide-21
SLIDE 21

Discussion: assassination

  • Near perfect (GCC)
  • random canary
  • protect fp, ra
  • What’s the bug?
  • How to prevent?

21

slide-22
SLIDE 22

Discussion: mini-heartbleed

22

slide-23
SLIDE 23

Discussion: ssp

  • What happens if you cause a crash?

23

slide-24
SLIDE 24

Discussion: ssp

24

slide-25
SLIDE 25

Discussion: ssp

25

slide-26
SLIDE 26

Discussion: ssp

26

slide-27
SLIDE 27

Discussion: pltgot

  • What was the vulnerability?
  • Where to overwrite?
  • How to prevent?

27

slide-28
SLIDE 28

Discussion: fd

  • Overwriting ‘struct FILE’

@libio.h struct _IO_FILE { int _flags; ... struct _IO_wide_data { ... const struct _IO_jump_t *_wide_vtable; } } 28

slide-29
SLIDE 29

Discussion: fd

  • Why need vtable?

29

slide-30
SLIDE 30

Discussion: fd

_IO_wfile_jumps (default) _IO_wfile_jumps_mmap ... fclose(fp)?

  • _IO_file_close(): close()
  • _IO_file_close_mmap(): munmap() & close()

30

slide-31
SLIDE 31

Discussion: fd

  • How to prevent this vulnerability?

31

slide-32
SLIDE 32

Today’s Tutorial

  • In-class tutorial:
  • Ret-to-libc
  • Code pointer leakage / gadget finding
  • First ROP!

32

slide-33
SLIDE 33

Reminder: crackme0x00

void start() { printf("IOLI Crackme Level 0x00\n"); printf("Password:"); char buf[32]; memset(buf, 0, sizeof(buf)); read(0, buf, 256); if (!strcmp(buf, "250382")) printf("Password OK :)\n"); else printf("Invalid Password!\n"); } 33

slide-34
SLIDE 34

Reminder: crackme0x00

$ checksec ./target [*] '/home/lab/tut-rop/target' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) 34

slide-35
SLIDE 35

Reminder: crackme0x00

int main(int argc, char *argv[]) { setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0); void *self = dlopen(NULL, RTLD_NOW); printf("stack : %p\n", &argc); printf("system(): %p\n", dlsym(self, "system")); printf("printf(): %p\n", dlsym(self, "printf")); start(); return 0; } 35

slide-36
SLIDE 36

Ret-to-libc: printf

[buf ] [.....] [ra ] -> printf [dummy] [arg1 ] -> "Password OK :)" 36

slide-37
SLIDE 37

Ret-to-libc: system

[buf ] [.....] [ra ] -> system [dummy] [arg1 ] -> "/bin/sh" 37

slide-38
SLIDE 38

Chaining Two Function Calls

printf("Password OK:)") system("/bin/sh") 38

slide-39
SLIDE 39

Chaining Two Function Calls

[buf ] [..... ] [old-ra ] -> 1) printf [ra ] -------------------> 2) system [old-arg1 ] -> 1) "Password OK :)" [arg1 ] -> "/bin/sh" 39

slide-40
SLIDE 40

Chaining N Function Calls

[buf ] [..... ] [old-ra ] -> 1) printf [ra ] -------------------> pop/ret gadget [old-arg1 ] -> 1) "Password OK :)" [ra ] -> 2) system [ra ] -------------------> pop/ret gadget [arg1 ] -> "/bin/sh" [ra ] ... 40

slide-41
SLIDE 41

Tutorial Goal: Chaining Three Calls

  • pen("/proc/flag", O_RDONLY)

read(3, tmp, 1024) write(1, tmp, 1024) 41

slide-42
SLIDE 42

In-class Tutorial

  • Step1: Ret-to-libc
  • Step2: Understanding module base
  • Step3: First ROP

$ ssh lab06@computron.gtisc.gatech.edu -p 9006 $ ssh lab06@cyclonus.gtisc.gatech.edu -p 9006 Password: lab06 $ cd tut-rop $ cat README 42

slide-43
SLIDE 43

References

  • ROP

43