← all posts

· 3 min read · by Eav Puthcambo

When the provided solver is a trap

A Windows crackme ships two "reference" scripts that reimplement its VM. Both are wrong, because they hardcode a seed that real startup code computes. The fix is to stop reimplementing and emulate the real thing.

cr4ck 3 (Serial), LYKN CTF 2026 (reversing)

Serial.exe is a Windows dialog app: type a serial of the form LYKNCTF{ + 24 chars + }, hit a button, get a verdict. Behind it is a bytecode VM gated by a self-hash of its own .text section.

What makes this one interesting is that the challenge shipped two Python scripts that reimplement the VM statically, crack.py and debug.py, as if to help you. They're both broken.

Why the reference scripts never work

Brute-forcing against those scripts never produces a match. Tracing them shows a keystream desync and a wrong per-character offset, but the real root cause is deeper: both scripts hardcode the VM's initial seed (r15d = 0xc499790f), and that's simply wrong.

The real seed is derived from a global constant, 0xB16B00B5, written by startup code that runs before main. If you only emulate the check function in isolation, that code never executes, so the seed is never set correctly. The reachable value for position 0 just doesn't contain the target under the hardcoded seed, no matter what byte you try. The provided "help" is a dead end by design.

Emulate the real binary instead

Rather than keep patching a broken reimplementation, I built a Unicorn emulator of the actual executable and used it as an oracle:

  • map the PE, a stack, and a fake TEB/PEB (the check does a PEB anti-debug probe internally, so the emulation has to not crash on it)
  • stub GetDlgItemTextA to hand back my candidate serial, and MessageBoxA to capture the verdict
  • drive the dialog procedure directly with a synthetic "button pressed" message instead of running a real message loop

This runs the genuine startup code too, so the seed is correct without me ever having to figure out its formula.

The progress oracle

The VM runs in constant time per character, so timing tells you nothing. But the outer comparison loop bails at the first wrong character and writes that index to a fixed global. That global is exactly "how many leading characters are correct", which is all a character-by-character brute force needs:

for pos in range(24):
    for ch in printable:              # 0x20..0x7e
        serial[pos] = ch
        prog, ok = run(serial)
        if ok: break
        if prog > best: best, keep = prog, ch
    serial[pos] = keep

24 positions, about 95 candidates each, one emulator run per try. A few minutes, fully deterministic, no guessing:

Dyn4m1c_0nly_LYKN_2026!!

The flag is a wink at the lesson: the static reference was broken, and solving it meant going dynamic. When a challenge hands you a reimplementation, the reimplementation can lie. The real binary can't.

📂 Full writeup with the Unicorn oracle and the brute force: ctf-writeups/reverse/…/cr4ck 3

Thanks for reading! Questions or corrections? Ping me on GitHub.

Read more

all posts →