The Broken Time Capsule

WolvCTF 2026RevHardBy ethandhomnicWriteup by @xabito

We recovered a command-line restoration tool and a damaged time-capsule backup. The tool claims the backup is unreadable, but it may be waiting for the right sequence.

Usage: ./time_capsule backup.tc (each slot is a decimal byte)

Recover the message and submit it as the flag.

Attachments

Recon

We get a stripped, statically-linked x86-64 Linux ELF (time_capsule, musl libc) and a 1227-byte custom-format backup file (backup.tc). The tool is invoked as:

./time_capsule <slot-1> <slot-2> <slot-3> <slot-4> backup.tc

Each slot is a decimal byte (0–255). The program prints one of two errors (“The clock face is unreadable.” / “Backup index is damaged; try a different copy.”) unless the correct 4-byte sequence is supplied, in which case it prints a hidden message containing the flag.

main (at 0x401060) is small: it strtols the four slot arguments, rejects anything non-numeric or greater than 255, packs them into four stack bytes, and calls a worker at 0x401290 with (backup_path, slots*). Return 0 means “damaged”; nonzero means success. The worker validates the file and then interprets it:

Ghidra decompilation of the worker validating the backup header

Exploitation

Reversing the file format

Header validation in the worker pins down the format:

Offset Size Meaning
0x00 4 magic TCAP
0x04 1 version, must be 0x02
0x05 1 p, number of VM instructions
0x06 1 height, ops per output byte, must be 1..32
0x07 1 must be 0xC3
0x08 2 code_len (LE), length of the encrypted message
0x0A 7·p VM code, 7 bytes per instruction

The total size must equal 10 + 7·p + 2·height + code_len. For backup.tc: p=0xA5 (165 instructions), height=10, code_len=42, giving 10+1155+20+42 = 1227 bytes. The tail is a 20-byte op stream (10 pairs of bytes) applied per output byte, then a 42-byte encrypted keystream. The three “record-like” strings in the file and the 0123456789ABCDEF hex table are red herrings. The apparent “SHA-256 IV words” (6a09e667, bb67ae85, …) are just 32-bit immediates inside the backup file, because the file is a program.

The virtual machine

Each instruction is 7 bytes: opcode, reg_a, reg_b, imm32, operating on eight 32-bit registers r0..r7. The opcode jump table at .rodata:0x408048 decodes to:

0x10 MOV r[a], imm32       0x24 ROL r[a], imm
0x11 LOAD r[a] = slot[b]   0x25 SHR r[a], imm        (logical)
0x12 MOV r[a], r[b]        0x26 ADD r[a], imm
0x20 ADD r[a], r[b]        0x27 XOR r[a], imm
0x21 XOR r[a], r[b]        0x28 MUL r[a], imm
0x22 MUL r[a], r[b]        0x29 AND r[a], imm
0x23 SUB r[a], r[b]        0x30 JZ r[a], rel    0x31 JNZ r[a], rel
0x32 JMP rel               0x40 CHECK r[a] == imm32   0xFE HALT

Invalid opcodes, out-of-range PCs/registers, a failing CHECK, an instruction budget overrun, or halting without exactly 2 passing CHECKs all trigger the “damaged” error.

Ghidra decompilation of the VM dispatch loop reaching the two CHECK instructions

On success, a key-derivation routine decrypts the trailing blob and writes it to stdout. The Python emulator used by the solver mirrors the parser, instruction budget, branches, and halt condition:

import struct

MASK = 0xffffffff

def rol32(x, n):
    n &= 31
    return ((x << n) | (x >> (32 - n))) & MASK if n else x

def parse(path):
    data = open(path, "rb").read()
    assert data[:4] == b"TCAP" and data[4] == 2 and data[7] == 0xc3
    p, height = data[5], data[6]
    code_len = struct.unpack("<H", data[8:10])[0]
    assert len(data) == 10 + 7 * p + 2 * height + code_len
    code_end = 10 + 7 * p
    op_end = code_end + 2 * height
    return {
        "p": p,
        "height": height,
        "code": data[10:code_end],
        "opstream": data[code_end:op_end],
        "keystream": data[op_end:],
    }

def run(meta, slots):
    code, p = meta["code"], meta["p"]
    regs = [0] * 8
    pc = steps = checks = 0
    while True:
        steps += 1
        if steps > 4 * p + 16:
            return False, "step limit"
        if not 0 <= pc < p:
            return False, "pc out of range"
        ins = code[7 * pc:7 * pc + 7]
        op, a, b = ins[0], ins[1], ins[2]
        imm = struct.unpack("<I", ins[3:7])[0]
        npc = pc + 1
        if op == 0xfe:
            if checks != 2:
                return False, "wrong CHECK count"
            return True, regs, checks
        if op == 0x10:
            regs[a] = imm
        elif op == 0x11:
            if b > 3:
                return False, "slot index"
            regs[a] = slots[b]
        elif op == 0x12:
            regs[a] = regs[b]
        elif op == 0x20:
            regs[a] = (regs[a] + regs[b]) & MASK
        elif op == 0x21:
            regs[a] ^= regs[b]
        elif op == 0x22:
            regs[a] = (regs[a] * regs[b]) & MASK
        elif op == 0x23:
            regs[a] = (regs[a] - regs[b]) & MASK
        elif op == 0x24:
            regs[a] = rol32(regs[a], imm)
        elif op == 0x25:
            regs[a] = (regs[a] >> (imm & 31)) & MASK
        elif op == 0x26:
            regs[a] = (regs[a] + imm) & MASK
        elif op == 0x27:
            regs[a] ^= imm
        elif op == 0x28:
            regs[a] = (regs[a] * imm) & MASK
        elif op == 0x29:
            regs[a] &= imm
        elif op in (0x30, 0x31):
            rel = imm - (1 << 32) if imm >= (1 << 31) else imm
            cond = (regs[a] == 0) if op == 0x30 else (regs[a] != 0)
            if cond:
                npc = pc + 1 + rel
        elif op == 0x32:
            rel = imm - (1 << 32) if imm >= (1 << 31) else imm
            npc = pc + 1 + rel
        elif op == 0x40:
            if regs[a] != imm:
                return False, f"CHECK failed at {pc}"
            checks += 1
        else:
            return False, f"bad opcode {op:#x}"
        pc = npc

Disassembling the 165 instructions shows four symmetric “rounds” mixing each slot into r0 (constants cribbed from SHA-256 IVs and SplitMix64, e.g. 0x85EBCA6B, 0x9E3779B9), then the same again into r4, then:

122: CHECK r0 == 0x2EC29234
123: CHECK r4 == 0x04DE2A9C

Each round is x = (acc + slot_i + C_i) ^ K_i; x = rol(x, R_i); x *= M_i (odd); x ^= x >> S_i, plus a parity branch on (slot_i + C_i) & 1 selecting either x ^= XO_i or x += AE_i. After the CHECKs, both registers are mixed further through four more slot-add/rol/xor rounds; r0 and r4 at HALT seed the message decryption.

Solving the slots without a 2³² brute force

Each round is invertible, so we can work backward from the first CHECK. The meet-in-the-middle search stores every (slot0, slot1) result entering round 2, then inverts rounds 3 and 2 for every (slot3, slot2) pair:

from collections import defaultdict

TARGET0 = 0x2ec29234
B0_0 = 0x6a09e667

# C, K, rotate, multiplier, shift, XOR-if-odd, add-if-even.
R0 = [
    (0x243f6a88, 0xa4093822, 7,  0x85ebca6b, 11, 0x9e3779b9, 0xa5a5a5a5),
    (0x85a308d3, 0x299f31d0, 13, 0xc2b2ae35, 15, 0x7f4a7c15, 0x3c6ef372),
    (0x13198a2e, 0x082efa98, 21, 0x27d4eb2f, 9,  0xd1b54a35, 0xbb67ae85),
    (0x03707344, 0xec4e6c89, 11, 0x165667b1, 13, 0x94d049bb, 0x6a09e667),
]

def mulinv(a):
    x = 1
    for _ in range(5):  # Newton iteration modulo 2^32
        x = (x * (2 - a * x)) & MASK
    return x

def mix(x, i, odd):
    C, K, R, M, S, XO, AE = R0[i]
    x = rol32(x ^ K, R)
    x = (x * M) & MASK
    x ^= x >> S
    return (x ^ XO) if odd else ((x + AE) & MASK)

