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{...}
The binary is a statically-linked, stripped x86-64 ELF (~680 KB). Following the workflow: first a lightweight overview, then a Ghidra dump.
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 complete. Now finding main and the cipher logic — the prompt strings (seal> at 0x47c9c6) are the anchor.
The user-facing logic lives in 0x401660 (likely main).
main is fully recovered. The algorithm:
- Build a 256-byte S-box at
0x4aa340from constants at0x47c020.., then Fisher–Yates shuffle it with a fixed-seed LCG (s = s*0x19660d + 0x3c6ef35f, seed at0x4a80d0). - Fill a key area from
0x4aa2e0with more LCG bytes — 5×16 round keys + a 16-byte final XOR key at0x4aa330. - 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 permutationdst[(3+7i)%16] = src[i], finally XOR with the key at0x4aa330. - Compare against six hardcoded qwords.
Let me verify the exact loop semantics in the disassembly, and check the .acgseal section.
.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.
The disassembly confirms everything:
- S-box built at
0x4aa340..0x4aa43f(SIMD from constants at0x47c020..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 at0x4aa330). - Encryption: only the first 48 bytes of the input (3 blocks), 5 rounds of
SBOX[b ^ K_r]+ permutationtmp[(3+7k)&0xf] = b[k], then XOR0x4aa330, compare to the.acgsealvalues.
Rather than hand-decode the SIMD S-box generator, I'll extract ground truth at runtime: break right after init and dump the tables.
gdb is available. Dumping the initialized tables.
Tables dumped (352 bytes = 96 key bytes + 256-byte S-box). Now implementing the inverse cipher in Python and decrypting the .acgseal target.
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:
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:
- Key schedule (deterministic). Builds a 256-byte S-box at
0x4aa340from constants at0x47c020, then Fisher–Yates-shuffles it with a fixed-seed LCG (seed = seed*0x19660d + 0x3c6ef35f, seed0x0005c5b3at0x4a80d0). The same LCG then fills 96 bytes at0x4aa2e0: five 16-byte round keys plus a final XOR key at0x4aa330. Because the seed is hardcoded, the whole key material is identical every run. - 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 permutationtmp[(3+7k) % 16] = b[k]; afterwards a final XOR with0x4aa330. ("Five rounds, every round looks the same.") - Check. The ciphertext is compared against 6 hardcoded qwords — the same 48 bytes that sit in the custom
.acgsealsection.
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.
