SlideShare a Scribd company logo
ROP Chaining
What is it?
• So that we can control the EIP via a series of
cleverly crafted RETs, that’s not in our control, on
the Stack and bypass ASLR, W^X etc. and finally
achieve attacker controlled code execution !
Why is it needed ?
Return Oriented Programming (ROP chaining)
Let us decode that ****
• EIP
• RETs
• Stack
• Code execution
• ASLR
• W^X
Basics
• Function call under the hood
Function call ()
• CALL = PUSH RET ADDRESS ON STACK
• { = SET UP THE STACK =
• MOVE ESP AHEAD
• PUSH EBP
• MOV ESP TO EBP
Function Return
• return/ } =
• 2) ret =
• return control back to the calling function = the return
address stored earlier on the stack = pop eip
• 1) leave =
• restore esp = mov ebp to esp
• restore ebp = pop ebp
TOS
CALL instruction
TOS
Return Address
{ = function set up
TOS
Old EBP xxxx
EBP
Old EBP
EBP
xxxx
Argument
Return Address
TOS
Old EBP xxxx
EBP
xxxx} = return = leave + ret
leave instruction =
1) esp = ebp
TOS
leave instruction = 2) pop ebp
TOS
ret instruction = pop esp
TOS
Return Address
EIP
Hence the idea
• Put things WE want on the stack so that it
eventually ends up in the EIP
• Vanilla Buffer Overflow works
Challenges
• Stack region should be executable (DEP/W^X)
• Address to put on stack (address of shell
code) should be known/predictable (ASLR)
ASLR
• What ?
• Why ?
• How ?
Sample
• Vulnerable to buffer overflow.
• add_bin() - adds “/bin” to a string
• add_sh() - adds “/sh” to the same string
• exec_string() - calls system(the_above_string)
Objective
• Get $
• Hint :
• How do we execute all 3 ()s in a sequence ?
Initial thoughts ?
• Address of each function is known ! Can’t we just
put them on the stack as we would for the first
function ?
YES, that’s the idea !
• But NO, not as directly ! WHY ?
Return Oriented Programming (ROP chaining)
What just happened ?
• We arranged the stack as we were planning to.
actual return address of
vulnerable_function
&add_bin()
actual return address of
add_bin()&pop;ret
argument for add_bin()
actual return address of
add_sh()
&add_sh()
&pop;pop;ret
arg1 for add_Sh()
arg2 for add_Sh()
&exec_string()
EIP
&add_bi
n()
&pop;retpopret
ROP-fu
• This is what is ROP chaining
GADGETS
• Find instructions of the format
….. RET
• This is what we call `GADGETS`
• There are automated tools to find these in
your binary
ACHIEVEMENT
• Use them to achieve what you want. This is one
way to bypass ASLR - actually better said as :
achieve what we want despite ASLR being
present !
Applications
Some rather fancy ones
• Exploits
• JailBreaks
• Rooting
QUESTIONS ??
Resources
• https://reverseengineering.stackexchange.com/questions/1992/what-is-plt-got
• https://www.blackhat.com/presentations/bh-usa-08/Shacham/BH_US_08_Shacham_Return_Oriented_Programming.pdf
• https://www.trust.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_TRUST/LectureSlides/Chapter02%20-
%20RuntimeAttacks.pdf
• https://stackoverflow.com/questions/4292447/does-ret-instruction-cause-esp-register-added-by-4
• https://security.stackexchange.com/questions/37373/aslr-randomization-bss
• https://www.trustwave.com/Resources/SpiderLabs-Blog/Baby-s-first-NX-ASLR-bypass/
• https://www.rcesecurity.com/2011/12/stack-manipulation-using-pop-ret/
• https://dkalemis.wordpress.com/2010/10/27/the-need-for-a-pop-pop-ret-instruction-sequence/
• https://github.com/JonathanSalwan/ROPgadget
• https://sploitfun.wordpress.com/2015/05/08/bypassing-aslr-part-iii/
• https://stackoverflow.com/questions/41231637/how-does-a-function-call-work
• http://www.avrbeginners.net/new/wp-content/uploads/2011/08/avrbeginners_04_Jumps_Calls_and_the_Stack_1.0.1.pdf
• https://cs.nyu.edu/courses/fall04/V22.0201-003/ia32_chap_03.pdf
• https://stackoverflow.com/questions/16368769/return-to-call-after-jumps-in-assembly
Return Oriented Programming (ROP chaining)

