SlideShare a Scribd company logo
CNIT 127: Exploit Development




Ch 4: Introduction to Format String
Bugs
Updated 2-28-21
Understanding Format Strings
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...
Format String Controls Output
Most Important for Us
• %x
	
	
	
Hexadecimal


• %8x
	
	
Hexadecimal padded to 8 chars


• %10x
	
	
Hexadecimal padded to 10 chars


• %100x
	
Hexadecimal padded to 100 chars
Format String Vulnerabilities
Buffer Overflow
• This code is obviously stupid


char name[10];


strcpy(name, "Rumplestiltskin");


• C just does it, without complaining
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
Format String Controlled by User
Explanation
• %x.%x.%x.%x
	
-- read 4 words from stack


• %n.%n
	
	
	
-- write 2 numbers to RAM


	
	
	
	
	
addresses from the stack
%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
printf Family
• Format string bugs affect a whole family
of functions
Countermeasures
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
Exploitation Technique
Steps for a Format String Exploit
• Control a write operation


• 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 address to target RAM
location
Control a Parameter
• The format string is on the stack


• Insert four letters before the %x fields


• Controls the fourth parameter


– Note: sometimes it's much further down the
list, such as parameter 300
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 program exits


• C Library Hooks
Target RAM Options
• "atexit" structure (link Ch 4n)


• Any function pointer


• In Windows, the default unhandled
exception handler is easy to find and
exploit
Disassemble in gdb
• gdb -q ED204


• disassemble main


• First it calls printf


• Later it calls exit
Dynamic Relocation


(also called Global Offset Table (GOT))
• PLT and GOT are used to address shared
libraries


• See links Ch 4o, 4p
Writing to the GOT
• We control the eip!
Python Code to Write 1 Byte
Python Code to Write Four Bytes
Write Chosen Values in 4 Bytes
Write Chosen Values in 4 Bytes
Inserting Dummy Shellcode
xcc is BRK
View the Stack in gdb
• Choose an address in the NOP sled
Dummy Exploit Runs to xcc
Testing for Bad Characters
• Avoid these
Testing for Bad Characters
• All the other characters got through
Generate Shellcode
Keep Total Length of Injection Constant
• Add 'A' characters after shellcode


• To keep the stack frame size constant
Final Check
• Address
in NOP
sled


• Shellcode
intact
Shell
CNIT 127 Ch 4: Introduction to format string bugs

More Related Content

PDF
Ch 6: The Wild World of Windows
PDF
CNIT 127 Ch 3: Shellcode
PDF
Ch 5: Introduction to heap overflows
PDF
CNIT 127 Ch 8: Windows overflows (Part 1)
PDF
CNIT 127 Ch 1: Before you Begin
PDF
CNIT 127 14: Protection Mechanisms
PDF
CNIT 126 6: Recognizing C Code Constructs in Assembly
PDF
Linux Binary Exploitation - Return-oritend Programing
Ch 6: The Wild World of Windows
CNIT 127 Ch 3: Shellcode
Ch 5: Introduction to heap overflows
CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 1: Before you Begin
CNIT 127 14: Protection Mechanisms
CNIT 126 6: Recognizing C Code Constructs in Assembly
Linux Binary Exploitation - Return-oritend Programing

What's hot (20)

PDF
Advanced heap exploitaion
PDF
Execution
PPTX
Practical Malware Analysis: Ch 5: IDA Pro
PPSX
Support for Object-Oriented Programming (OOP) in C++
PDF
MacOS memory allocator (libmalloc) Exploitation
PPTX
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
PDF
Finding Your Way in Container Security
PPTX
JS Event Loop
PPTX
java Servlet technology
PPT
Exception handling
PPTX
Exception handling in java
PPT
Labels and buttons
PDF
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
PPTX
Typescript ppt
PDF
Play with FILE Structure - Yet Another Binary Exploit Technique
PPTX
secure socket layer
PDF
Pwning in c++ (basic)
PDF
PPTX
Bash Shell Scripting
PDF
Binary exploitation - AIS3
Advanced heap exploitaion
Execution
Practical Malware Analysis: Ch 5: IDA Pro
Support for Object-Oriented Programming (OOP) in C++
MacOS memory allocator (libmalloc) Exploitation
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Finding Your Way in Container Security
JS Event Loop
java Servlet technology
Exception handling
Exception handling in java
Labels and buttons
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Typescript ppt
Play with FILE Structure - Yet Another Binary Exploit Technique
secure socket layer
Pwning in c++ (basic)
Bash Shell Scripting
Binary exploitation - AIS3
Ad

