Chain Composition with the + Operator
One of angrop’s most powerful features is the ability to compose chains using the + operator. This allows you to build complex exploits step by step.
Basic Chain Composition
Multi-Step Exploit Example
This example shows building a complete exploit chain that opens and reads a file:Each chain operation returns a
RopChain object that can be combined with other chains using +. The resulting chain maintains all constraints and ensures correct execution order.Real-World Example: Linux Kernel Escape
This example from angrop’s test suite demonstrates composing a sophisticated kernel privilege escalation chain:Breaking Down the Chain
Let’s examine what each step accomplishes:1
Escalate privileges
commit_creds() with init_cred to gain root privileges.2
Find init process
rax.3
Move return value to argument register
rax to rdi for the next call.4
Set up additional arguments
rsi to init_nsproxy while preserving the rdi value we just set.5
Switch namespaces
6
Fork and sleep
Chain Inspection and Debugging
Angrop provides methods to inspect and debug your chains before using them:Pretty-Print Chains
Generate Exploit Code
Get Raw Bytes
Incremental Chain Building
You can build chains incrementally, adding operations as needed:Chain Optimization
Angrop automatically optimizes chains during generation, but you can influence the process:Minimize Stack Usage
Avoid Register Clobbering
Error Handling
When chain building fails, angrop raisesRopException with details:
Advanced Composition Patterns
Conditional Chains
Repeated Operations
Performance Considerations
- Chain length: Longer chains may take more time to generate due to constraint solving
- Preserve registers: Using
preserve_regsadds constraints and may limit available gadgets - Badbytes: More badbytes increase chain generation complexity
- Optimization: The initial
find_gadgets(optimize=True)enables better chain composition
Next Steps
Now that you understand chain composition, explore specific operations:- Register Operations - Setting and moving registers
- Memory Operations - Writing and modifying memory
- Function Calls - Calling functions with arguments
- Syscalls - Making system calls