buffer
play

Buffer Overflow overflows Defenses and other memory safety - PowerPoint PPT Presentation

This time We will continue By looking at Buffer Overflow overflows Defenses and other memory safety vulnerabilities Everything youve always wanted to know about gdb but were too afraid to ask Overflow defenses Other memory


  1. Simple example (ret) equivalent to 0x17f: pop %edx ret mov %edx, 5 %eip %esp next … 5 0x17f %edx Text 5 gadget 0x00 0xffffffff

  2. Code sequence %eip 0x17f: mov %eax, [%esp] mov %ebx, [%esp-8] %eax mov [%ebx], %eax %ebx %esp … … … 0x404 … 5 Text 0x00 0xffffffff 0x404

  3. Code sequence 0x17f: mov %eax, [%esp] %eip mov %ebx, [%esp-8] 5 %eax mov [%ebx], %eax %ebx %esp … … … 0x404 … 5 Text 0x00 0xffffffff 0x404

  4. Code sequence 0x17f: mov %eax, [%esp] mov %ebx, [%esp-8] 5 %eax %eip mov [%ebx], %eax 0x404 %ebx %esp … … … 0x404 … 5 Text 0x00 0xffffffff 0x404

  5. Code sequence 0x17f: mov %eax, [%esp] mov %ebx, [%esp-8] 5 %eax mov [%ebx], %eax %eip 0x404 %ebx %esp … … … 0x404 … 5 5 Text 0x00 0xffffffff 0x404

  6. Equivalent ROP sequence %eip 0x17f: pop %eax ret %eax … 0x20d: pop %ebx %ebx ret … 0x21a: mov [%ebx], %eax %esp … … 0x21a 0x404 0x20d 5 Text 0x00 0xffffffff 0x404

  7. Equivalent ROP sequence 0x17f: pop %eax %eip ret 5 %eax … 0x20d: pop %ebx %ebx ret … 0x21a: mov [%ebx], %eax %esp … … 0x21a 0x404 0x20d 5 Text 0x00 0xffffffff 0x404

  8. Equivalent ROP sequence 0x17f: pop %eax ret 5 %eax … %eip 0x20d: pop %ebx %ebx ret … 0x21a: mov [%ebx], %eax %esp … … 0x21a 0x404 0x20d 5 Text 0x00 0xffffffff 0x404

  9. Equivalent ROP sequence 0x17f: pop %eax ret 5 %eax … 0x20d: pop %ebx %eip 0x404 %ebx ret … 0x21a: mov [%ebx], %eax %esp … … 0x21a 0x404 0x20d 5 Text 0x00 0xffffffff 0x404

  10. Equivalent ROP sequence 0x17f: pop %eax ret 5 %eax … 0x20d: pop %ebx 0x404 %ebx ret … %eip 0x21a: mov [%ebx], %eax … … 0x21a 0x404 0x20d 5 Text 0x00 0xffffffff 0x404

  11. Equivalent ROP sequence 0x17f: pop %eax ret 5 %eax … 0x20d: pop %ebx 0x404 %ebx ret … 0x21a: mov [%ebx], %eax %eip … … 0x21a 0x404 0x20d 5 5 Text 0x00 0xffffffff 0x404

  12. Image by Dino Dai Zovi

  13. Whence the gadgets?

  14. Whence the gadgets? • How can we find gadgets to construct an exploit?

  15. Whence the gadgets? • How can we find gadgets to construct an exploit? • Automate a search of the target binary for gadgets (look for ret instructions, work backwards) Cf. https://github.com/0vercl0k/rp -

  16. Whence the gadgets? • How can we find gadgets to construct an exploit? • Automate a search of the target binary for gadgets (look for ret instructions, work backwards) Cf. https://github.com/0vercl0k/rp - • Are there sufficient gadgets to do anything interesting?

  17. Whence the gadgets? • How can we find gadgets to construct an exploit? • Automate a search of the target binary for gadgets (look for ret instructions, work backwards) Cf. https://github.com/0vercl0k/rp - • Are there sufficient gadgets to do anything interesting? • Yes: Shacham found that for significant codebases (e.g., libc), gadgets are Turing complete Especially true on x86’s dense instruction set -

  18. Whence the gadgets? • How can we find gadgets to construct an exploit? • Automate a search of the target binary for gadgets (look for ret instructions, work backwards) Cf. https://github.com/0vercl0k/rp - • Are there sufficient gadgets to do anything interesting? • Yes: Shacham found that for significant codebases (e.g., libc), gadgets are Turing complete Especially true on x86’s dense instruction set - • Schwartz et al (USENIX Security ’11) have automated gadget shellcode creation, though not needing/requiring Turing completeness

  19. Blind ROP

  20. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult

  21. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult • Recent, published attacks are often for 32-bit versions of executables

  22. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult • Recent, published attacks are often for 32-bit versions of executables • Attack response : Blind ROP

  23. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult • Recent, published attacks are often for 32-bit versions of executables • Attack response : Blind ROP If server restarts on a crash, but does not re-randomize:

  24. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult • Recent, published attacks are often for 32-bit versions of executables • Attack response : Blind ROP If server restarts on a crash, but does not re-randomize: 1.Read the stack to leak canaries and a return address

  25. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult • Recent, published attacks are often for 32-bit versions of executables • Attack response : Blind ROP If server restarts on a crash, but does not re-randomize: 1.Read the stack to leak canaries and a return address 2.Find gadgets (at run-time) to effect call to write

  26. Blind ROP • Defense: Randomizing the location of the code (by compiling for position independence) on a 64- bit machine makes attacks very difficult • Recent, published attacks are often for 32-bit versions of executables • Attack response : Blind ROP If server restarts on a crash, but does not re-randomize: 1.Read the stack to leak canaries and a return address 2.Find gadgets (at run-time) to effect call to write 3.Dump binary to find gadgets for shellcode http://www.scs.stanford.edu/brop/

  27. Defeat! • The blind ROP team was able to completely automatically , only through remote interactions , develop a remote code exploit for nginx , a popular web server

  28. Defeat! • The blind ROP team was able to completely automatically , only through remote interactions , develop a remote code exploit for nginx , a popular web server • The exploit was carried out on a 64-bit executable with full stack canaries and randomization

  29. Defeat! • The blind ROP team was able to completely automatically , only through remote interactions , develop a remote code exploit for nginx , a popular web server • The exploit was carried out on a 64-bit executable with full stack canaries and randomization • Conclusion: give an inch, and they take a mile?

  30. Defeat! • The blind ROP team was able to completely automatically , only through remote interactions , develop a remote code exploit for nginx , a popular web server • The exploit was carried out on a 64-bit executable with full stack canaries and randomization • Conclusion: give an inch, and they take a mile? • Put another way: Memory safety is really useful!

  31. void safe() { char buf[80]; fgets(buf, 80, stdin); } void safer() { char buf[80]; fgets(buf, sizeof(buf), stdin); }

  32. void safe() { char buf[80]; fgets(buf, 80, stdin); } void safer() { char buf[80]; fgets(buf, sizeof(buf), stdin); } void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); }

  33. void safe() { char buf[80]; fgets(buf, 80, stdin); } void safer() { char buf[80]; fgets(buf, sizeof(buf), stdin); } void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); }

  34. Format string vulnerabilities

  35. printf format strings int i = 10; printf(“%d %p\n”, i, &i);

  36. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i

  37. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame

  38. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame caller’s 
 stack frame

  39. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame caller’s 
 stack frame

  40. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame caller’s 
 stack frame • printf takes variable number of arguments • printf pays no mind to where the stack frame “ends” • It presumes that you called it with (at least) as many arguments as specified in the format string

  41. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame caller’s 
 stack frame • printf takes variable number of arguments • printf pays no mind to where the stack frame “ends” • It presumes that you called it with (at least) as many arguments as specified in the format string

  42. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame caller’s 
 stack frame • printf takes variable number of arguments • printf pays no mind to where the stack frame “ends” • It presumes that you called it with (at least) as many arguments as specified in the format string

  43. printf format strings int i = 10; printf(“%d %p\n”, i, &i); 0x00000000 0xffffffff … %ebp %eip &fmt 10 &i printf ’s stack frame caller’s 
 stack frame • printf takes variable number of arguments • printf pays no mind to where the stack frame “ends” • It presumes that you called it with (at least) as many arguments as specified in the format string

  44. void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); }

  45. void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); } “%d %x"

  46. void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); } “%d %x" 0x00000000 0xffffffff … %ebp %eip &fmt caller’s 
 stack frame

  47. void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); } “%d %x" 0x00000000 0xffffffff … %ebp %eip &fmt caller’s 
 stack frame

  48. void vulnerable() { char buf[80]; if(fgets(buf, sizeof(buf), stdin)==NULL) return; printf(buf); } “%d %x" 0x00000000 0xffffffff … %ebp %eip &fmt caller’s 
 stack frame

  49. Format string vulnerabilities

  50. Format string vulnerabilities • printf(“100% dml”);

  51. Format string vulnerabilities • printf(“100% dml”); • Prints stack entry 4 byes above saved %eip

  52. Format string vulnerabilities • printf(“100% dml”); • Prints stack entry 4 byes above saved %eip • printf(“%s”);

  53. Format string vulnerabilities • printf(“100% dml”); • Prints stack entry 4 byes above saved %eip • printf(“%s”); • Prints bytes pointed to by that stack entry

  54. Format string vulnerabilities • printf(“100% dml”); • Prints stack entry 4 byes above saved %eip • printf(“%s”); • Prints bytes pointed to by that stack entry • printf(“%d %d %d %d …”);

  55. Format string vulnerabilities • printf(“100% dml”); • Prints stack entry 4 byes above saved %eip • printf(“%s”); • Prints bytes pointed to by that stack entry • printf(“%d %d %d %d …”); • Prints a series of stack entries as integers

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