CNIT 127: Exploit Development

CNIT 127: Exploit Development
Slide Note
Embed
Share

Format string vulnerabilities, data interpretation in RAM, buffer overflow risks, and controlled attacks through format strings. Explore the impact of format string bugs on memory, information disclosure, and possible remote code execution. Learn about the printf family functions and how format strings can be exploited to manipulate memory locations and trigger denial-of-service attacks.

  • Format String Bugs
  • Vulnerabilities
  • Memory Exploitation
  • Information Disclosure
  • Remote Code Execution

Uploaded on Feb 18, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs

  2. Understanding Format Strings

  3. Data Interpretation RAM contains bytes The same byte can be interpreted as An integer A character Part of an instruction Part of an address Part of a string Many, many more...

  4. Format String Controls Output

  5. Format String Demo

  6. Most Important for Us %x %8x %10x %100x Hexadecimal Hexadecimal padded to 8 chars Hexadecimal padded to 10 chars Hexadecimal padded to 100 chars

  7. Format String Vulnerabilities

  8. Buffer Overflow This code is obviously stupid char name[10]; strcpy(name, "Rumplestiltskin"); C just does it, without complaining

  9. Format String Without Arguments printf("%x.%x.%x.%x"); There are no arguments to print! Should give an error message Instead, C just pulls the next 4 values from the stack and prints them out Can read memory on the stack Information disclosure vulnerability

  10. Format String Controlled by Attacker

  11. %n Format String %n writes the number of characters printed so far To the memory location pointed to by the parameter Can write to arbitrary RAM locations Easy DoS Possible remote code execution

  12. printf Family Format string bugs affect a whole family of functions

  13. Countermeasures

  14. Defenses Against Format String Vulnerabilities Stack defenses don't stop format string exploits Canary value ASLR and NX Can make exploitation more difficult Static code analysis tools Generally find format string bugs gcc Warnings, but no format string defenses

  15. Exploitation Technique

  16. Steps Control a parameter Find a target RAM location That will control execution Write 4 bytes to target RAM location Insert shellcode Find the shellcode in RAM Write shellcode to target RAM location

  17. Control a Parameter Insert four letters before the %x fields Controls the fourth parameter Note: sometimes it's much further down the list, such as parameter 300

  18. Target RAM Options Saved return address Like the Buffer Overflows we did previously Global Offset Table Used to find shared library functions Destructors table (DTORS) Called when a porgram exits C Library Hooks

  19. Target RAM Options "atexit" structure (link Ch 4n) Any function pointer In Windows, the default unhandled exception handler is easy to find and exploit

  20. Disassemble in gdb

  21. Targeting the GOT

  22. Writing to Target RAM We now control the destination address, but not the value written there

  23. Python Code to Write 4 Bytes

  24. Changing One Byte Add 16 to %16x Previously Now Each byte increased by 13

  25. Python Code to Write a Chosen Word

  26. Inserting Dummy Shellcode \xcc is BRK

  27. View the Stack in gdb Choose an address in the NOP sled

  28. Dummy Exploit Runs to \xcc

  29. Testing for Bad Characters \x09 is bad

  30. Testing for Bad Characters \x10 is bad

  31. Testing for Bad Characters Started at 11 = 0x0b \x20 is bad

  32. Testing for Bad Characters Started at 33 = 0x21 No more bad characters

  33. Generate Shellcode msfvenom -p linux/x86/shell_bind_tcp -b '\x00\x09\x0a\x20' PrependFork=true -f python

  34. Keep Total Length of Injection Constant May not be necessary, but it's a good habit

  35. Final Check Address in NOP sled Shellcode intact

  36. Shell (in gdb) Wait for the port to close Test it outside gdb

Related


More Related Content