program.bin
tongue

Stack Tongue Reverse Engineering • 350 points (Dynamic Decay) • Hard

DYNAMIC SCORING Current: 350 pts Range: 500 pts → 350 pts • Solves: 44 The gate controller does not check seals itself. It runs a small program that does. Challenge Artifacts: program.bin tongue Submit Flag*

Dr.Binary
run_sandbox
run_sandbox
inspect_binary
run_sandbox

The binary prompts for a "seal" and runs program.bin. Let me decompile the interpreter.

dump_data
run_sandbox
run_sandbox
run_sandbox
run_sandbox
read_file

The VM is clear. Now let me decode program.bin (STK1 magic, XOR with key stream k = 0xc3, k = k*5+0x3b) and disassemble it.

run_sandbox

37-byte seal, one constraint chain per position. Inverting each (XOR → ADD → ROL → [SUB] → target):

run_sandbox

All 37 constraints invert cleanly. Verifying against the real binary:

run_sandbox

Flag: CACTF{st4ck_t0ngu3_sp34ks_1n_r1ddl3s} — the binary prints accepted (exit 0).

How it worked

tongue (statically linked, stripped) is a tiny stack-VM interpreter, main at 0x401690:

  1. Loads program.bin (max 0x2000 bytes), requires magic STK1
  2. Decrypts bytes 4..N-1 with a keystream: k₀=0xc3, kₙ₊₁ = kₙ*5 + 0x3b (mod 256)
  3. Prompts seal> , reads 0x80 bytes via fgets, strips \n
  4. Interprets the program with a 256-byte stack at 0x4ac300, sp at 0x4ac2e0

Opcode set (failures set a flag but execution continues — 0xf0 prints accepted/rejected):

opmeaning
0x17 cpush constant
0x2c ipush seal[i & 0x7f]
0x63 rrotate top 8-bit left by r & 7
0x41 / 0x5e / 0x7aXOR / ADD / SUB (mod 256)
0x88 cpop, compare with constant (sets fail flag on mismatch)
0x9d ncompare strlen(seal) == n
0xf0END

program.dec (496 → 492 payload bytes) is a flat sequence of 37 independent constraint chains: CHECK len == 37, then per position push seal[i], xor c1, add c2, rol c3, optional sub c4, check == target — each index 0..36 appears exactly once.

Since each chain is invertible, I reversed every one: y = ror(target, c3), undo SUB, undo ADD, undo XOR — giving all 37 bytes in one pass, then verified every forward constraint and confirmed against the real binary.

niceee

Dr.Binary

Glad it landed! 🎉

Quick recap for the writeup if you want it:

  • VM spec: 8 opcodes, 256-byte stack, keystream-decrypted bytecode (STK1 header)
  • Crack: 37 independent invertible chains → solved in one Python pass, no brute force needed

The full disassembly of program.dec is in the transcript above if you want to archive it. Ping me for the next challenge.