Overview
Thechain command automatically builds ROP chains to achieve specific goals like spawning a shell or calling functions with controlled arguments.
Usage
Arguments
path- Path to the binary to analyze
Options
-t, --target- Target goal for the ROP chain (required)-f, --fast- Skip optimization for faster chain generation
Target Goals
The-t/--target option specifies what the ROP chain should accomplish:
execve
Generate a ROP chain that calls execve("/bin/sh", 0, 0) to spawn a shell.
- Looks for
execvein PLT or symbols - Searches for
/bin/shstring in the binary - If
/bin/shis not found, writes it to writable memory first
system
Generate a ROP chain that calls system("sh") to spawn a shell.
- Requires the binary to have a
systemfunction in PLT or symbols - Searches for
shstring in the binary
arg1, arg2, arg3, arg4
Generate a ROP chain to call a function at address 0xdeadbeef with 1, 2, 3, or 4 arguments set to 0x41414141.
Useful for testing argument-passing gadgets or calling specific functions.
Fast Mode
By default, the chain command optimizes gadgets after finding them, which can take time. Use the-f/--fast flag to skip optimization:
Output Format
The command outputs Python code using pwntools-style syntax:Example: execve Chain
Performance
Like the dump command, chain uses cached gadgets from/tmp to speed up subsequent runs on the same binary. Optimization (when not using -f) runs in parallel using all available CPU cores.