Skip to content
Adam Omar Saleh

Chronos Security logo, as used by CSCTF 2026CSCTF 2026Pwn

FORGE

A classic House of Force. The note editor (temper) has an off-by-design heap overflow that lets us smash the top chunk's size field with 0xffffffffffffffff.

Competition
Chronos Security logo, as used by CSCTF 2026CSCTF 2026
Category
PwnMedium (425 pts, 25 solves)
Source status
Source-documented · not platform-verified
Document
PDF edition3 min read

Brief

The challenge

Category
PWN / binary exploitation (heap)
Difficulty
Medium (425 pts, 25 solves)
Files
forge (PIE, full RELRO), libc.so.6 + ld-linux-x86-64.so.2 (glibc 2.27)
Remote
w03.ctf.chronos-security.ro:33295
Challenge page
Challenge page

TL;DR

A classic House of Force. The note editor (temper) has an off-by-design heap overflow that lets us smash the top chunk's size field with 0xffffffffffffffff. Because the binary runs glibc 2.27 (no top-chunk size sanity check), we then request one gigantic malloc to drag the top chunk down into libc, land the next allocation on __free_hook, overwrite it with system, and free a chunk containing "/bin/sh".

Text
heap+libc leak  →  overflow top size = -1  →  malloc(target-top)  →  __free_hook = system  →  free("/bin/sh")

01

Recon

The source (forge.c) is included. It's a 16-slot note manager over malloc:

  • forge — malloc(size) of any size, then read_until_nl(p, size) reads content (no NUL terminator written).

  • temper — "append more content":

    C
    read_until_nl(p + strlen(p), notes[i].size);   // BUG: should be size - strlen(p)

    It writes up to size bytes starting after the current string, so the total write can run past the end of the chunk — a controllable heap overflow.

  • inspect — puts(notes[i].data) → read primitive / info leak.

  • melt — free + NULLs the pointer (no classic UAF).

The header comment even names it: // forge - House of Force (glibc 2.27, Ubuntu 18.04). Protections: PIE + full RELRO (so the GOT is read-only — hooks in libc are the target).

02

Leaks

There's no direct UAF (melt nulls the pointer), but we can free a chunk, re-allocate the same size with empty content, then inspect to read the pointers libc left behind.

  • Heap leak: two 0x20 chunks → tcache. Re-forge one with empty content and read its fd, which is the address of the other freed chunk → heap_base = leak - 0x260.

  • Libc leak: a 0x500 request (chunk 0x510 > tcache max 0x410) goes straight to the unsorted bin on free, so its fd/bk point into main_arena. A 0x88 guard chunk (not a cached size) is carved after it so the free doesn't just consolidate into the top. Re-forge 0x500 empty, inspect → libc_base = leak - 0x3ebca0.

03

House of Force

  1. Put "/bin/sh\x00" in a chunk (reuses the freed tcache chunk, safely mid-heap).

  2. Forge a victim right before the top chunk (forge(0x28), carved fresh from the top so the bytes beyond it are pristine zeros → strlen is predictable).

  3. temper the victim so the write lands exactly on top->size, setting it to 0xffffffffffffffff. The write starts at victim_data + strlen (0x18); 16 bytes of padding + "\xff"*8 overwrite the top size.

  4. Request the magic size nb = __free_hook - 0x18 - top (passed as nb - 8 so request2size rounds back to nb). This moves the top chunk down to __free_hook - 0x18.

    • __free_hook is ≡ 8 mod 16, so we aim the next chunk's user pointer at __free_hook - 8 (16-aligned) and prefix the write with 8 junk bytes.

  5. The next forge returns __free_hook - 8; write padding + system.

  6. melt the "/bin/sh" note → free(ptr) calls __free_hook(ptr) = system("/bin/sh").

Shell. flag → /tmp/flag:

Text
CSCTF{7yb54DWvCapfEFMKrlBuaqKf}

04

Running

Shell
python3 exploit.py           # local, against ./forge with the shipped loader+libcpython3 exploit.py remote    # w03.ctf.chronos-security.ro:33295

Full exploit in exploit.py.

Flag: CSCTF{7yb54DWvCapfEFMKrlBuaqKf}

Flag

Result

Flag

CSCTF{7yb54DWvCapfEFMKrlBuaqKf}

Source-documented · not platform-verified

PDF edition

Writeup PDF

Formatted edition of this walkthrough, built from my source notes · 4 pages.