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

What's hot (20)

PDF
CNIT 127 14: Protection Mechanisms
Sam Bowne
 
PDF
Play with FILE Structure - Yet Another Binary Exploit Technique
Angel Boy
 
PPTX
Sisteme de Operare: Memorie virtuala
Alexandru Radovici
 
PDF
Practical Malware Analysis Ch13
Sam Bowne
 
PPTX
Linux Kernel Booting Process (1) - For NLKB
shimosawa
 
PDF
Linux Internals - Part III
Emertxe Information Technologies Pvt Ltd
 
PDF
CNIT 127: Ch 18: Source Code Auditing
Sam Bowne
 
PDF
Linux Kernel - Virtual File System
Adrian Huang
 
PPTX
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
Adrian Huang
 
PDF
MacOS memory allocator (libmalloc) Exploitation
Angel Boy
 
PDF
Ch8 (1) morris mano
KIRTI89
 
PDF
Linux scheduler
Liran Ben Haim
 
PDF
Linux binary Exploitation - Basic knowledge
Angel Boy
 
PDF
ACPI Debugging from Linux Kernel
SUSE Labs Taipei
 
PDF
Advanced heap exploitaion
Angel Boy
 
PPTX
Operating system 25 classical problems of synchronization
Vaibhav Khanna
 
PPTX
Semaphore
Arafat Hossan
 
PDF
I2c drivers
pradeep_tewani
 
PDF
Linux SMEP bypass techniques
Vitaly Nikolenko
 
PDF
CNIT 126: Ch 6: Recognizing C Constructs in Assembly
Sam Bowne
 
CNIT 127 14: Protection Mechanisms
Sam Bowne
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Angel Boy
 
Sisteme de Operare: Memorie virtuala
Alexandru Radovici
 
Practical Malware Analysis Ch13
Sam Bowne
 
Linux Kernel Booting Process (1) - For NLKB
shimosawa
 
Linux Internals - Part III
Emertxe Information Technologies Pvt Ltd
 
CNIT 127: Ch 18: Source Code Auditing
Sam Bowne
 
Linux Kernel - Virtual File System
Adrian Huang
 
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
Adrian Huang
 
MacOS memory allocator (libmalloc) Exploitation
Angel Boy
 
Ch8 (1) morris mano
KIRTI89
 
Linux scheduler
Liran Ben Haim
 
Linux binary Exploitation - Basic knowledge
Angel Boy
 
ACPI Debugging from Linux Kernel
SUSE Labs Taipei
 
Advanced heap exploitaion
Angel Boy
 
Operating system 25 classical problems of synchronization
Vaibhav Khanna
 
Semaphore
Arafat Hossan
 
I2c drivers
pradeep_tewani
 
Linux SMEP bypass techniques
Vitaly Nikolenko
 
CNIT 126: Ch 6: Recognizing C Constructs in Assembly
Sam Bowne
 

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

PDF
CNIT 127: Ch 4: Introduction to format string bugs
Sam Bowne
 
PDF
CNIT 127 Ch 4: Introduction to format string bugs
Sam Bowne
 
PDF
CNIT 127 Ch 4: Introduction to format string bugs
Sam Bowne
 
PDF
CNIT 127: 4: Format string bugs
Sam Bowne
 
PDF
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
Sam Bowne
 
PDF
Exploitation Crash Course
UTD Computer Security Group
 
PPTX
Software to the slaughter
Quinn Wilton
 
PPTX
Format String Attack
Mayur Mallya
 
PDF
Format string
Vu Review
 
PDF
2.Format Strings
phanleson
 
PPTX
C format string vulnerability
sluge
 
PDF
AllBits presentation - Lower Level SW Security
AllBits BVBA (freelancer)
 
PPTX
[MOSUT] Format String Attacks
Aj MaChInE
 
PDF
Fuzzing - Part 1
UTD Computer Security Group
 
ODP
Format string vunerability
nuc13us
 
PPT
E-Commerce Security - Application attacks - Server Attacks
phanleson
 
PDF
StackOverflow
Susam Pal
 
PDF
Low Level Exploits
hughpearse
 
PDF
Buffer overflow tutorial
hughpearse
 
PDF
Software Security
Roman Oliynykov
 
CNIT 127: Ch 4: Introduction to format string bugs
Sam Bowne
 
CNIT 127 Ch 4: Introduction to format string bugs
Sam Bowne
 
CNIT 127 Ch 4: Introduction to format string bugs
Sam Bowne
 
CNIT 127: 4: Format string bugs
Sam Bowne
 
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
Sam Bowne
 
Exploitation Crash Course
UTD Computer Security Group
 
Software to the slaughter
Quinn Wilton
 
Format String Attack
Mayur Mallya
 
Format string
Vu Review
 
2.Format Strings
phanleson
 
C format string vulnerability
sluge
 
AllBits presentation - Lower Level SW Security
AllBits BVBA (freelancer)
 
[MOSUT] Format String Attacks
Aj MaChInE
 
Fuzzing - Part 1
UTD Computer Security Group
 
Format string vunerability
nuc13us
 
E-Commerce Security - Application attacks - Server Attacks
phanleson
 
StackOverflow
Susam Pal
 
Low Level Exploits
hughpearse
 
Buffer overflow tutorial
hughpearse
 
Software Security
Roman Oliynykov
 
Ad

More from Sam Bowne (20)

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

Recently uploaded (20)

PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
PPTX
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Dimensions of Societal Planning in Commonism
StefanMz
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 

CNIT 127 Ch 4: Introduction to format string bugs