rop heap attacks cfi integer overflows
play

ROP, heap attacks, CFI, integer overflows Nadia Heninger and Deian - PowerPoint PPT Presentation

CSE 127: Computer Security ROP, heap attacks, CFI, integer overflows Nadia Heninger and Deian Stefan Some slides adopted from Kirill Levchenko, Stefan Savage, Stephen Checkoway, Hovav Shacham, Raluca Popal, and David Wagner Review: calling and


  1. 
 
 
 How dow you use this as an attacker? • Overflow the stack with values and addresses to such gadgets to express your program • E.g., if shellcode needs to write a value to %edx , use the previous gadget 
 v 1 pop %edx %esp ret

  2. What does this gadget do? mov %eax, %(ebx) ret v 2 pop %ebx ret v 1 pop %eax %esp ret

  3. relevant register(s): %eax = 0x00000000 %ebx = 0x00000000 relevant stack: relevant memory: 0xbadcaffe: 0x00000000 0x08049b90 relevant code: 0xbadcaffe 0x08049b63 0x08049b00: ret %eip ... 0xdeadbeef 0x08049b63: pop %ebx 0x08049bbc %esp 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) 0x08049b91: ret ... 0x08049bbc: pop %eax 0x08049bbd: ret

  4. relevant register(s): %eax = 0x00000000 %ebx = 0x00000000 relevant stack: relevant memory: 0xbadcaffe: 0x00000000 0x08049b90 relevant code: 0xbadcaffe 0x08049b63 0x08049b00: ret ... 0xdeadbeef %esp 0x08049b63: pop %ebx 0x08049bbc 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) 0x08049b91: ret ... %eip 0x08049bbc: pop %eax 0x08049bbd: ret

  5. relevant register(s): %eax = 0xdeadbeef %ebx = 0x00000000 relevant stack: relevant memory: 0xbadcaffe: 0x00000000 0x08049b90 relevant code: 0xbadcaffe 0x08049b63 0x08049b00: ret %esp ... 0xdeadbeef 0x08049b63: pop %ebx 0x08049bbc 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) 0x08049b91: ret ... 0x08049bbc: pop %eax 0x08049bbd: ret %eip

  6. relevant register(s): %eax = 0xdeadbeef %ebx = 0x00000000 relevant stack: relevant memory: 0xbadcaffe: 0x00000000 0x08049b90 relevant code: 0xbadcaffe %esp 0x08049b63 0x08049b00: ret ... 0xdeadbeef 0x08049b63: pop %ebx %eip 0x08049bbc 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) 0x08049b91: ret ... 0x08049bbc: pop %eax 0x08049bbd: ret

  7. relevant register(s): %eax = 0xdeadbeef %ebx = 0xbadcaffe relevant stack: relevant memory: 0xbadcaffe: 0x00000000 0x08049b90 relevant code: %esp 0xbadcaffe 0x08049b63 0x08049b00: ret ... 0xdeadbeef 0x08049b63: pop %ebx 0x08049bbc %eip 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) 0x08049b91: ret ... 0x08049bbc: pop %eax 0x08049bbd: ret

  8. relevant register(s): %eax = 0xdeadbeef %ebx = 0xbadcaffe relevant stack: relevant memory: 0xbadcaffe: 0x00000000 %esp 0x08049b90 relevant code: 0xbadcaffe 0x08049b63 0x08049b00: ret ... 0xdeadbeef 0x08049b63: pop %ebx 0x08049bbc 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) %eip 0x08049b91: ret ... 0x08049bbc: pop %eax 0x08049bbd: ret

  9. relevant register(s): %eax = 0xdeadbeef %ebx = 0xbadcaffe relevant stack: relevant memory: 0xbadcaffe: 0xdeadbeef %esp 0x08049b90 relevant code: 0xbadcaffe 0x08049b63 0x08049b00: ret ... 0xdeadbeef 0x08049b63: pop %ebx 0x08049bbc 0x08049b64: ret ... 0x08049b90: mov %eax, %(ebx) 0x08049b91: ret %eip ... 0x08049bbc: pop %eax 0x08049bbd: ret

  10. What does this gadget do? mov %eax, %(ebx) ret v 2 pop %ebx ret v 1 pop %eax %esp ret mem[v 2 ] = v 1 mov v 2, %ebx mov v 1, %(%ebx)

  11. Can express arbitrary programs

  12. Can find gadgets automatically

  13. Return-Oriented Programming not even really about “returns”…

  14. Today • Advanced modern attack techniques ➤ ROP ➤ Heap-based attacks • Control flow integrity • Integer overflow attacks

  15. Handling heap-allocated memory can be just as error-prone as the stack • We may: ➤ Write/read memory we shouldn’t have access to ➤ Forget to free memory ➤ Free already freed objects ➤ Use pointers that point to freed object • What if the attacker can cause the program to use freed objects?

  16. Heap corruption • Can bypass security checks (data-only attacks) ➤ E.g., isAuthenticated, buffer_size, isAdmin, etc. • Can overwrite function pointers ➤ Direct transfer of control when function is called ➤ C++ virtual tables are especially good targets

  17. vtables • Each object contains pointer to vtable class Base { public : virtual void foo() { cout << “Hi \n ”; } • Array of function pointers }; class Derived : public Base { public : void foo() {cout << "Bye \n ";} }; ➤ one entry per function void bar(Base* obj) { obj->foo(); } int main(int argc, char* argv[]) { • Call looks up entry in vtable Base *b = new Base(); Derived *d = new Derived(); bar(b); bar(d); Q: What does bar() compile to? } A: *(obj->vtable[0])(obj)

  18. What does a use after free (UAF) attack look like? Victim: Free object: free(obj); Attacker: Overwrite the vtable of the object so entry (e.g., obj->vtable[0] ) points to attacker gadget Victim: Use dangling pointer: obj->foo()

  19. Today • Advanced modern attack techniques ➤ ROP ➤ Heap-based attacks • Control flow integrity • Integer overflow attacks

  20. Control Flow Integrity • In almost all the attacks we looked at, the attacker is overwriting jump targets that are in memory (return addresses on the stack and function pointers on the stack/heap) • Idea: don’t try to stop the memory writes. Instead: restrict control flow to legitimate paths ➤ I.e., ensure that jumps, calls, and returns can only go to allowed target destinations

  21. Restrict indirect transfers of control

  22. Restrict indirect transfers of control • Why do we not need to do anything about direct transfer of control flow (i.e., direct jumps/calls)?

  23. Restrict indirect transfers of control • Why do we not need to do anything about direct transfer of control flow (i.e., direct jumps/calls)? ➤ Address is hard-coded in instruction. Not under attacker control

  24. Restrict indirect transfers of control

  25. Restrict indirect transfers of control • What are the ways to transfer control indirectly?

  26. Restrict indirect transfers of control • What are the ways to transfer control indirectly? • Forward path: jumping to (or calling function at) an address in register or memory ➤ E.g., qsort, interrupt handlers, virtual calls, etc. • Reverse path: returning from function (uses address on stack)

  27. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 bool lt(int x, int y) { return x < y; } 
 bool gt(int x, int y) { return x > y; }

  28. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() bool lt(int x, int y) { return x < y; call sort } 
 bool gt(int x, int y) { call sort return x > y; ret }

  29. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() bool lt(int x, int y) { return x < y; call sort call arg$3 } 
 bool gt(int x, int y) { call sort ret return x > y; ret }

  30. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret }

  31. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  32. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  33. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  34. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  35. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  36. 
 
 What’s a legitimate target? Look at the program control-flow graph (CFG)! void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  37. How do we restrict jumps to CFG? • Assign labels to all indirect jumps and their targets • Before taking an indirect jump, validate that target label matches jump site ➤ Like stack canaries, but for for control flow target • Need hardware support ➤ Otherwise trade off precision for performance

  38. Fine grained CFI (Abadi et al.) • Statically compute CFG • Dynamically ensure program never deviates ➤ Assign label to each target of indirect transfer ➤ Instrument indirect transfers to compare label of destination with the expected label to ensure it's valid

  39. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  40. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { label 1 label 1 return x < y; call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  41. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { label 1 label 1 return x < y; check 1 then call sort call arg$3 ret ret } 
 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  42. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { label 1 label 1 return x < y; check 1 then call sort call arg$3 ret ret } 
 label 2 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  43. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { label 1 label 1 check 2 then check 2 then return x < y; check 1 then call sort call arg$3 ret ret } 
 label 2 bool gt(int x, int y) { call sort ret return x > y; ret } direct call indirect call return

  44. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { label 1 label 1 check 2 then check 2 then return x < y; check 1 then call sort call arg$3 ret ret } 
 label 3 label 2 bool gt(int x, int y) { call sort ret label 3 return x > y; ret } direct call indirect call return

  45. 
 
 Fine grained CFI (Abadi et al.) void sort2(int a[],int b[], int len { 
 sort(a, len, lt); 
 sort(b, len, gt); 
 } 
 sort2() sort() lt() gt() bool lt(int x, int y) { label 1 label 1 check 2 then check 2 then return x < y; check 1 then call sort call arg$3 ret ret } 
 label 3 label 2 check 3 then bool gt(int x, int y) { call sort ret label 3 return x > y; ret } direct call indirect call return

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend