SlideShare a Scribd company logo
Return Oriented Programming (ROP) 
INTRODUCTION, EXPLOITATIONS AND COUNTER-MEASURES 
Pipat Methavanitpong 
Doctoral Student 
ppmet.th@vlsi.ce.titech.ac.jp 
Kunieda-Isshiki Laboratory 
Department of Communications and Computer Engineering 
Tokyo Institute of Technology 
11/4/2014
What is ROP? 
A program composes of functions 
◦ A lot of Calls and Returns 
Manipulating return addresses 
Go to other Address / Function / Program 
Can be done without injecting new code 
Example 
◦ [Linux] Opening sh shell 
◦ [Windows] Opening a calculator 
source: https://en.wikipedia.org/wiki/Return-oriented_programming
Anatomy of x86 Stack 
Caller • Function Arguments 
Callee 
• Function Return Address 
• Frame Pointer 
• Exception Handler Frame 
• Locally Declared Variables and Buffers 
• Callee Save Registers 
Higher Addresses 
Grow Downward 
Lower Addresses 
source: http://msdn.microsoft.com/en-us/library/aa290051.aspx#vctchcompilersecuritychecksindepthanchor3
Attack 
Approaches 
Stack 
Smashing 
Attack 
Return-to-libc 
Borrowed 
Code 
Chunks 
(Gadgets) 
1. Stack Smashing 
2. Return-to-libc 
3. Borrowed Code 
Chunks
Stack 
Smashing 
Overflow data in stack to its header 
or beyond 
Example 
• Size unchecked string input/copy 
• “HELLOBUG”x5 
• Overwrite return address of 
DrawLine() 
• When DrawLine() returns, it 
goes to address of value 
“HELLOBUG” 
H E L L O B U G 
H E L L O B U G 
H E L L O B U G 
H E L L O B U G 
H E L L O B U G 
source: https://en.wikipedia.org/wiki/Return-oriented_programming
Return-to-libc 
Common component of a program 
◦ Target once, apply all 
Provide handful functions (it’s a library) 
◦ system() can be used to execute shell commands 
Library’s code is marked as executable 
◦ Recent defenses force a restriction on execution on address spaces 
◦ Non executable (NX) bit feature is useless 
Steps 
◦ Exploit a buffer overflow vulnerability to gain flow control 
◦ Craft a targeted function’s arguments e.g. “/bin/bash” 
◦ Return to the targeted function entry e.g. “system()”
Borrowed 
Code Chunks 
(Gadgets) 
Registers tend to be reused 
Many chances to access memory 
Neutral instructions can serve evil 
No need to inject code 
Link these together 
YOU ARE HACKED! 
source: Black Hat 2008 – ROP Exploitation without Code Injection
Defenses 
Stack Canary 
Stack smashing protection 
A layer between a buffer and control data 
Verify it to confirm stack overflow or not 
StackGuard / ProPolice / GS Security Cookie 
NX bit 
Mark memory as executable or not 
Can be hardware implementation or software 
(emulated) 
GCC FORTIFY_SOURCE 
Detect and prevent buffer overflow during 
compile-time 
Sometimes, buffer size is known 
ASCII Zone 
Fill memory with NULL character to prevent 
string abuse 
Address Space Layout Randomization (ASLR) 
Random placing program and library code 
Position Independent Executable (PIE) 
Allow the executable part of a program to be 
reallocated everywhere 
Section Rearrangement 
Mitigate damage of overflow 
E.g. data and bss section to the lowest 
 Overflow does not overwrite other important parts of 
program’s sections
Further Resources 
Black Hat 2008 – ROP Exploitation without Code Injection 
SecurityTube – Buffer Overflow Primer Part 8 (Return To Libc Theory) 
Marcelo Carvalho – Buffer Overflow with a Practical Example 
RSA Conf 2010 – Practical Return-Oriented Programming 
Sebastian Krahmer – x86-64 buffer overflow exploits and the borrowed code chunks exploitation technique 
Florida State University – Offensive Computer Security Lectures 
Black Hat 2004 – A Comparison of Buffer Overflow Prevention Implementations and Weaknesses 
OpenRCE – Reversing Microsoft Visual C++ part I: Exception Handling 
Fedora – Security Features 
Red Hat Magazine – Limiting Buffer Overflow with ExecShield 
Microsoft Technet – On the Effectiveness of DEP and ASLR

More Related Content

