Pwn • 250 points (Dynamic Decay) • Medium
DYNAMIC SCORING Current: 250 pts Range: 250 pts → 100 pts • Solves: 0 Only the compiled checker survived. The decompilers you know do not like it. Challenge Artifacts: gatekeeper.cpython-312.pyc Submit Flag* CTF{...}
Python 3.12 hash-based pyc, 1754 bytes. Let me check the sandbox's Python and unmarshal it.
Python 3.13 only — the pyc is 3.12. Let me try unmarshalling the code object directly (3.12 vs 3.13 marshal code-object layout is compatible) and check if pip/network works for proper tooling.
marshal.loads works cross-version. Now let me get a real Python 3.12 for correct opcode interpretation (3.12 vs 3.13 opcode tables differ).
Clean disassembly. _q is a generator. Let me see the full listing.
Full logic recovered. Reconstructing:
def _q(_a): # LCG keystream generator
_b = 1477
for _ in range(_a):
_b = (_b * 1103515245 + 12345) & 2147483647
yield (_b >> 16) & 255
def _r(_s):
if _s.translate({i: i ^ 1 for i in range(128)}) == 'B@BUGzu2ru^l1e2^5mv5xr^r5xr^x2r|':
return 2 # decoy: "accepted (test mode)"
_t = bytes(_x ^ 165 for _x in b'\x91$\xe5t\n\xd4o\xa4\xf2\xa4\xde\x01\x89\xbb,\x19\xb3?\xd6\xa6`\xb6\x9d,M\xfb\x9b$r\x16\x8aw\xe9\xe6')
if len(_s) != len(_t): return 0
for _i, (_c, _k) in enumerate(zip(_s, _q(len(_s)))):
if ((ord(_c) ^ _k) * 29 + _i * _i) % 251 != _t[_i]: return 0
return 1 # real "accepted"
Two checks: a translate(xor 1) decoy, and the real per-character equation. Since gcd(29,251)=1, each char is invertible. Let me solve both and verify against the binary itself.`
Both candidates recovered. Now verify against the actual checker binary:
Solved. ✅
Flag: CTF{d1s4ss3mbl3d_n0t_d3c0mp1l3d} (the binary literally prints accepted for CACTF{d1s4ss3mbl3d_n0t_d3c0mp1l3d} — if the platform wants the raw string, submit CACTF{d1s4ss3mbl3d_n0t_d3c0mp1l3d}).
How it went:
- Triage —
file: CPython 3.12 hash-based pyc. The sandbox only had 3.13, and the "decompilers you know" (uncompyle6/decompyle3) top out at 3.9/3.10 — that's why they choke, not because the bytecode is malformed. - Disassembly — installed Python 3.12.16 via
uv, thendis.dis(marshal.loads(data[16:]), depth=10)→ full listing indis312.txt. - Logic — the checker (
_q,_r) has two gates:- Decoy:
_s.translate({i: i^1 for i in range(128)}) == 'B@BUGzu2ru^l1e2^5mv5xr^r5xr^x2r|'→ returns 2 (accepted (test mode)). XOR is self-inverse, so that "flag" is just the string XOR-1:CACTF{t3st_m0d3_4lw4ys_s4ys_y3s}— a trap. - Real gate: with target
t = bytes(x ^ 165 for x in b'\x91$\xe5...')(34 bytes) and an LCG keystream (b=1477; b = (b*1103515245+12345) & 2^31-1; yield (b>>16)&255), each char must satisfy((ord(c) ^ k_i) * 29 + i²) % 251 == t[i]. Sincegcd(29,251)=1, invert withpow(29, -1, 251)→ord(c) = ((t[i] - i²)·29⁻¹ mod 251) ^ k_i.
- Decoy:
- Verification — ran the unmodified pyc under 3.12: real flag →
accepted, decoy →accepted (test mode), junk →rejected.
Full disassembly saved at dis312.txt.
