aptitude-test

Event
BrunnerCTF 2026
Category
rev
Published
Tags
#cipher #oracle #anti-cheat #windows

Reversing the score file cipher, working out the plaintext layout and spawn generation, then using the submission server itself as an oracle to land a score over 9000 without tripping the anti-cheat.

rev7 min read

On this page

At BrunnerCorp, we test that all prospective candidates have the core competencies required before submitting an application. One such competency is the ability to meet harder and harder goals within increasingly unrealistic timelines as a deadline approaches. […] We only consider applicants with a score of over 9000. Please note that all forms of cheating will be detected and result in immediate disqualification.

An aim-trainer with an anticheat wrapper. After a game, it writes your results in aim-score.bin and you upload it manually. Beating 9000 without ‘cheating’ is impossible.


1. Recon

The binary is a Rust and not stripped, the COFF symbol table survives with 6200 entries, including the whole anticheat crate:

anticheat::game::{run, window_proc, STATE}
anticheat::container::{open_package, read_package_header, derive_nonce, read_chunk, ...}
anticheat::integrity::{load_and_run, verify_header, validate_and_execute_package, Protector::*}
anticheat::hash::{Fnv64::*, hash64, StreamCipher::apply}
anticheat::loader::{PayloadVm::*, launch_stream}
anticheat::vm::{build_program, execute}
anticheat::anti_debug::windows::{peb_being_debugged, ntdll_hook_indicators, ...}
anticheat::input::{BotDetector::{push, score, looks_automated}, demo_score}
anticheat::strings::{xor_decode, xor_decode_wide}
anticheat::decoy::{decoy_path, decoy_branch, decoy_checksum}

Source paths leak as well: /mnt/d/CTF/BrunnerCTF/2026/BrunnerCorp Pre-Employment Aptitude Test/src/anticheat/src/.

Gotcha: the symbol values are section-relative, not RVAs. VA = ImageBase + 0x1000 + value. window_proc reads as 0x1c9d0 but actually lives at 0x14001d9d0. objdump’s own labels are the authority

The 1.4 MB decoy

There is a 1,421,071-byte encrypted payload at the end of the file, beginning at 0x15aa7b, entropy 8.00, with trailer magic HACEX001. Together with container::*, integrity::validate_and_execute_package, loader::PayloadVm and vm::execute it looks exactly like the intended target, an encrypted embedded payload with chunked stream encryption and FNV-keyed nonces.

It is just a decoy. game::run and window_proc are in the outer binary, and window_proc is what writes aim-score.bin. The overlay, the VM, the anti-debug suite and decoy::* are all there to pull you and make you waste time.


2. The score file cipher

aim-score.bin is written at the end of window_proc. Two string xrefs give it away:

0x14001e90b  lea rdi, [rip+0xa303e]   ; "BrunnerAimTrainer-static-key"
0x14001e98b  lea rcx, [rip+0xa2fda]   ; "aim-score.bin"
0x14001e997  call std::fs::File::create
0x14001e9c1  call std::io::Write::write_all

The loop just above it is a 2×-unrolled XOR:

movabs r8, 0x4924924924924925   ; magic divide-by-28  (key length)
mov    sil, 0x11                ; counter, += 0x22 per 2 bytes
...
lea    edx, [rsi-0x11]
xor    dl,  BYTE PTR [r10+rax*1]      ; key[i % 28]
xor    BYTE PTR [rcx+r10*1], dl
movzx  eax, BYTE PTR [r10+rax*1+0x1]  ; key[(i+1) % 28]
xor    al,  sil
xor    BYTE PTR [rcx+r10*1+0x1], al

0x4924924924924925 is the unsigned-division magic for 28 (the key length): q = mulhi(n>>2, magic) >> 1. The counter advances 0x22 per two bytes, so per byte it’s 0x11, and the even branch subtracts 0x11, meaning both halves reduce to the same expression:

out[i] = in[i] ^ KEY[i % 28] ^ ((0x11 * i) & 0xff)
KEY = "BrunnerAimTrainer-static-key"   (28 bytes)

It is an involution, so the same function encodes and decodes.

There is no MAC. Grepping window_proc’s whole extent for call targets doesn’t resolve to hash64, Fnv64::* or StreamCipher::apply. Nothing has to be recomputed after editing.


3. Plaintext layout

From the Vec::extend chain at 0x1e246 to 0x1e6bb:

offsizefield
014"BRUNNER-AIM-1\0"
148seed (STATE+0xd8)
224client width (STATE+0xe8, min 100)
264client height (STATE+0xec, min 100)
304score (STATE+0x90)
344click count (STATE+0x18)
384spawn count (STATE+0x30)
4224·nclicks: {t_ms:u64, x:u32, y:u32, w:u32, h:u32}
…36·mspawns: {spawn_ms:u64, x:u32, y:u32, radius:u32, w:u32, h:u32, expire_ms:u64}

The spawn struct is 40 bytes in memory (lea rdx,[rdi+rdi*4], *8) but serialises as 36, there’s padding at +0x1c that is not written.


4. Spawn generation

The server re-derives the entire target sequence from the seed, so this has to be reproduced exactly. From 0x1eae6 to 0x1edc0:

PRNG: xorshift64 (state STATE+0xe0, seeded from the u64 at STATE+0xd8):

x ^= x << 13;  x ^= x >> 7;  x ^= x << 17

Note the binary also contains SplitMix64 (0xbf58476d1ce4e5b9, 0x94d049bb133111eb), used elsewhere, and a nice red herring if you grep for PRNG constants and stop there.