More Related Content

PPTX
What is Stack? Application of Stack
PDF
Javascript Secrets - Front in Floripa 2015
PPTX
An introduction to ROP
PPT
PPT
PPT
Repl internals
DOCX
Exercice.docx
PPTX
How Functions Work
What is Stack? Application of Stack
Javascript Secrets - Front in Floripa 2015
An introduction to ROP
Repl internals
Exercice.docx
How Functions Work

What's hot (20)

PDF
Command line arguments that make you smile
PDF
Linux class 15 26 oct 2021
PDF
Functional Programming in JAVA 8
PDF
The Compatibility Challenge:Examining R and Developing TERR
PPTX
Return Oriented Programming (ROP) Based Exploits - Part I
PDF
NTUSTxTDOH - Pwn基礎 2015/12/27
PDF
GNU Parallel
PDF
台科逆向簡報
PPTX
Actor systems
PDF
Buzzword poem generator in Python
ODP
Java Boilerplate Busters
PPTX
Unix training session 3
ODP
Java Boilerplate Busters
ODP
With package
PDF
multi-line record grep
ZIP
.Net 4.0 Threading and Parallel Programming
PDF
Asynchronous Python at Kumparan
PPTX
test
PPTX
Intro to reverse engineering owasp
PDF
Performance testing of microservices in Action
Command line arguments that make you smile
Linux class 15 26 oct 2021
Functional Programming in JAVA 8
The Compatibility Challenge:Examining R and Developing TERR
Return Oriented Programming (ROP) Based Exploits - Part I
NTUSTxTDOH - Pwn基礎 2015/12/27
GNU Parallel
台科逆向簡報
Actor systems
Buzzword poem generator in Python
Java Boilerplate Busters
Unix training session 3
Java Boilerplate Busters
With package
multi-line record grep
.Net 4.0 Threading and Parallel Programming
Asynchronous Python at Kumparan
test
Intro to reverse engineering owasp
Performance testing of microservices in Action
Ad

Similar to Return Oriented Programming (ROP chaining) (20)

PDF
127 Ch 2: Stack overflows on Linux
PDF
CNIT 127: Ch 2: Stack Overflows in Linux
PDF
127 Ch 2: Stack overflows on Linux
PDF
CNIT 127: Ch 2: Stack overflows on Linux
PDF
CNIT 127 Ch 2: Stack overflows on Linux
PPTX
Buffer overflow attacks
PDF
ROP 輕鬆談
PDF
CNIT 127 Ch 2: Stack overflows on Linux
PPTX
Basic ASM by @binaryheadache
PPT
Stacks
PPT
Software Exploitation Techniques by Amit Malik
PDF
5 chapter3 list_stackqueuepart2
PDF
Diving Into Memory Allocation to Understand Buffer Overflow Better
PDF
lec15_x86procedure_4up.pdf
PPTX
Reversing malware analysis training part4 assembly programming basics
PDF
PDF
05_Return_to_Libc.pdf
PDF
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
PPTX
Software to the slaughter
PDF
rop heap attacks cfi int overflows computer security
127 Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack Overflows in Linux
127 Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
Buffer overflow attacks
ROP 輕鬆談
CNIT 127 Ch 2: Stack overflows on Linux
Basic ASM by @binaryheadache
Stacks
Software Exploitation Techniques by Amit Malik
5 chapter3 list_stackqueuepart2
Diving Into Memory Allocation to Understand Buffer Overflow Better
lec15_x86procedure_4up.pdf
Reversing malware analysis training part4 assembly programming basics
05_Return_to_Libc.pdf
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Software to the slaughter
rop heap attacks cfi int overflows computer security
Ad

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
Modernizing your data center with Dell and AMD
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
cuic standard and advanced reporting.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation_ Review paper, used for researhc scholars
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx

