SlideShare a Scribd company logo
1 of 15
Bypassing DEP using ROP
By Japneet Singh
Agenda
• Buffer overflow exploits
• Data execution prevention (DEP)
• Key idea behind bypassing DEP
• ROP
• Demo
Buffer overflow exploits
• 2 stages
• Memory corruption to inject shellcode
• Redirect process execution to injected shellcode
Vulnerable code
int main(int argc, char *argv[])
{
…
char buffer[2048]{};
HANDLE h = ::CreateFileA(argv[1], …);
…
DWORD bytesRead = 0;
if (!::ReadFile(h, buffer, 2048, &bytesRead, …)) {
…
ProcessInput(buffer, bytesRead);
…
}
void ProcessInput(char *str, int size)
{
char inputCopy[MAX_PATH]{};
memcpy(inputCopy, str, size);
printf(inputCopy);
}
Stack based buffer overflow
Stack frame of main()
Parameters to ProcessInput()
Return address to main()
Stack frame of ProcessInput()
On entering ProcessInput
Stack frame of main()
Overwritten area
Overwritten area
Address of Shellcode
Shellcode
Shellcode
NOPs
On memcpy
FFFF
F200
FFFF
F200
Stack frame of main()
Overwritten area
Overwritten area
Address of Shellcode
Shellcode
Shellcode
NOPs
F200
FFFF
On return from ProcessInput
Buffer overflow mitigations
• To make buffer overflows harder, make either of the two stages
harder to implement
• Windows Vista introduced few mechanisms to make buffer overflows
harder:
• ASLR – Pseudo-randomize the addresses where binaries load, and where
stacks/heaps get laid out.
• DEP – Mark memory areas as executable or non-executable. Any attempt to
execute code from an area marked as non-executable would lead to access
violation.
If DEP is enabled
Stack frame of main()
Parameters to ProcessInput()
Return address to main()
Stack frame of ProcessInput()
On entering ProcessInput
Stack frame of main()
Overwritten area
Overwritten area
Address of Shellcode
Shellcode
Shellcode
NOPs
On memcpy
FFFF
F200
FFFF
F200
Stack frame of main()
Overwritten area
Overwritten area
Address of Shellcode
Shellcode
Shellcode
NOPs
F200
FFFF
On return from ProcessInput
Key idea behind bypassing DEP
• Find and execute relevant instructions from existing code which is
already marked executable.
Return oriented programming (ROP)
• Figure out what instructions are needed to be executed
• Find out a small groups of required instructions in the existing code,
such that each small group is followed by return. Such small groups of
instructions ending with return are called Rop Gadgets.
• Setup the stack so that each each Rop Gadget’s return leads exactly to
execution of next Gadget.
How ROP works
...
…
Return from Function 1
Function 1 parameters
Function 1 address
Gadget 2 address
Gadget 1 address
…
Stack Code in loaded Exe/Dll(s)
****
****
****
push esp
ret
****
****
****
mov esp, ebp
pop ebp
ret
FFFF
F200
****
****
****
****
ret
One more concept
• Modifying a page protection using VirtualProtect
• Can make memory pages executable
VirtualProtect(address, size, PAGE_EXECUTE_READWRITE, &oldProtection)
Using ROP to bypass DEP
Stack frame of main()
Shellcode
Address of VirtualProtect
Address of shellcode
Parameters to VirtualProtect
Stack frame to be used by
VirtualProtect
F200
FFFF
On return from ProcessInput Code in loaded Exe/Dll(s)
****
****
****
****
ret
VirtualProtect in
Kernel32.dll
Demo
• Making stack executable via VirtualProtect call using simple ROP
Current scenario
• Many Advanced exploit detection engines introduced mitigations for
ROP
• Windows 10 introduced Control flow guard to mitigate ROP
• ROP is almost dead, and not seen in the wild!
• But, there are other ROP-less techniques 
References
• https://github.com/japsingh/DVWA

More Related Content

What's hot

Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09
Tumennast Erdenebold
 

What's hot (20)

Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
 
TRex Realistic Traffic Generator - Stateless support
TRex  Realistic Traffic Generator  - Stateless support TRex  Realistic Traffic Generator  - Stateless support
TRex Realistic Traffic Generator - Stateless support
 
GNS3
GNS3GNS3
GNS3
 
DPDK Acceleration with Arkville
DPDK Acceleration with ArkvilleDPDK Acceleration with Arkville
DPDK Acceleration with Arkville
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
 
Practica 8 Instalacion de redes CISCO
Practica 8 Instalacion de redes CISCOPractica 8 Instalacion de redes CISCO
Practica 8 Instalacion de redes CISCO
 
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String MethodsPython Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
 
1 intro to_dpdk_and_hw
1 intro to_dpdk_and_hw1 intro to_dpdk_and_hw
1 intro to_dpdk_and_hw
 
Breaking Down the Entry Barriers on Linux Kernel Networking Stack
Breaking Down the Entry Barriers on Linux Kernel Networking StackBreaking Down the Entry Barriers on Linux Kernel Networking Stack
Breaking Down the Entry Barriers on Linux Kernel Networking Stack
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made Simple
 
Network(pr)kurdish
Network(pr)kurdishNetwork(pr)kurdish
Network(pr)kurdish
 
Analyse d'un kernel (crash, core) dump
Analyse d'un kernel (crash, core) dumpAnalyse d'un kernel (crash, core) dump
Analyse d'un kernel (crash, core) dump
 
GTPing, How To
GTPing, How ToGTPing, How To
GTPing, How To
 
Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09Cisco Packet Tracer Overview 20 Jul09
Cisco Packet Tracer Overview 20 Jul09
 
DPDK KNI interface
DPDK KNI interfaceDPDK KNI interface
DPDK KNI interface
 
Python for the Network Nerd
Python for the Network NerdPython for the Network Nerd
Python for the Network Nerd
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Intel dpdk Tutorial
Intel dpdk TutorialIntel dpdk Tutorial
Intel dpdk Tutorial
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 

Similar to Bypassing DEP using ROP

Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++
Fernando Moreira
 

Similar to Bypassing DEP using ROP (20)

fg.workshop: Software vulnerability
fg.workshop: Software vulnerabilityfg.workshop: Software vulnerability
fg.workshop: Software vulnerability
 
Compromising Linux Virtual Machines with Debugging Mechanisms
Compromising Linux Virtual Machines with Debugging MechanismsCompromising Linux Virtual Machines with Debugging Mechanisms
Compromising Linux Virtual Machines with Debugging Mechanisms
 
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)
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick review
 
