SlideShare a Scribd company logo
1 of 9
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

What's hot

Virtual platform
Virtual platformVirtual platform
Virtual platform
sean chen
 
Return-Oriented Programming: Exploits Without Code Injection
Return-Oriented Programming: Exploits Without Code InjectionReturn-Oriented Programming: Exploits Without Code Injection
Return-Oriented Programming: Exploits Without Code Injection
guest9f4856
 
Design and implementation_of_shellcodes
Design and implementation_of_shellcodesDesign and implementation_of_shellcodes
Design and implementation_of_shellcodes
Amr Ali
 
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
DVClub
 

What's hot (20)

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

Similar to Return oriented programming (ROP)

2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf
cifoxo
 
Debugging With Id
Debugging With IdDebugging With Id
Debugging With Id
guest215c4e
 
Shell tutorial
Shell tutorialShell tutorial
Shell tutorial
Vu Duy Tu
 
DefCon 2012 - Rooting SOHO Routers
DefCon 2012 - Rooting SOHO RoutersDefCon 2012 - Rooting SOHO Routers
DefCon 2012 - Rooting SOHO Routers
Michael Smith
 
Track A-Compilation guiding and adjusting - IBM
Track A-Compilation guiding and adjusting - IBMTrack A-Compilation guiding and adjusting - IBM
Track A-Compilation guiding and adjusting - IBM
chiportal
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
hughpearse
 
bh-europe-01-clowes
bh-europe-01-clowesbh-europe-01-clowes
bh-europe-01-clowes
guest3e5046
 

Similar to Return oriented programming (ROP) (20)

Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
 
Software Reverse Engineering in a Security Context
Software Reverse Engineering in a Security ContextSoftware Reverse Engineering in a Security Context
Software Reverse Engineering in a Security Context
 
2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
LLVM
LLVMLLVM
LLVM
 
Debugging With Id
Debugging With IdDebugging With Id
Debugging With Id
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
 
Software Security
Software SecuritySoftware Security
Software Security
 
Reverse shell
Reverse shellReverse shell
Reverse shell
 
Shell tutorial
Shell tutorialShell tutorial
Shell tutorial
 
DefCon 2012 - Rooting SOHO Routers
DefCon 2012 - Rooting SOHO RoutersDefCon 2012 - Rooting SOHO Routers
DefCon 2012 - Rooting SOHO Routers
 
Track A-Compilation guiding and adjusting - IBM
Track A-Compilation guiding and adjusting - IBMTrack A-Compilation guiding and adjusting - IBM
Track A-Compilation guiding and adjusting - IBM
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11
 
Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitation
 
bh-europe-01-clowes
bh-europe-01-clowesbh-europe-01-clowes
bh-europe-01-clowes
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache Airflow
 
Stack-Based Buffer Overflows
Stack-Based Buffer OverflowsStack-Based Buffer Overflows
Stack-Based Buffer Overflows
 

More from Pipat Methavanitpong

More from Pipat Methavanitpong (6)

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

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 

Recently uploaded (20)

kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

Return oriented programming (ROP)

  • 1. 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
  • 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