ROPgadget
ROPgadget is a Python tool designed to search for ROP (Return-Oriented Programming) gadgets within binary files. It supports various file formats (ELF, PE, Mach-O, Raw) and architectures, including x86, x64, ARM, ARM64, PowerPC, SPARC, MIPS, RISC-V 64, and RISC-V Compressed. Currently at version 7.7, the project is actively maintained with several releases per year addressing bug fixes and adding support for new architectures and features.
Common errors
-
ROPgadget: command not found
cause ROPgadget's executable script is not in your system's PATH, or the installation was incomplete/failed. This typically happens if `pip`'s script directory isn't in PATH, or if you're trying to run `ROPgadget.py` directly from a cloned repository without installing it.fixEnsure ROPgadget is properly installed (`pip install ROPgadget`). Verify that the directory where pip installs executables (e.g., `~/.local/bin` or `/usr/local/bin`) is included in your system's PATH. If running from source, execute with `python3 ROPgadget.py` from the main project directory or install it via `sudo -H python3 setup.py install` to put it in your PATH. -
ImportError: No module named capstone
cause The Capstone disassembly framework, which is a fundamental dependency for ROPgadget, is not installed or not accessible within your current Python environment.fixInstall Capstone explicitly using pip: `pip install capstone` or `sudo -H python3 -m pip install capstone`. If you are working within a virtual environment, ensure it is activated before running the installation command. -
AttributeError: 'ROPgadget' object has no attribute 'rawArch'
cause This error might occur when using an older version of ROPgadget with command-line arguments or configurations that were introduced in newer versions, such as `--rawArch` for specifying raw architecture.fixUpgrade ROPgadget to the latest version (`pip install --upgrade ROPgadget`) to ensure all features and arguments are supported.
Warnings
- gotcha Older versions of ROPgadget might produce `SyntaxWarning` messages when run with newer Python interpreters, particularly Python 3.10+ or 3.13.
- gotcha When installing ROPgadget from source (rather than PyPI), the Capstone disassembly framework must be installed manually before ROPgadget. Failure to do so will result in import errors or installation failures.
- gotcha Historically, there have been compatibility issues with Python 3, particularly for older ROPgadget versions. While modern versions are Python 3 compatible, using outdated versions with Python 3 might lead to unexpected behavior.
- gotcha When building ROP chains for x86_64 binaries, especially targeting GLIBC functions like `printf()` or `system()`, the stack must be 16-byte aligned before function calls. Misalignment can cause `movaps` instructions to trigger general protection faults.
- gotcha When scanning Linux kernel images for ROP gadgets, generic tools like ROPgadget may produce false positives (e.g., from sections only executable at boot) and false negatives (e.g., from thunked returns).
Install
-
pip install ROPgadget
Imports
- main
from ropgadget import main # main() # To run the tool programmatically as an application entry point
Quickstart
# Analyze a binary for ROP gadgets ROPgadget --binary /bin/ls --only "pop|ret" --depth 3 # Find a ROP chain to execute /bin/sh (example) # Note: Actual binaries and gadgets will vary. This is a conceptual example. # Assuming a vulnerable binary `vuln` exists in the current directory ROPgadget --binary ./vuln --ropchain --badbytes "000a0d" --rawArch x64 --offset 0x0 --callPreceded