Per target, with t = elapsed / 3600s clamped to 1.0:

radius = trunc(32 + t*(3 - 32))
s = xorshift64(s);  x = (s & 0xffffffff) % (w - 2*radius) + radius
s = xorshift64(s);  y = (s & 0xffffffff) % (h - radius - 70) + 70
lifetime = 1.25 + t*(0.01 - 1.25)   seconds
interval = 0.75 + t*(0.15 - 0.75)   seconds

The +70 is add ebp, 0x46; the w - 2*radius is sub r8d,r10d twice.

The constants come from the STATE initialiser in game::run (0x1d4d8), built on the stack then blitted. Mapping rsp+0x90 → STATE+0x08:

STATEvaluemeaning
+0x380xe10 = 3600game duration, seconds
+0x48/0x500, 750000000interval start 0.75 s
+0x58/0x600, 150000000interval end 0.15 s
+0x68/0x701, 250000000lifetime start 1.25 s
+0x78/0x800, 10000000lifetime end 0.01 s
+0x88/0x8c32, 3radius start / end

The durations are (u64 secs, u32 nanos) pairs recombined as secs + nanos/1e9.

“Over 9000”

The game is one hour long and the spawn interval shrinks 0.75 s to 0.15 s, so the number of targets is

N = ∫₀³⁶⁰⁰ dt / (0.75 - 0.6·t/3600) = (3600/0.6)·ln(0.75/0.15) = 6000·ln 5 ≈ 9657

The score increases by one point per hit. 9000 is ~93% correct hits of a perfect hour. It also means reaction time is budgeted: since the next target spawns interval after your click, a react time r gives 6000·ln((0.75+r)/(0.15+r)), so 8100 at 60 ms, 9064 at 20 ms, 9500 at 5 ms. The generator truncates the interval to whole milliseconds each step, which pushes the real counts slightly higher: 8207, 9084 and 9515 respectively. Cheating is the only way to solve the challenge (unless you are secretly superman).


5. The server as an oracle

The upload endpoints returns different errors based on what you submit:

  1. Invalid score file: invalid spawn timing

My first forgery treated the 36-byte array as “hit records” and stuffed arbitrary values in, producing expire_ms = 344 against spawn_ms = 1100. To pass, expire = spawn + lifetime must hold with spawn_ms monotonic.

  1. spawn 0 radius does not match seed/rules

Spawns are not free-form, they are re-derived from the seed. This is what revealed that offset 14 is the seed. Fixing this required the full section 4 reconstruction. t=0 → radius=32 is the first thing checked.

  1. [CHEATING DETECTED]: file claims score 58, replay produced score 49

Two bugs at once:

  • It echoed 58, which was my miss count at offset 30, so offset 30 is the score.
  • The replay found only 49/9672. My spawns were on a fixed timer; the real recurrence is click-relative, STATE+0xa8 is rewritten by Instant::now() on the click path, so spawn[i+1] = click[i] + interval(t). On a fixed timer the timeline desynchronises after the first target and only re-aligns by coincidence, which is exactly what 49 hits out of 9672 looks like.

6. Final generator

KEY   = b"BrunnerAimTrainer-static-key"
MAGIC = b"BRUNNER-AIM-1\x00"
crypt = lambda b: bytes(c ^ KEY[i%28] ^ ((0x11*i)&0xff) for i,c in enumerate(b))

def xorshift64(x):
    x ^= (x << 13) & M64;  x ^= x >> 7;  x ^= (x << 17) & M64
    return x & M64

t_ms, s = 0, seed
while t_ms < 3600_000:
    t      = min(1.0, t_ms / 3600_000)
    radius = max(1, int(32 + (3-32)*t))
    s = xorshift64(s); x = (s & 0xffffffff) % (w - 2*radius) + radius
    s = xorshift64(s); y = (s & 0xffffffff) % (h - radius - 70) + 70
    life   = int((1.25 + (0.01-1.25)*t) * 1000)
    spawns.append((t_ms, x, y, radius, w, h, t_ms + life))
    click  = t_ms + max(1, min(5, life-1))
    clicks.append((click, x, y, w, h))
    t_ms   = click + max(1, int((0.75 + (0.15-0.75)*t) * 1000))

Output: 9515 spawns, 9515 clicks, score 9515, 570,942 bytes. Verified before upload, 1:1 click/spawn, every click inside its radius and within [spawn, expire], spawn_ms is strictly monotonic and the byte accounting is exact.

Accepted. The BotDetector never fired on the uploaded file: 5 ms reaction times and pixel-perfect centre clicks pass without complaint, so input::BotDetector is only wired into the local game loop, not the server-side validator. The server only checks the seed-derivation, spawn causality and replay score.


7. Takeaways

  • Find where the artefact is produced before attacking the crypto. The 1.8 MB HACEX001 container, the payload VM and the anti-debug suite are a complete, self-consistent rabbit hole. The score file is written in plaintext by the outer binary.
  • Check for a MAC early. Grepping window_proc for calls to the hash module took one command and determined the entire strategy, with a MAC this becomes a key-recovery problem; without one it’s a serialisation exercise.
  • A validating server is a free oracle. Three error strings pinned down the spawn semantics, the seed field and the score field.
  • The advertised threat model wasn’t the real one. “All forms of cheating will be detected” plus a whole BotDetector in the binary were also rabbit-holes - The validator only checks that the replay is internally consistent with the seed.