def unmix(x, i, odd):
    C, K, R, M, S, XO, AE = R0[i]
    x = (x ^ XO) if odd else ((x - AE) & MASK)
    y = x
    for _ in range(32 // S + 1):  # undo x ^= x >> S
        y = x ^ (y >> S)
    x = (y * mulinv(M)) & MASK
    x = ((x >> R) | (x << (32 - R))) & MASK if R else x
    return x ^ K

meta = parse("backup.tc")
fwd = defaultdict(list)
for s0 in range(256):
    x = (B0_0 + s0 + R0[0][0]) & MASK
    x = mix(x, 0, (s0 + R0[0][0]) & 1)
    for s1 in range(256):
        y = (x + s1 + R0[1][0]) & MASK
        y = mix(y, 1, (s1 + R0[1][0]) & 1)
        fwd[y].append((s0, s1))

solutions = []
for s3 in range(256):
    a3 = unmix(TARGET0, 3, (s3 + R0[3][0]) & 1)
    b3 = (a3 - s3 - R0[3][0]) & MASK
    for s2 in range(256):
        a2 = unmix(b3, 2, (s2 + R0[2][0]) & 1)
        b2 = (a2 - s2 - R0[2][0]) & MASK
        for s0, s1 in fwd.get(b2, ()):
            slots = (s0, s1, s2, s3)
            if run(meta, slots)[0]:
                solutions.append(slots)

print(solutions)  # [(53, 167, 18, 233)]

For each MITM hit, run executes the full VM in Python, and we keep only tuples that pass both CHECKs and halt with exactly two passing checks. Exactly one tuple survives: slots = (53, 167, 18, 233).

Two details cost us debugging time: the parity branch tests (slot + C) & 1, not slot & 1 (some constants are odd), and one constant must be read little-endian from the byte stream (at pc 121 the bytes 22 38 09 a4 mean 0xA4093822).

Recovering the 42-byte message

At HALT, the initial chaining value is h0 = rol32(r4, 11) ^ r0. Each output byte uses key_i = rol32((slot[i&3] ^ (i*0x9E3779B9)) + h_i, (i%11)+5), then transforms its ciphertext byte with the 20-byte op stream. The operand byte B, not the opcode, selects the byte lane of key_i for sel.

def derive_msg(meta, slots, r0, r4):
    ks, ops = meta["keystream"], meta["opstream"]
    h = rol32(r4, 11) ^ r0
    out = bytearray()
    for i in range(len(ks)):
        t = slots[i & 3] ^ ((i * 0x9e3779b9) & MASK)
        key = rol32((t + h) & MASK, (i % 11) + 5)
        d = ks[i]
        for j in range(meta["height"]):
            op, B = ops[2 * j:2 * j + 2]
            sel = (key >> ((B & 3) * 8)) & 0xff
            if op == 0x41:
                d ^= slots[B]
            elif op == 0x52:
                d += B
            elif op == 0x63:
                d &= 0xff
                n = B & 7
                d = ((d << n) | (d >> (8 - n))) & 0xff if n else d
            elif op == 0x74:
                d ^= sel
            elif op == 0x85:
                d -= B
            elif op == 0x96:
                d += sel
            elif op == 0xa7:
                d ^= B * i
            else:
                raise ValueError(f"bad message op {op:#x}")
            d &= 0xff
        out.append(d)
        h = ((i * 0x45d9f3b + d) & MASK) ^ key
        h = (rol32(h, 7) + ks[i] - 0x5cbece94) & MASK
    return bytes(out)

slots = (53, 167, 18, 233)
ok, regs, checks = run(meta, slots)
assert ok and checks == 2
message = derive_msg(meta, slots, regs[0], regs[4])
assert len(message) == 42

The hash update after each byte is h_{i+1} = rol32(((i*0x45D9F3B + out_i) ^ key_i), 7) + ks_i - 0x5CBECE94, all modulo 2³². The op stream uses 0x41 for slot XOR, 0x52 for addition, 0x63 for an 8-bit rotate, 0x74 for sel XOR, 0x85 for subtraction, 0x96 for sel addition, and 0xA7 for XOR with B*i.

Flag capture

Running the real binary confirms the recovered slots and decrypted message:

$ docker run --rm --platform linux/amd64 -v "$PWD:/w" -w /w \
    debian:bookworm-slim ./time_capsule 53 167 18 233 backup.tc
wctf{the_clock_keeps_its_secrets_dce922ea}