ORIKES dead code decrypts a QR codename via Unicorn brute force

rev
flag L3m0n{44b23d1aa03f4d10db66b82e0f683761}

A raylib game: bossfight, plus assets and a bundled libraylib.so. The brief is one Sekiro line - "Hesitation Is Defeat!!!" - and the boss fight itself is a Gyoubu reskin. Buried in the dialogue table is the actual hint: "Look Close Shinobi, You might learn something you need."

Hint

If the binary contains a full AES S-box and inverse S-box, something in it decrypts data - the question is what ever calls it.

A decryptor nobody calls

The usual passes (PNG chunks, zsteg, trailing data after assets) all come back clean. strings turns up dialogue and raylib noise, but .rodata holds a complete AES S-box and inverse S-box. Disassembling around it finds a textbook tiny-AES implementation (KeyExpansion, InvShiftRows, InvSubBytes, InvMixColumns) with a clear call chain: a key derivation function, a blob-assembly function, and the AES decrypt itself.

Insight

None of those four functions - the decrypt driver, the key mixer, or either blob-assembly helper - are ever called from anywhere in the binary. No direct call, no relocation, no function-pointer table entry. The whole decryption path is dead code. main only ever draws a mangled string. The challenge is to run that unreachable code yourself.

Reassembling the ciphertext

The blob-assembly function walks a linked list (24-byte nodes: data pointer, length, padding, next pointer) rooted in .data.rel.ro. Four nodes, lengths 13+13+13+12 = 51 bytes, concatenated in list order spell "aes" followed by exactly 3 AES blocks (48 bytes) - which also satisfies the decryptor's own length sanity check (len & 0xf == 3).

Pitfall

The chunks are deliberately cut across 16-byte .rodata slot boundaries, and several individual slots happen to start with the "aes" tag themselves. Reading each 16-byte slot as its own standalone ciphertext produces a buffer with stray "aes" sitting in the middle of a block - plausible-looking garbage. The linked list order is the only authority on how the pieces actually concatenate.

The key comes from a 32-bit integer run through a small mixer:

c
1a1 = rol32(k, 7) + 0x13579bdf;
2a0 = k ^ 0x6d3a91c5;
3t  = k ^ a1;
4a2 = ror32(t, 19) ^ 0xa5c31e27;
5a3 = (a0 + a2) ^ ror32(a1, 15);

A decoy clue, confirmed as a decoy

When the boss dies, main draws an altered version of a real Sekiro quote, with extra characters spliced in: " MHgyMjIw", which base64-decodes to 0x2220. Tempting - it looks like the seed. But 0x2220 is actually the PLT stub address for IsKeyDown, and running the mixer on it decrypts the blob to pure noise. It confirms "look closely at this string" as a direction, nothing more.

Brute-forcing the real 32-bit key

With the decoy ruled out, the seed space is just 32 bits - small enough for a straight C/OpenSSL brute force (24 threads, decrypt the first block, check for a printable or L3m0n{ prefix), landing in about 2.5 minutes:

output
HIT k=91cecbb4 (2446248884) : L3m0n{44b23d1aa03f4d10db66b82e0f683761}
AES key   715af4fc2776bdfa497371d2c0382a23
plaintext "L3m0n{44b23d1aa03f4d10db66b82e0f683761}" + 9x0x09 PKCS#7 pad
output
L3m0n{44b23d1aa03f4d10db66b82e0f683761}

Note

Verification ran the binary's own machine code under Unicorn rather than reimplementing AES - mapping the real PT_LOAD segments and directly calling the key-mixer, blob-assembler, and decrypt functions in place. Because the decrypt routine NUL-terminates right where the PKCS#7 pad begins, only after validating that pad, seeing a clean 0x00 followed by eight 0x09 bytes in the output is itself proof the padding checked out - not just a side effect of string printing.