A compact bytecode format for JavaScriptCore
A compact bytecode format for JavaScriptCoreA compact bytecode format for JavaScriptCore
A compact bytecode format for JavaScriptCore
 
Demystify eBPF JIT Compiler
Demystify eBPF JIT CompilerDemystify eBPF JIT Compiler
Demystify eBPF JIT Compiler
 
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them allDEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW Security
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
[若渴計畫] Challenges and Solutions of Window Remote Shellcode[若渴計畫] Challenges and Solutions of Window Remote Shellcode
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
 
test
testtest
test
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash Cracking
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
Workshop "Can my .NET application use less CPU / RAM?", Yevhen Tatarynov
Workshop "Can my .NET application use less CPU / RAM?", Yevhen TatarynovWorkshop "Can my .NET application use less CPU / RAM?", Yevhen Tatarynov
Workshop "Can my .NET application use less CPU / RAM?", Yevhen Tatarynov
 
Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 

More from Japneet Singh (7)

Polarbear recent windows 0day
Polarbear   recent windows 0dayPolarbear   recent windows 0day
Polarbear recent windows 0day
 
Code signing and trust
Code signing and trustCode signing and trust
Code signing and trust
 
Tor the onion router
Tor   the onion routerTor   the onion router
Tor the onion router
 
Malware classification using Machine Learning
Malware classification using Machine LearningMalware classification using Machine Learning
Malware classification using Machine Learning
 