Similar to CNIT 127 Ch 4: Introduction to format string bugs (20)

PDF
CNIT 127: Ch 4: Introduction to format string bugs
PDF
CNIT 127 Ch 4: Introduction to format string bugs
PDF
CNIT 127 Ch 4: Introduction to format string bugs
PDF
CNIT 127: 4: Format string bugs
PDF
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
PDF
Exploitation Crash Course
PPTX
Software to the slaughter
PPTX
Format String Attack
PDF
Format string
PDF
2.Format Strings
PPTX
C format string vulnerability
PDF
AllBits presentation - Lower Level SW Security
PPTX
[MOSUT] Format String Attacks
PDF
Fuzzing - Part 1
ODP
Format string vunerability
PPT
E-Commerce Security - Application attacks - Server Attacks
PDF
StackOverflow
PDF
Low Level Exploits
PDF
Buffer overflow tutorial
PDF
Software Security
CNIT 127: Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127: 4: Format string bugs
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
Exploitation Crash Course
Software to the slaughter
Format String Attack
Format string
2.Format Strings
C format string vulnerability
AllBits presentation - Lower Level SW Security
[MOSUT] Format String Attacks
Fuzzing - Part 1
Format string vunerability
E-Commerce Security - Application attacks - Server Attacks
StackOverflow
Low Level Exploits
Buffer overflow tutorial
Software Security
Ad

More from Sam Bowne (20)

PDF
Introduction to the Class & CISSP Certification
PDF
Cyberwar
PDF
3: DNS vulnerabilities
PDF
8. Software Development Security
PDF
4 Mapping the Application
PDF
3. Attacking iOS Applications (Part 2)
PDF
12 Elliptic Curves
PDF
11. Diffie-Hellman
PDF
2a Analyzing iOS Apps Part 1
PDF
9 Writing Secure Android Applications
PDF
12 Investigating Windows Systems (Part 2 of 3)
PDF
10 RSA
PDF
12 Investigating Windows Systems (Part 1 of 3
PDF
9. Hard Problems
PDF
8 Android Implementation Issues (Part 1)
PDF
11 Analysis Methodology
PDF
8. Authenticated Encryption
PDF
7. Attacking Android Applications (Part 2)
PDF
7. Attacking Android Applications (Part 1)
PDF
5. Stream Ciphers
Introduction to the Class & CISSP Certification
Cyberwar
3: DNS vulnerabilities
8. Software Development Security
4 Mapping the Application
3. Attacking iOS Applications (Part 2)
12 Elliptic Curves
11. Diffie-Hellman
2a Analyzing iOS Apps Part 1
9 Writing Secure Android Applications
12 Investigating Windows Systems (Part 2 of 3)
10 RSA
12 Investigating Windows Systems (Part 1 of 3
9. Hard Problems
8 Android Implementation Issues (Part 1)
11 Analysis Methodology
8. Authenticated Encryption
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 1)
5. Stream Ciphers

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PPTX
Institutional Correction lecture only . . .
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Insiders guide to clinical Medicine.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Cell Types and Its function , kingdom of life
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharma ospi slides which help in ospi learning
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
RMMM.pdf make it easy to upload and study
Institutional Correction lecture only . . .
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Complications of Minimal Access Surgery at WLH
Insiders guide to clinical Medicine.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Basic Mud Logging Guide for educational purpose
Cell Types and Its function , kingdom of life
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharma ospi slides which help in ospi learning
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf

CNIT 127 Ch 4: Introduction to format string bugs