Return Oriented Programming (ROP chaining)

  • 3. • So that we can control the EIP via a series of cleverly crafted RETs, that’s not in our control, on the Stack and bypass ASLR, W^X etc. and finally achieve attacker controlled code execution ! Why is it needed ?
  • 5. Let us decode that **** • EIP • RETs • Stack • Code execution • ASLR • W^X
  • 6. Basics • Function call under the hood
  • 7. Function call () • CALL = PUSH RET ADDRESS ON STACK • { = SET UP THE STACK = • MOVE ESP AHEAD • PUSH EBP • MOV ESP TO EBP
  • 8. Function Return • return/ } = • 2) ret = • return control back to the calling function = the return address stored earlier on the stack = pop eip • 1) leave = • restore esp = mov ebp to esp • restore ebp = pop ebp
  • 9. TOS CALL instruction TOS Return Address { = function set up TOS Old EBP xxxx EBP Old EBP EBP xxxx Argument
  • 10. Return Address TOS Old EBP xxxx EBP xxxx} = return = leave + ret leave instruction = 1) esp = ebp TOS leave instruction = 2) pop ebp TOS ret instruction = pop esp TOS Return Address EIP
  • 11. Hence the idea • Put things WE want on the stack so that it eventually ends up in the EIP • Vanilla Buffer Overflow works
  • 12. Challenges • Stack region should be executable (DEP/W^X) • Address to put on stack (address of shell code) should be known/predictable (ASLR)
  • 13. ASLR • What ? • Why ? • How ?
  • 14. Sample • Vulnerable to buffer overflow. • add_bin() - adds “/bin” to a string • add_sh() - adds “/sh” to the same string • exec_string() - calls system(the_above_string)
  • 15. Objective • Get $ • Hint : • How do we execute all 3 ()s in a sequence ?
  • 16. Initial thoughts ? • Address of each function is known ! Can’t we just put them on the stack as we would for the first function ?
  • 17. YES, that’s the idea ! • But NO, not as directly ! WHY ?
  • 19. What just happened ? • We arranged the stack as we were planning to.
  • 20. actual return address of vulnerable_function &add_bin() actual return address of add_bin()&pop;ret argument for add_bin() actual return address of add_sh() &add_sh() &pop;pop;ret arg1 for add_Sh() arg2 for add_Sh() &exec_string() EIP &add_bi n() &pop;retpopret
  • 21. ROP-fu • This is what is ROP chaining
  • 22. GADGETS • Find instructions of the format ….. RET • This is what we call `GADGETS` • There are automated tools to find these in your binary
  • 23. ACHIEVEMENT • Use them to achieve what you want. This is one way to bypass ASLR - actually better said as : achieve what we want despite ASLR being present !
  • 24. Applications Some rather fancy ones • Exploits • JailBreaks • Rooting
  • 26. Resources • https://reverseengineering.stackexchange.com/questions/1992/what-is-plt-got • https://www.blackhat.com/presentations/bh-usa-08/Shacham/BH_US_08_Shacham_Return_Oriented_Programming.pdf • https://www.trust.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_TRUST/LectureSlides/Chapter02%20- %20RuntimeAttacks.pdf • https://stackoverflow.com/questions/4292447/does-ret-instruction-cause-esp-register-added-by-4 • https://security.stackexchange.com/questions/37373/aslr-randomization-bss • https://www.trustwave.com/Resources/SpiderLabs-Blog/Baby-s-first-NX-ASLR-bypass/ • https://www.rcesecurity.com/2011/12/stack-manipulation-using-pop-ret/ • https://dkalemis.wordpress.com/2010/10/27/the-need-for-a-pop-pop-ret-instruction-sequence/ • https://github.com/JonathanSalwan/ROPgadget • https://sploitfun.wordpress.com/2015/05/08/bypassing-aslr-part-iii/ • https://stackoverflow.com/questions/41231637/how-does-a-function-call-work • http://www.avrbeginners.net/new/wp-content/uploads/2011/08/avrbeginners_04_Jumps_Calls_and_the_Stack_1.0.1.pdf • https://cs.nyu.edu/courses/fall04/V22.0201-003/ia32_chap_03.pdf • https://stackoverflow.com/questions/16368769/return-to-call-after-jumps-in-assembly

Editor's Notes

  • #3: Just a very clever trick with a very fancy (but meaningful) name !
  • #5: Some of us at this point are like
  • #7: gcc -ggdb -mpreferred-stack-boundary=2 -fno-stack-protector -z execstack -o funCall_output funCall.c