· 2 min read

CSAW26 Quals - nitro

The binary decrypts its own checker at runtime and reuses the decrypted bytes as the flag keystream. I solved it statically, so the anti-debug never ran.

Tagged: self-modifying-code, static-analysis, xor

Event
CSAW CTF Quals 2026
Category
rev

Summary

The binary decrypts its own secret_check function at runtime, then uses those decrypted bytes as the keystream for the flag. I solved it statically and never ran the binary, so the anti-debug never came into play.

Steps

1. Self-modifying code

main() calls mprotect on its own .enccode section to make it RWX, XORs 0x15e bytes at secret_check with the 8-byte repeating key 1337c0debaadf00d (symbol smc_key.0), and calls the result.

Doing the same XOR offline gives you the decrypted function.

2. Password

The decrypted secret_check builds the expected password on the stack one byte at a time with mov BYTE PTR [rbp+disp8], imm8, which is opcode c6 45 <disp8> <imm8>.

I regexed the decrypted bytes for that pattern, sorted by stack offset, and took the longest run of consecutive slots with printable values:

slots = sorted({d[0]: v[0] for d, v in re.findall(rb'\xc6\x45(.)(.)', dec, re.S)}.items())

That gives n2o_boost.

3. Flag keystream

The flag isn’t stored anywhere. It’s XORed with a keystream that indexes back into the decrypted code:

k_i = (dec[(7*i + 3) % 0x15e] + 5*i + 0x6b) mod 256
flag[i] = enc_flag[i] ^ k_i          # over 0x2f bytes

Note

Since the keystream comes from the decrypted code, you can’t just dump the flag at runtime without redoing the decryption step, and once you’ve redone it there’s no reason to run the binary at all.

Solver: solve.py

Challenge files

  • nitro
  • nitro.dec
  • nitro.dec_ghidra/
  • nitro.decomp.c
  • nitro_ghidra/
  • patch.py
  • secret.c
  • solve.py

Download the zip (26 files, 115 KB)