Operation Mirage triple-corrupted JPEG plus a polyglot ZIP

forensics
flag L3m0n{ch4m3l30n_v4ult_h34d3r_r3p41r_4nd_p0lygl0t_m4st3ry}

A 265,769-byte file that no parser will open - no image viewer, no file command, nothing. It's a JPEG with three defects baked in on purpose: the Start-Of-Image magic is punched out, the luma quantization table is zeroed, and the frame header claims half the real height. Repairing all three exposes a dossier panel, a damaged QR badge, and the exact key format for a ZIP hiding past the end of the image.

Hint

file classified.bin won't tell you what's wrong, only that something is. Walk the JPEG markers by hand.

1/6Step 1: fix the magic bytes

The first four bytes are DE AD BE EF where a JPEG wants FF D8 FF E0. Not corruption - a deliberate swap, and once it's patched back the marker walk runs clean: APP0, an APP2 labeled CHAMELEON_CIPHER, two DQT segments, and an SOF0 reporting 1280x360.

2/6Step 2: fix the quantization table

The luma DQT is 64 zero bytes declaring table id 5 - not a legal id at all, so nothing will decode until it's replaced. The scan data behind it turns out to have come from a flat (near-lossless) quantizer: every coefficient 1. Pasting in the standard JPEG table also "works" in the sense that it decodes, but leaves the panel text smeared and the QR unreadable.

3/6Step 3: fix the frame height

SOF0 claims height 360; the real picture is 720. Patching the height in the header reveals the lower half of the frame - the "beyond the frame" the description hints at.

The fully repaired 1280x720 frame: Operation Mirage dossier panel, damaged QR badge and the four-step access protocol

Restored frame after fixing the magic, the quantization table and the height.

4/6Step 4: read the auxiliary token

The APP2 marker's payload, XORed with 0x5A, decodes directly to a second secret:

output
sp3ctr4l_sh1ft_c4m0ufl4g3

5/6Step 5: repair and decode the QR badge

The badge is a 25x25 version-2 QR at 6 px/module, but all three 7x7 finder patterns are painted in as solid black squares, so no off-the- shelf QR detector locks onto it. Sampling the module grid by hand, writing the canonical finder pattern and separators back over the corners, and rendering it clean gives:

output
CODENAME: MIRAGE-PHANTOM-9472

Left: the QR badge as shipped with three solid black finder squares. Right: the same modules with canonical finder patterns rewritten, which decodes

Badge before and after the finder patterns are rebuilt.

6/6Step 6: open the appended vault

1552 bytes sit after the real End-Of-Image marker. Its ZIP local-file headers carry a mutated signature, 43 4D 03 04 where 50 4B 03 04 (PK\x03\x04) should be, and the whole blob is XORed with a repeating key - the scanned codename. De-XOR it and the mutated signature resolves into a normal ZIP: two ZipCrypto-encrypted entries, flag.txt and a manifest log. The password is <CODENAME>#<AUX_TOKEN>:

output
MIRAGE-PHANTOM-9472#sp3ctr4l_sh1ft_c4m0ufl4g3

Insight

The restored dossier panel - found only after grinding through the file the hard way - spells out the exact chain used above:

output
1. SECURITY BADGE: Tactical matrix damaged. Reconstruct standard 7x7 finder squares
   on all 3 corners (outer: 7x7, inner: 5x5 white, core: 3x3 black) to scan Codename.
2. VAULT MASTER KEY: Formatted as: <SCANNED_CODENAME>#<AUX_TOKEN>
3. AUXILIARY TOKEN: Encrypted stream stored inside JPEG APP2 marker.
   Decryption cipher: byte ^ 0x5A.
4. EXFILTRATION VAULT: Container appended past JPEG End-Of-Image (0xFFD9).
   De-obfuscation key: Repeating XOR using <SCANNED_CODENAME>.
[!] WARNING: Automated scanners (binwalk/strings) will fail due to polyglot masking.

Reading the panel first would have saved most of the work - but finding it required repairing the JPEG far enough to see it, which is itself most of the challenge.

Pitfall

With the standard JPEG quantization table instead of the flat one, the QR still "renders" - just wrong. It produces confident-looking near-miss reads like CODB05M6RHMIRAI%OMHANTOM-9J+J, close enough to the real codename that it's tempting to start guessing characters or trying fuzzy matches on it. It's garbage; the fix is the correct quantization table, not a smarter reader.

Also: don't brute-force the vault password before reading the panel. Rockyou was thrown at this archive early, which was never going to work

  • the password is a 44-character mixed-case token with underscores and a #, built from two pieces that only exist once you've actually repaired the image.