PDF
Course lecture - An introduction to the Return Oriented Programming
PPTX
08 - Return Oriented Programming, the chosen one
PDF
Return oriented programming
PPT
PPTX
Dive into ROP - a quick introduction to Return Oriented Programming
PPTX
Operating Systems - A Primer
PPTX
An introduction to ROP
PPTX
How Functions Work
Course lecture - An introduction to the Return Oriented Programming
08 - Return Oriented Programming, the chosen one
Return oriented programming
Dive into ROP - a quick introduction to Return Oriented Programming
Operating Systems - A Primer
An introduction to ROP
How Functions Work

What's hot (20)

PPTX
Return Oriented Programming (ROP) Based Exploits - Part I
PPT
Virtual platform
PDF
One Shellcode to Rule Them All: Cross-Platform Exploitation
PDF
Return-Oriented Programming: Exploits Without Code Injection
PPTX
07 - Bypassing ASLR, or why X^W matters
PPTX
05 - Bypassing DEP, or why ASLR matters
PDF
ROP 輕鬆談
ODP
Design and implementation_of_shellcodes
PDF
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
PDF
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
PPT
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
PDF
不深不淺,帶你認識 LLVM (Found LLVM in your life)
PDF
Triton and symbolic execution on gdb
PPTX
Berkeley Packet Filters
PPTX
04 - I love my OS, he protects me (sometimes, in specific circumstances)
PPTX
Software to the slaughter
PDF
Exploitation Crash Course
PDF
[COSCUP 2021] A trip about how I contribute to LLVM
PPTX
Shellcode mastering
PPTX
Bypassing DEP using ROP
Return Oriented Programming (ROP) Based Exploits - Part I
Virtual platform
One Shellcode to Rule Them All: Cross-Platform Exploitation
Return-Oriented Programming: Exploits Without Code Injection
07 - Bypassing ASLR, or why X^W matters
05 - Bypassing DEP, or why ASLR matters
ROP 輕鬆談
Design and implementation_of_shellcodes
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
不深不淺,帶你認識 LLVM (Found LLVM in your life)
Triton and symbolic execution on gdb
Berkeley Packet Filters
04 - I love my OS, he protects me (sometimes, in specific circumstances)
Software to the slaughter
Exploitation Crash Course
[COSCUP 2021] A trip about how I contribute to LLVM
Shellcode mastering
Bypassing DEP using ROP
Ad

Similar to Return oriented programming (ROP) (20)

PPTX
Buffer overflow attacks
PDF
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
PDF
Software Reverse Engineering in a Security Context
PDF
2023-02-22_Tiberti_CyberX.pdf
PDF
Ceh v5 module 20 buffer overflow
PDF
Dive into exploit development
PPT
PDF
linux_internals_2.3 (1).pdf àaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ODP
Debugging With Id
PPTX
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
PDF
Software Security
PPTX
Reverse shell
PDF
Shell tutorial
PDF
DefCon 2012 - Rooting SOHO Routers
PPT
Track A-Compilation guiding and adjusting - IBM
PDF
Low Level Exploits
PDF
OpenSAF Symposium_Python Bindings_9.21.11
PPTX
Linux binary analysis and exploitation
PPT
bh-europe-01-clowes
PDF
Building and deploying LLM applications with Apache Airflow
Buffer overflow attacks
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Software Reverse Engineering in a Security Context
2023-02-22_Tiberti_CyberX.pdf
Ceh v5 module 20 buffer overflow
Dive into exploit development
linux_internals_2.3 (1).pdf àaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Debugging With Id
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Software Security
Reverse shell
Shell tutorial
DefCon 2012 - Rooting SOHO Routers
Track A-Compilation guiding and adjusting - IBM
Low Level Exploits
OpenSAF Symposium_Python Bindings_9.21.11
Linux binary analysis and exploitation
bh-europe-01-clowes
Building and deploying LLM applications with Apache Airflow
Ad

More from Pipat Methavanitpong (6)

PPTX
Influence of Native Language and Society on English Proficiency
PPTX
Intel processor trace - What are Recorded?
PPTX
Principles in software debugging
PDF
HPP Week 1 Summary
PPTX
Exploring the World Classroom: MOOC
PPTX
Seminar 12-11-19
Influence of Native Language and Society on English Proficiency
Intel processor trace - What are Recorded?
Principles in software debugging
HPP Week 1 Summary
Exploring the World Classroom: MOOC
Seminar 12-11-19

Recently uploaded (20)

PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
web development for engineering and engineering
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT
Project quality management in manufacturing
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PPTX
Sustainable Sites - Green Building Construction
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Geodesy 1.pptx...............................................
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Road Safety tips for School Kids by a k maurya.pptx
Structs to JSON How Go Powers REST APIs.pdf
Lecture Notes Electrical Wiring System Components
web development for engineering and engineering
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Project quality management in manufacturing
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
ETO & MEO Certificate of Competency Questions and Answers
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
“Next-Gen AI: Trends Reshaping Our World”
Sustainable Sites - Green Building Construction
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Geodesy 1.pptx...............................................
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Simulation of electric circuit laws using tinkercad.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Road Safety tips for School Kids by a k maurya.pptx

Return oriented programming (ROP)

  • 1. Return Oriented Programming (ROP) INTRODUCTION, EXPLOITATIONS AND COUNTER-MEASURES Pipat Methavanitpong Doctoral Student [email protected] Kunieda-Isshiki Laboratory Department of Communications and Computer Engineering Tokyo Institute of Technology 11/4/2014
  • 2. What is ROP? A program composes of functions ◦ A lot of Calls and Returns Manipulating return addresses Go to other Address / Function / Program Can be done without injecting new code Example ◦ [Linux] Opening sh shell ◦ [Windows] Opening a calculator source: https://en.wikipedia.org/wiki/Return-oriented_programming
  • 3. Anatomy of x86 Stack Caller • Function Arguments Callee • Function Return Address • Frame Pointer • Exception Handler Frame • Locally Declared Variables and Buffers • Callee Save Registers Higher Addresses Grow Downward Lower Addresses source: http://msdn.microsoft.com/en-us/library/aa290051.aspx#vctchcompilersecuritychecksindepthanchor3
  • 4. Attack Approaches Stack Smashing Attack Return-to-libc Borrowed Code Chunks (Gadgets) 1. Stack Smashing 2. Return-to-libc 3. Borrowed Code Chunks
  • 5. Stack Smashing Overflow data in stack to its header or beyond Example • Size unchecked string input/copy • “HELLOBUG”x5 • Overwrite return address of DrawLine() • When DrawLine() returns, it goes to address of value “HELLOBUG” H E L L O B U G H E L L O B U G H E L L O B U G H E L L O B U G H E L L O B U G source: https://en.wikipedia.org/wiki/Return-oriented_programming
  • 6. Return-to-libc Common component of a program ◦ Target once, apply all Provide handful functions (it’s a library) ◦ system() can be used to execute shell commands Library’s code is marked as executable ◦ Recent defenses force a restriction on execution on address spaces ◦ Non executable (NX) bit feature is useless Steps ◦ Exploit a buffer overflow vulnerability to gain flow control ◦ Craft a targeted function’s arguments e.g. “/bin/bash” ◦ Return to the targeted function entry e.g. “system()”
  • 7. Borrowed Code Chunks (Gadgets) Registers tend to be reused Many chances to access memory Neutral instructions can serve evil No need to inject code Link these together YOU ARE HACKED! source: Black Hat 2008 – ROP Exploitation without Code Injection
  • 8. Defenses Stack Canary Stack smashing protection A layer between a buffer and control data Verify it to confirm stack overflow or not StackGuard / ProPolice / GS Security Cookie NX bit Mark memory as executable or not Can be hardware implementation or software (emulated) GCC FORTIFY_SOURCE Detect and prevent buffer overflow during compile-time Sometimes, buffer size is known ASCII Zone Fill memory with NULL character to prevent string abuse Address Space Layout Randomization (ASLR) Random placing program and library code Position Independent Executable (PIE) Allow the executable part of a program to be reallocated everywhere Section Rearrangement Mitigate damage of overflow E.g. data and bss section to the lowest  Overflow does not overwrite other important parts of program’s sections
  • 9. Further Resources Black Hat 2008 – ROP Exploitation without Code Injection SecurityTube – Buffer Overflow Primer Part 8 (Return To Libc Theory) Marcelo Carvalho – Buffer Overflow with a Practical Example RSA Conf 2010 – Practical Return-Oriented Programming Sebastian Krahmer – x86-64 buffer overflow exploits and the borrowed code chunks exploitation technique Florida State University – Offensive Computer Security Lectures Black Hat 2004 – A Comparison of Buffer Overflow Prevention Implementations and Weaknesses OpenRCE – Reversing Microsoft Visual C++ part I: Exception Handling Fedora – Security Features Red Hat Magazine – Limiting Buffer Overflow with ExecShield Microsoft Technet – On the Effectiveness of DEP and ASLR