Super Over APK native keystream cipher, decoys that fail their own check

rev
flag L3m0n{be2620774c296df4d9e77647edbca07d}

"A cricket score-validator Android app checks your submitted score code before declaring a Super Over win. The interesting part of that check isn't where you'd expect to find it." That sentence alone is worth reading twice - the check really isn't where the Java side suggests.

Hint

Two flag-shaped strings show up almost immediately, in two different places, agreeing with each other. That agreement is itself the clue that something's wrong with them.

Two matching decoys

classes3.dex has a QA_SELFTEST_REFERENCE constant, and libscorecheck.so has a "selftest=PASS ref=" log line - both carrying L3m0n{51deba110ffb0a7c1ea7edfacead0bed}. They agree with each other, which looks like confirmation, but running the shipped native nativeVerify function against that exact value returns 0 (reject). Two planted decoys that cross-reference each other is still just one coordinated decoy.

The real check lives in the native library

Java_com_l3m0nctf_superover_SuperOver_nativeVerify seeds a tiny xorshift32 PRNG:

asm
10xa40  mov  w10, #0x7c3a
20xa48  movk w10, #0x4b1d, lsl #16      ; seed = 0x4B1D7C3A
30xa50  eor  w10, w10, w10, lsl #13
40xa54  eor  w10, w10, w10, lsr #17
50xa58  eor  w10, w10, w10, lsl #5
60xa5c  lsr  w12, w10, #0x13            ; output byte = state >> 19

Insight

The actual check takes your 32-hex-character input, parses it as 16 bytes, and runs it through six rounds of: add a 16-byte keystream block, a byte-mixing pass (a[i] ^= rotl8(a[i-1], 3)), a 7-byte vector rotate (ext v0.16b, v0.16b, v0.16b, #7), then a second mixing pass (a[i] += rotl8(a[i+1], 5)). The result is compared against keystream[96:112] XOR .rodata[0:16] - two values baked into the binary itself, not derived from any user input. Every one of those six rounds is invertible, so this isn't a hash to brute-force; it's a cipher to run backwards.

python
1def rotl8(v, n):
2    return ((v << n) | (v >> (8 - n))) & 0xFF
3
4def mix_backward(a):
5    for i in range(16):                                   # undo the descending add
6        a[i] = (a[i] - rotl8(a[(i + 1) & 15], 5)) & 0xFF
7    a = bytearray(a[(i + 9) & 15] for i in range(16))       # undo the 7-byte rotate
8    for i in range(15, -1, -1):                             # undo the xor pass
9        a[i] ^= rotl8(a[(i - 1) & 15], 3)
10    return a
11
12def decrypt(target, ks):
13    a = bytearray(target)
14    for r in range(5, -1, -1):
15        a = mix_backward(a)
16        blk = ks[16 * r:16 * r + 16]
17        a = bytearray((a[i] - blk[i]) & 0xFF for i in range(16))
18    return bytes(a)
19
20target = bytes(ks[96 + i] ^ rod[i] for i in range(16))   # rod = .rodata[0:16]
21plain = decrypt(target, ks)
22print("L3m0n{%s}" % plain.hex())

Running the decrypt gives a unique 16-byte preimage whose hex encoding is the accepted score code:

output
L3m0n{be2620774c296df4d9e77647edbca07d}

Note

Confirmed by forward re-encrypting the recovered plaintext and checking it reproduces target exactly - and, more convincingly, by running the actual shipped arm64 function under Unicorn and checking it returns 1 for the recovered answer while returning 0 for the decoy, for all-zero input, and for two "close but wrong in the last nibble" near-misses. Emulating the real binary code beats reimplementing the algorithm and hoping it's faithful.