Show the full solve script
python
1import io, zipfile, numpy as np, cv2, zxingcpp
2from PIL import Image
3
4SRC = 'classified.bin'
5raw = open(SRC, 'rb').read()
6
7# 1. SOI magic disguised as DE AD BE EF
8buf = bytearray(raw)
9buf[0:4] = bytes([0xFF, 0xD8, 0xFF, 0xE0])
10
11# 2. luma DQT is zeroed and declares an invalid table id. The scan data came from a
12#    flat (near-lossless) quantiser, so only a flat table decodes cleanly.
13i = 2; n = 0
14while i < len(buf) - 1:
15    m = buf[i+1]
16    if m == 0xDA: break
17    L = int.from_bytes(buf[i+2:i+4], 'big')
18    if m == 0xDB:
19        payload = bytes([0x00 if n == 0 else 0x01]) + bytes([1] * 64)
20        seg = b'\xff\xdb' + (len(payload) + 2).to_bytes(2, 'big') + payload
21        buf[i:i+2+L] = seg; i += len(seg); n += 1; continue
22    if m == 0xC0:                       # 3. SOF0 says 360, real is 720
23        buf[i+5:i+7] = (720).to_bytes(2, 'big')
24    i += 2 + L
25img = np.array(Image.open(io.BytesIO(bytes(buf))).convert('RGB'))
26
27# 4. auxiliary token: APP2 "CHAMELEON_CIPHER", XOR 0x5A
28seg = buf[20:20+2+44]
29payload = seg[seg.index(b':')+1:]
30token = ''.join(chr(c ^ 0x5A) for c in payload)
31
32# 5. QR badge: the three 7x7 finder patterns are painted solid black. Sample a
33#    25x25 grid (ver-2 QR, 6 px/module), restore finders and separators, decode.
34N, X0, Y0, W = 25, 88, 428, 150
35FIND = np.array([[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,1,1,1,0,1],[1,0,1,1,1,0,1],
36                 [1,0,1,1,1,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]], np.uint8)
37
38def repair(A):
39    A = A.copy()
40    A[0:7,0:7] = FIND; A[0:7,N-7:N] = FIND; A[N-7:N,0:7] = FIND
41    A[7,0:8] = 0; A[7,N-8:N] = 0; A[0:8,7] = 0
42    A[N-8:N,7] = 0; A[N-8,0:8] = 0; A[0:8,N-8] = 0
43    return A
44
45def render(M, scale=8, quiet=4):
46    out = np.ones(((N+2*quiet)*scale,)*2, np.uint8) * 255
47    for r in range(N):
48        for c in range(N):
49            if M[r,c]:
50                out[(quiet+r)*scale:(quiet+r+1)*scale,
51                    (quiet+c)*scale:(quiet+c+1)*scale] = 0
52    return out
53
54def sample(ch, ox, oy, frac=0.34):
55    m = W / N; V = np.zeros((N,N), np.float32)
56    for r in range(N):
57        for c in range(N):
58            cx = X0 + ox + c*m + m/2; cy = Y0 + oy + r*m + m/2
59            x0 = int(round(cx - m*frac)); x1 = max(x0+1, int(round(cx + m*frac)))
60            y0 = int(round(cy - m*frac)); y1 = max(y0+1, int(round(cy + m*frac)))
61            V[r,c] = ch[y0:y1, x0:x1].mean()
62    return V
63
64codename = None
65for ch in (cv2.GaussianBlur(img[:,:,2].astype(np.float32), (0,0), 0.8),
66           cv2.cvtColor(img, cv2.COLOR_RGB2GRAY).astype(np.float32)):
67    for oi in range(7):
68        for oj in range(7):
69            V = sample(ch, oi*0.25, oj*0.25)
70            res = zxingcpp.read_barcodes(render(repair((V < 128).astype(np.uint8))),
71                                          formats=zxingcpp.BarcodeFormat.QRCode,
72                                          is_pure=True, return_errors=True)
73            for x in (res or []):
74                if x.valid:
75                    codename = x.text; break
76            if codename: break
77        if codename: break
78    if codename: break
79value = codename.split(':', 1)[1].strip() if ':' in codename else codename
80
81# 6. polyglot vault: bytes past EOI, XOR with the codename, ZipCrypto password
82blob = raw[raw.rfind(b'\xff\xd9')+2:]
83key = value.encode()
84plain = bytes(b ^ key[i % len(key)] for i, b in enumerate(blob))
85zf = zipfile.ZipFile(io.BytesIO(plain))
86pwd = f'{value}#{token}'.encode()
87print('FLAG:', zf.read('flag.txt', pwd=pwd).decode().strip())