Overview
This example shows how to build a ROP chain that executes/bin/sh using the execve() system call. This is one of the most common goals in exploit development.
CLI Approach
The easiest way to generate an execve chain is using the command-line tool:CLI Output Example
- Sets up the necessary registers
- Prepares arguments for
execve() - Calls
execve@pltwith appropriate arguments
Python API Approach
Build execve chain
There are two approaches depending on whether the binary has an Method 2: Using syscall (if no execve function)
execve function:Method 1: Using execve@plt (if available)Complete Example
Simple execve() Chain
Advanced execve() Chain with Memory Write
How It Works
Anexecve("/bin/sh", NULL, NULL) chain needs to:
- Place “/bin/sh” in memory - Either find it in the binary or write it to a writable location
- Set up arguments - Set registers/stack for:
arg1: Pointer to “/bin/sh”arg2: NULL (argv)arg3: NULL (envp)
- Call execve - Either through PLT, direct symbol, or syscall
CLI Options
The CLI supports additional options:Understanding the Output
The generated chain usescode_base + offset format:
code_base = 0x0: Assumes PIE base is 0 (adjust in your exploit)- Each
p64()is either a gadget address or data - Comments show what each gadget does
code_base if the binary uses PIE/ASLR.