Register Preservation
When building complex chains, you often need to set up multiple registers without clobbering values you’ve already set.Basic Register Preservation
Preserving Multiple Registers
Function Calls with Register Preservation
From the Python API docs and real examples:preserve_regs={'rdi'}, angrop will:
- Ignore the first argument (
0x41414141) since rdi is preserved - Only set registers that are not in the preserve set
- Keep the existing value in rdi intact
Real-World Example: Kernel Chain
Fromexamples/linux_escape_chain/solve.py:38-44:
move_regs(rdi='rax')puts the task_struct pointer in rdiset_regs(rsi=init_nsproxy, preserve_regs={'rdi'})sets rsi without destroying rdifunc_call("switch_task_namespaces", [], preserve_regs={'rdi', 'rsi'})keeps both arguments
Sigreturn (SROP) Chains
Signal return frames let you set all registers at once, including RIP and RSP.Basic Sigreturn
Sigreturn for Syscalls
Fromdocs/pythonapi.md:61-62:
When to Use Sigreturn
Use SROP when:- You have very few gadgets available
- You need to set many registers at once
- You want to control both code and stack pointers
- You have a
sigreturngadget (or syscall 15 on x86_64)
Memory Write + Function Call Chains
Complex exploits often require writing data to memory before calling functions.Write String Then Call Function
Fromdocs/pythonapi.md:45-46, 77:
Complete File Read Chain
Memory Manipulation Chains
Memory Arithmetic Operations
Fromdocs/pythonapi.md:39-42:
Practical Use: Bypassing Canary
Register Movement Patterns
Moving Return Values
Complex Register Shuffling
Stack Pivoting
Pivot to Controlled Region
Fromdocs/pythonapi.md:49-50:
Complete Pivot Example
Syscall Chains
Direct Syscall Invocation
Fromdocs/pythonapi.md:56:
execve() via Syscall
Advanced Chain Techniques
Ret Sled
Fromdocs/pythonapi.md:69-70:
- Align stack before calling functions
- Delay execution for timing attacks
- Pad chain to avoid detection
Stack Shifting
Fromdocs/pythonapi.md:67:
Badbyte Avoidance
Fromdocs/pythonapi.md:72-74:
Multi-Stage Exploit Example
Debugging Complex Chains
Pretty Print with Comments
Generate Python Code
Fromdocs/pythonapi.md:80-87:
Validate Chain Length
Common Patterns
Pattern: Open-Read-Write
Pattern: Privilege Escalation
Pattern: Socket Reuse
Related Examples
- Kernel Escape Chain - Real-world kernel exploitation
- Custom Gadgets - Working with specific addresses