rounds

Reverse Engineering • 350 points (Static) • Medium

A contractor's homemade cipher protects the seal. It is only five rounds deep, but every round looks the same. Target: https://cyber-arena-2026.s3.ap-south-1.amazonaws.com/scs/binary/chall3/rounds Launch Target Submit Flag* CTF{...}

Dr.Binary
run_sandbox

The binary is a statically-linked, stripped x86-64 ELF (~680 KB). Following the workflow: first a lightweight overview, then a Ghidra dump.

inspect_binary

Key facts from triage:

  • Statically-linked glibc, stripped, no PIE, NX on — standard, not packed.
  • A custom section .acgseal (48 bytes) — almost certainly the encrypted seal/flag.
  • User-facing strings: seal> , accepted, rejected — matches the "homemade cipher, five rounds" story.

Proceeding to the Ghidra dump.

dump_data

Dump complete. Now finding main and the cipher logic — the prompt strings (seal> at 0x47c9c6) are the anchor.

run_sandbox
run_sandbox

The user-facing logic lives in 0x401660 (likely main).

read_file

main is fully recovered. The algorithm:

  1. Build a 256-byte S-box at 0x4aa340 from constants at 0x47c020.., then Fisher–Yates shuffle it with a fixed-seed LCG (s = s*0x19660d + 0x3c6ef35f, seed at 0x4a80d0).
  2. Fill a key area from 0x4aa2e0 with more LCG bytes — 5×16 round keys + a 16-byte final XOR key at 0x4aa330.
  3. Encrypt the 48-byte input in 4 blocks of 16: per round (5 rounds) b[i] = SBOX[b[i] ^ K_r[i]] then a byte permutation dst[(3+7i)%16] = src[i], finally XOR with the key at 0x4aa330.
  4. Compare against six hardcoded qwords.

Let me verify the exact loop semantics in the disassembly, and check the .acgseal section.

run_sandbox
run_sandbox

.acgseal holds exactly the 48 target bytes. The LCG seed at 0x4a80d0 is 0x0005c5b3 (fixed → deterministic S-box and keys). Now reading the full main disassembly to pin down each loop precisely.

read_file

The disassembly confirms everything:

  • S-box built at 0x4aa340..0x4aa43f (SIMD from constants at 0x47c020..0x47c07f), then Fisher–Yates shuffled with the fixed-seed LCG.
  • Key fill: 6×16 LCG bytes at 0x4aa2e0..0x4aa33f (5 round keys + final XOR key at 0x4aa330).
  • Encryption: only the first 48 bytes of the input (3 blocks), 5 rounds of SBOX[b ^ K_r] + permutation tmp[(3+7k)&0xf] = b[k], then XOR 0x4aa330, compare to the .acgseal values.

Rather than hand-decode the SIMD S-box generator, I'll extract ground truth at runtime: break right after init and dump the tables.

run_sandbox

gdb is available. Dumping the initialized tables.

run_sandbox

Tables dumped (352 bytes = 96 key bytes + 256-byte S-box). Now implementing the inverse cipher in Python and decrypting the .acgseal target.

write_file
run_sandbox

Decrypted plaintext: CACTF{sp_n3tw0rks_unw1nd_b4ckw4rd} (zero-padded to 48 bytes), and re-encryption reproduces the target exactly. Final verification against the real binary:

run_sandbox

Verified — the binary itself prints accepted.

Solution

Flag: CACTF{sp_n3tw0rks_unw1nd_b4ckw4rd}

How it works

rounds is a stripped, static x86-64 ELF. main (0x401660) does everything:

  1. Key schedule (deterministic). Builds a 256-byte S-box at 0x4aa340 from constants at 0x47c020, then Fisher–Yates-shuffles it with a fixed-seed LCG (seed = seed*0x19660d + 0x3c6ef35f, seed 0x0005c5b3 at 0x4a80d0). The same LCG then fills 96 bytes at 0x4aa2e0: five 16-byte round keys plus a final XOR key at 0x4aa330. Because the seed is hardcoded, the whole key material is identical every run.
  2. The cipher. The input is read with fgets, newline-stripped, zero-padded to 48 bytes, and encrypted as 3 blocks of 16. Per block, 5 identical rounds: b[i] = SBOX[b[i] ^ K_r[i]], then a fixed byte permutation tmp[(3+7k) % 16] = b[k]; afterwards a final XOR with 0x4aa330. ("Five rounds, every round looks the same.")
  3. Check. The ciphertext is compared against 6 hardcoded qwords — the same 48 bytes that sit in the custom .acgseal section.

Breaking it

Every step is a bijection (S-box is a permutation — asserted in solve.py — permutation and XOR are trivially invertible), so the cipher unwinds backwards exactly as the flag text hints. I broke at 0x4017ac under gdb and dumped 0x4aa2e0..0x4aa440 (round keys + shuffled S-box, tables.bin), then inverted the cipher in solve.py: un-XOR, then for rounds 4→0 un-permute and b[i] = SBOX⁻¹[b[i]] ^ K_r[i]. Re-encrypting the recovered plaintext reproduces the .acgseal bytes, and feeding the flag to the binary yields accepted.

Files: solve.py (cipher inversion), tables.bin (runtime key dump), answer.txt.