Binary Exploitation
Cyber Academy S23
Announcements
✨Social Engineering Time ✨
Binary Exploitation Review
Review: The Stack
Review: How is the stack organized? (x86-64)
ROP: Overwriting the Return Address
Return address | 0x0000000000601234 |
Data (orig rbp value) | 0x0000000000401234 |
Input data | 0x0000000000000000 |
Input data | 0x0000000000000000 |
Stack frame:
func0:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
...read unlimited input into (%rsp)...
addq $16, %rsp
popq %rbp
ret
User input: aaaaaaaaaaaaaaaaaaaaaaaaabcdefgh
(32 a’s)
rsp
Stack is expanded downwards
(towards lower address values)
Lower memory addresses
Higher memory addresses
ROP: Overwriting the Return Address
Return address | 0x6867666564636261 |
Data (orig rbp value) | 0x6161616161616161 |
Input data | 0x6161616161616161 |
Input data | 0x6161616161616161 |
Stack frame:
func0:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
...read unlimited input into (%rsp)...
addq $16, %rsp
popq %rbp
ret
User input: aaaaaaaaaaaaaaaaaaaaaaaaabcdefgh
(32 a’s)
rsp
Stack is expanded downwards
(towards lower address values)
Data is written into the stack upwards (towards higher address values)
Lower memory addresses
Higher memory addresses
ROP: Overwriting the Return Address
Return address | 0x6867666564636261 |
Data (orig rbp value) | 0x6161616161616161 |
Input data | 0x6161616161616161 |
Input data | 0x6161616161616161 |
Stack frame:
func0:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
...read unlimited input into (%rsp)...
addq $16, %rsp
popq %rbp
ret
User input: aaaaaaaaaaaaaaaaaaaaaaaaabcdefgh
(32 a’s)
rsp
Stack is expanded downwards
(towards lower address values)
Data is written into the stack upwards (towards higher address values)
Lower memory addresses
Higher memory addresses
At the end of the function, it will “return” to the address 0x6867666564636261 and execute instructions there, a number that we control!
ROP: Overwriting the Return Address
Lower memory addresses - Higher memory addresses
Review: Code Injection
Review: Jumping to injected shellcode
Review: Jumping to injected shellcode
Exploit Mitigation: NX
Automating Exploitation: pwntools
IO Example with pwntools
Quality of Life: ELF Loading and Endianness
Assembling Shellcode
Demo Time!
Review: ROP Chains
Finding Gadgets
Exploit Mitigation: ASLR
Useful Tool: ASREPL
Useful GEF Commands: vmmap
checksec
info frame
deref
Challenges!!!
Check out our linktree: