ROP Class Initialization
TheROP class is the main entry point for semantic-aware ROP gadget finding. It extends angr’s Analysis class and provides comprehensive configuration options.
Configuration Parameters
only_check_near_rets
If
True, only analyze blocks that are within max_block_size bytes of return instructions. This dramatically speeds up gadget finding by avoiding analysis of code that cannot form valid gadgets.Performance Impact: Reduces search space by 10-100x on typical binariesLimitations:- Only effective for i386, amd64, and aarch64 architectures
- Automatically disabled with warning for other architectures
- May miss gadgets in unusual code locations (rare in practice)
- Analyzing obfuscated or hand-crafted code
- Working with non-standard architectures
- Need exhaustive gadget coverage
max_block_size
Limits the maximum size (in bytes) of basic blocks considered for gadgets. Longer blocks are less likely to be useful ROP gadgets because they:
- Have more side effects
- Are harder to chain together
- May contain unwanted operations
- x86/x64: 20 bytes (normal), 12 bytes (fast mode)
- ARM: 16 bytes (normal), 8 bytes (fast mode)
- MIPS: 20 bytes (normal), 12 bytes (fast mode)
- Smaller values: Faster analysis, simpler gadgets, may miss complex operations
- Larger values: Slower analysis, more complex gadgets, more side effects
- Standard exploitation: Use default
- Speed-critical: 12-16 bytes
- Advanced techniques: 24-32 bytes
max_sym_mem_access
Maximum number of symbolic memory accesses allowed in a gadget. Memory accesses complicate:Trade-offs:
- Constraint solving during chain building
- Gadget semantics and side effects
- Reliability of exploitation
- Memory reads/writes where the address depends on registers
- Excludes word-sized stack accesses (considered normal)
- Excludes constant address accesses
- Normal mode: 2 accesses
- Fast mode: 1 access
- Lower values: Faster, simpler gadgets, may limit write/read primitives
- Higher values: Slower, more powerful memory operations
fast_mode
Enables aggressive optimizations to speed up gadget finding at the cost of completeness.Auto-detection: When set to
None, automatically enables for binaries with >20,000 address candidatesOptimizations enabled:- Reduces
max_block_sizeto architecture’sfast_mode_max_block_size - Sets
max_sym_mem_accessto 1 - Skips gadgets with:
- Conditional branches
- Floating point operations
- Non-return jumps
- Large binaries (>1MB)
- Initial gadget discovery
- Time-constrained scenarios
- Need advanced gadgets (conditional branches, complex operations)
- Small binaries where speed is not critical
- Comprehensive gadget coverage required
is_thumb
Execute ROP chain in ARM Thumb mode (16-bit instruction encoding).Requirements:
- Only valid for ARM architecture binaries
- Raises assertion error if used with non-ARM binaries
- angrop does not support mode switching within a ROP chain
- All gadgets in the chain must be in the same mode (ARM or Thumb)
- The initial gadget must be at an address with the Thumb bit set (addr | 1)
kernel_mode
Find gadgets suitable for kernel-mode exploitation.Changes in behavior:
- Searches only in
.textsection (if available) - Does not look for syscall gadgets near return instructions
- Uses kernel-specific architecture configuration
- Linux kernel exploit development
- Kernel module exploitation
- Privilege escalation from kernel context
stack_gsize
Number of controllable pointer-sized elements on the stack. Defines the maximum allowable stack change for gadgets.Maximum stack change:
stack_gsize * arch.bytesExamples:- 64-bit:
stack_gsize=80→ max stack change = 640 bytes - 32-bit:
stack_gsize=80→ max stack change = 320 bytes
- Gadgets with
stack_change > stack_gsize * arch.bytesare rejected - Affects initial state setup (symbolic stack size)
- Influences pivot gadget analysis
- Smaller values:
- Faster constraint solving
- Rejects gadgets with large stack pops
- May limit available gadgets
- Larger values:
- Slower symbolic execution
- Accepts gadgets with many pops
- More memory usage
- Standard exploitation: 80-100
- Constrained environments: 40-60
- Complex chains: 120-160
cond_br
Enable support for gadgets containing conditional branches. When enabled, a single address may produce multiple gadgets (one per execution path).Performance Impact:Example with cond_br:When to enable:
- Significantly slower gadget analysis (2-10x)
- Increases number of gadgets found
- Complicates chain building
- Each conditional path becomes a separate gadget
- Gadgets have
has_conditional_branchflag - Branch dependencies tracked in
branch_dependencies
- Need maximum gadget coverage
- Exploiting binaries with limited gadgets
- Advanced ROP techniques (conditional chains)
- Speed is critical
- Sufficient gadgets without conditional branches
- Simplify chain building logic
max_bb_cnt
Maximum number of basic blocks to traverse when analyzing a gadget. Controls the depth of symbolic execution.What it controls:
- Number of steps taken during symbolic execution
- Complexity of control flow followed
- Analysis timeout behavior
max_bb_cnt=1: Only single basic block gadgetsmax_bb_cnt=2: Gadgets spanning up to 2 basic blocks (e.g., call + ret)max_bb_cnt=3: More complex multi-block gadgets
- Lower values:
- Faster analysis
- Simpler gadgets
- May miss useful sequences
- Higher values:
- Slower analysis (exponential growth)
- More complex gadgets
- May include gadgets with excessive side effects
- Standard use: 2 (default)
- Simple gadgets only: 1
- Complex gadgets: 3-4 (use with caution)
cond_br=True