
Performing Return Oriented Programming
Methodology for building Return-Oriented Programming (ROP) chains to bypass NX/DEP by...
Install
npx skills add xalgorix/xalgorix --skill performing-return-oriented-programming -g -a claude-code -y- Repository
- xalgorix/xalgorix1.3k
- Category
- Engineering
- Updated
- 6d ago
- License
- Apache-2.0
- Context cost
- Mediumabout 2,326 tokens
- Runs scripts
- No, instructions only
What it does
Methodology for building Return-Oriented Programming (ROP) chains to bypass NX/DEP by reusing existing code gadgets, covering gadget discovery, calling-convention argument setup, ret2libc, ret2syscall (execve), one_gadget, stack alignment, JOP, and stack pivoting across x86/x64/ARM64 during authorized engagements.
Performing Return-Oriented Programming
When to Use
- During authorized exploitation when you control the saved return address (via stack overflow, write-what-where, etc.) but NX/DEP prevents executing injected shellcode on the stack.
- When you need to call an existing function (
system,execve,mprotect) or invoke a syscall with attacker-chosen arguments by chaining small...; retgadgets. - When choosing between ret2libc (call a libc function), ret2syscall (raw
sys_execve, common in static binaries), ret2dlresolve, SROP (when gadgets are scarce), or stack pivoting (off-by-one / short overflows). - On ARM64 targets where
retjumps tox30and instructions cannot be entered mid-instruction, requiring JOP or pivot-based approaches.
Critical: Concepts/Steps Most Often Missed
- 16-byte stack alignment on x86-64. The SysV ABI requires
RSPbe 16-byte aligned at acall. libc functions use SSE (movaps) and willSIGSEGVif misaligned. Ifsystem()crashes inside libc, insert a bareretgadget before it to realign. This is the single most common reason a "correct" chain crashes. - Argument passing differs by arch/ABI. x86 cdecl pushes args on the stack (right-to-left); x86-64 SysV uses
RDI, RSI, RDX, RCX, R8, R9; Windows x64 usesRCX, RDX, R8, R9. You needpop rdi; ret-style gadgets to load registers, not just stack values. - The function needs a return slot. After
systemyou must place a return address (e.g.exit) or the chain crashes onsystem's own return. CTFs often get away with garbage, real targets do not. - ARM64 entry-point pitfall. When jumping to a function via ROP on ARM64, jump to the function's second instruction to avoid re-storing the stack pointer and looping forever.
- NUL bytes and bad chars in gadget addresses. A
pop rdi; retgadget at0x400686is fine, but addresses with NULs break string-copy overflows. Pick alternate gadgets or use ret2dlresolve/SROP.
