1 / 38

Lecture 9: Buffer Ovefflows and ROP

Lecture 9: Buffer Ovefflows and ROP. EEN 312: Processors: Hardware, Software, and Interfacing. Department of Electrical and Computer Engineering Spring 2014, Dr. Rozier (UM). BUFFER OVERFLOWS. General Overview of Buffer Overflow Mechanism Real Life Examples - SQL Slammer - Blaster

jetta
Download Presentation

Lecture 9: Buffer Ovefflows and ROP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9: Buffer Ovefflows and ROP EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr. Rozier (UM)

  2. BUFFER OVERFLOWS

  3. General Overview of Buffer Overflow Mechanism Real Life Examples- SQL Slammer- Blaster Prevention and Detection Mechanisms Buffer Overflows

  4. Can be done on the stack or on the heap. Can be used to overwrite the return address (transferring control when returning) or function pointers (transferring control when calling the function) General Overview “Smashing the Stack” (overflowing buffers on the stack to overwrite the return address) is the easiest vulnerability to exploit and the most common type in practice

  5. A large percentage of CERT advisories are about buffer overflow vulnerabilities. They dominate the area of remote penetration attacks, since they give the attacker exactly what they want - the ability to inject and execute attack code. Are Buffer Overflows Really A Problem?

  6. Are Buffer Overflows Really A Problem?

  7. Stack Lower Memory Addresses Heap Data Executable Code Anatomy of the Stack • Assumptions • Stack grows down (Intel, Motorola, SPARC, MIPS) • Stack pointer points to the last address on the stack

  8. Example Program Let us consider how the stack of this program would look: void function(int a, int b, int c){ char buffer1[5]; char buffer2[10]; } int main(){ function(1,2,3); }

  9. Function Parameters Return Address Saved Frame Pointer Local Variables Stack Frame pushl $3 pushl $2 pushl $1 call function function prolog pushl %ebp movl %esp, %ebp subl $20, %esp Higher Memory Addresses Allocates space for local variables

  10. 12 8 4 4 4 4 4 Top of memory Bottom of stack Bottom of memory Top of stack buffer2 buffer1 sfp ret a b c Linear View Of Frame/Stack

  11. Example Program 2 Buffer overflows take advantage of the fact that bounds checking is not performed void function(char *str){ char buffer[16]; strcpy(buffer, str); } int main(){ char large_string[256]; int i; for (i = 0; i < 255; i++){ large_string[i] = ‘A’; } function(large_string); }

  12. A A A A A A A A A A A A A A A A A A A A A A A A A A A A Example Program 2 When this program is run, it results in a segmentation violation 16 4 4 4 Top of memory Bottom of stack Bottom of memory Top of stack A A A A A A A A A A A A A A A A A A A buffer sfp ret *str The return address is overwritten with ‘AAAA’ (0x41414141) Function exits and goes to execute instruction at 0x41414141…..

  13. Example Program 3 Can we take advantage of this to execute code, instead of crashing? void function(int a, int b, int c){ char buffer1[5]; char buffer2[10]; int *r; r = buffer1 + 12; (*r) += 8; } int main(){ int x = 0; function(1,2,3); x = 1; printf(“%d\n”, x); }

  14. 4 12 8 4 4 4 4 4 Top of memory Bottom of stack Bottom of memory Top of stack r buffer2 buffer1 sfp ret a b c Example Program 3 buffer1 + 12 +8 This causes it to skip the assignment of 1 to x, and prints out 0 for the value of x Note: modern implementations have extra info in the stack between the local variables and sfp. This would slightly impact the value added to the address of buffer1.

  15. First example of a high speed worm (previously only existed in theory) Infected a total of 75,000 hosts in about 30 minutes Infected 90% of vulnerable hosts in 10 min Exploited a vulnerability in MS SQL Server Resolution Service, for which a patch had been available for 6 months Slammer Worm Info

  16. Code randomly generated an IP address and sent out a copy of itself Used UDP - limited by bandwidth, not network latency (TCP handshake). Packet was just 376 bytes long… Spread doubled every 8.5 seconds Max scanning rate (55 million scans/second) reached in 3 minutes Slammer Worm Info

  17. Slammer Worm

  18. Slammer Worm

  19. Could have been much worse Slammer carried a benign payload - devastated the network with a DOS attack, but left hosts alone Bug in random number generator caused Slammer to spread more slowly (last two bits of the first address byte never changed) Slammer Worm

  20. ARM Defenses • ARM attempts to defend against these attacks by protecting the stack! • Stack is not executable memory. • Exception if we try to jump to it. • But… we can still overwrite the stack!

  21. Why doesn’t the Processor Protect the Stack from being Overwritten?

  22. Attacking the LR • We can overwrite the LR to jump to places we aren’t allowed to jump to! • Execute any code already extant on the system.

  23. Breaching the Gates • How do we circumvent non-executable stacks? • Common method for x86-64: Ret2Libc • Libc library is mapped into the memory space of most programs. • Once we corrupt the stack, we can point the LR at a function in Libc • Good target: system() which can be passed the argument “/bin/sh” to get a shell

  24. Breaching the Gates • Why is this method not possible on ARM?

  25. Breaching the Gates • Why is this method not possible on ARM? • IA32/x86-64 arguments are where? • ARM arguments are where?

  26. Breaching the Gates • We need to get the registers filled appropriately some other way…

  27. Finding a Double Agent

  28. Breaching the Gates

  29. Breaching the Gates

  30. Breaching the Gates

  31. Breaching the Gates

  32. Breaching the Gates

  33. The Attack

  34. Finding Other Vectors

  35. Gadgets

  36. Gadgets

  37. Gadgets

  38. For next time • Read Chapter 4, Sections 4.5 – 4.9 • Project 3 out Friday

More Related