Exploiting the windows kernel
Exploiting the windows kernelExploiting the windows kernel
Exploiting the windows kernel
 
Reverse engineering
Reverse engineeringReverse engineering
Reverse engineering
 
Advanced persistent threats
Advanced persistent threatsAdvanced persistent threats
Advanced persistent threats
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 

Recently uploaded (20)

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 

Bypassing DEP using ROP

  • 1. Bypassing DEP using ROP By Japneet Singh
  • 2. Agenda • Buffer overflow exploits • Data execution prevention (DEP) • Key idea behind bypassing DEP • ROP • Demo
  • 3. Buffer overflow exploits • 2 stages • Memory corruption to inject shellcode • Redirect process execution to injected shellcode
  • 4. Vulnerable code int main(int argc, char *argv[]) { … char buffer[2048]{}; HANDLE h = ::CreateFileA(argv[1], …); … DWORD bytesRead = 0; if (!::ReadFile(h, buffer, 2048, &bytesRead, …)) { … ProcessInput(buffer, bytesRead); … } void ProcessInput(char *str, int size) { char inputCopy[MAX_PATH]{}; memcpy(inputCopy, str, size); printf(inputCopy); }
  • 5. Stack based buffer overflow Stack frame of main() Parameters to ProcessInput() Return address to main() Stack frame of ProcessInput() On entering ProcessInput Stack frame of main() Overwritten area Overwritten area Address of Shellcode Shellcode Shellcode NOPs On memcpy FFFF F200 FFFF F200 Stack frame of main() Overwritten area Overwritten area Address of Shellcode Shellcode Shellcode NOPs F200 FFFF On return from ProcessInput
  • 6. Buffer overflow mitigations • To make buffer overflows harder, make either of the two stages harder to implement • Windows Vista introduced few mechanisms to make buffer overflows harder: • ASLR – Pseudo-randomize the addresses where binaries load, and where stacks/heaps get laid out. • DEP – Mark memory areas as executable or non-executable. Any attempt to execute code from an area marked as non-executable would lead to access violation.
  • 7. If DEP is enabled Stack frame of main() Parameters to ProcessInput() Return address to main() Stack frame of ProcessInput() On entering ProcessInput Stack frame of main() Overwritten area Overwritten area Address of Shellcode Shellcode Shellcode NOPs On memcpy FFFF F200 FFFF F200 Stack frame of main() Overwritten area Overwritten area Address of Shellcode Shellcode Shellcode NOPs F200 FFFF On return from ProcessInput
  • 8. Key idea behind bypassing DEP • Find and execute relevant instructions from existing code which is already marked executable.
  • 9. Return oriented programming (ROP) • Figure out what instructions are needed to be executed • Find out a small groups of required instructions in the existing code, such that each small group is followed by return. Such small groups of instructions ending with return are called Rop Gadgets. • Setup the stack so that each each Rop Gadget’s return leads exactly to execution of next Gadget.
  • 10. How ROP works ... … Return from Function 1 Function 1 parameters Function 1 address Gadget 2 address Gadget 1 address … Stack Code in loaded Exe/Dll(s) **** **** **** push esp ret **** **** **** mov esp, ebp pop ebp ret FFFF F200 **** **** **** **** ret
  • 11. One more concept • Modifying a page protection using VirtualProtect • Can make memory pages executable VirtualProtect(address, size, PAGE_EXECUTE_READWRITE, &oldProtection)
  • 12. Using ROP to bypass DEP Stack frame of main() Shellcode Address of VirtualProtect Address of shellcode Parameters to VirtualProtect Stack frame to be used by VirtualProtect F200 FFFF On return from ProcessInput Code in loaded Exe/Dll(s) **** **** **** **** ret VirtualProtect in Kernel32.dll
  • 13. Demo • Making stack executable via VirtualProtect call using simple ROP
  • 14. Current scenario • Many Advanced exploit detection engines introduced mitigations for ROP • Windows 10 introduced Control flow guard to mitigate ROP • ROP is almost dead, and not seen in the wild! • But, there are other ROP-less techniques 