d4rk{JsFAaAaA_0bfu5c4710n_<3}
A 500-point forensics challenge — h4ckc0n's top tier — and a true nesting doll: Shamir shares, steghide, XZ, JSFuck and a custom byte cipher, each gating the next.
Summary
A single 18 MB Unsplash JPEG carries six Shamir shares in its metadata
(threshold 3, over GF(2^521-1)) plus a genuine steghide payload. The shares
reconstruct a 264-bit prime; the steghide password is the ROT13 of the photo id
in the filename. Inside the steghide payload is a four-layer stack — XZ → base64 →
JSFuck → obfuscated JavaScript — ending in a custom byte cipher whose key is
the reconstructed prime, supplied in decimal. Decrypting the 43-byte
ciphertext yields the flag.
Author paramveer504. Description: "Many may not know that not everything is
needed to make up something". Hints:
- H1: "A name turned halfway round the alphabet opens the room hidden inside the picture."
- H2: "Strip the coats one by one, but never strike the match; the last door wants a key before it speaks, the key is spoken by portions across the town."
Solution / Exploit
1. Recover the prime from the metadata shares
Seven 69-byte blobs are hidden across the JPEG's metadata, each behind a different
encoding. Six of them are Shamir shares (index byte + 66-byte value + 2-byte
sha256(idx || value)[:2] checksum, all validating); the 7th (APP15, index byte
0x46 = 'F') is not a share.
| segment | encoding | index |
|---|---|---|
APP1 XMP xmp:Label |
base64 | 1 |
| APP1 Exif UserComment (0x9286) | base85 | 2 |
APP12 (SHR\0) |
base32 | 3 |
APP11 (SHR\0) |
base36 | 5 |
| APP0/JFIF extra 69 bytes | raw | 6 |
bytes after FFD9 |
ascii85 | 7 |
APP15 (SHR\0) |
hex | 0x46 = 'F' (not a share) |
All seven decode to exactly 69 bytes — that shared length is the tell that they
belong together. Index 4 is deliberately absent ("not everything is needed"). The
COM segment at 0x59 (len 41) says "The Three Musketeers may find the prime" →
threshold 3. Lagrange interpolation at x=0 over Q = 2^521 - 1 from any
3 valid shares gives the same 264-bit prime:
dec: 21388077551557335503598707706588121040060001228422848505354972680588693352330213
hex: b8b606e6b8290b478f06ba56d316d3933b3dd6a369885c76975c6b622d8b59b3e5
The field modulus was proven, not assumed, by the gcd-of-consistency method:
the gcd of the Vandermonde/determinant consistency integers over 4+ shares is
exactly 2^521 - 1 (521 bits, prime) at threshold 3 and 4. Re-verification of the
blob decode reproduces:
idx1 XMP base64 len=69 idx=1 crc_ok=True
idx2 UserComment b85 len=69 idx=2 crc_ok=True
idx3 APP12 base32 len=69 idx=3 crc_ok=True
idx5 APP11 base36 len=69 idx=5 crc_ok=True
idx6 APP0 jfif raw len=69 idx=6 crc_ok=True
idx7 post-EOI a85 len=69 idx=7 crc_ok=True
idx70 APP15 hex len=69 idx=70 crc_ok=False <-- not a share
Lagrange f(0) over GF(2^521-1) for every 3-subset:
distinct secrets: 1
secret(hex) = b8b606e6b8290b478f06ba56d316d3933b3dd6a369885c76975c6b622d8b59b3e5
is prime? = True bits = 264
The 264-bit value sits in the low 66-byte window (the high bytes of the 66-byte pad are zero), consistent with a 521-bit field element.
2. Open the steghide payload (H1)
The image contains a genuine steghide payload (stegseek seed c6adb5de, ~389.3 KB
compressed, AES-128-CBC / rijndael-128). H1 says "a name turned halfway round
the alphabet" → ROT13 of the photo id in the filename
WAWyV76C3t8 → password JNJlI76P3g8 (the seed confirms
seed("JNJlI76P3g8") == c6adb5de):
1stegseek -q chall.jpg <(printf 'JNJlI76P3g8\n') out.bin
The payload is real, not noise: re-encoding the JPEG (which destroys steghide data)
and re-running --seed finds no seed across 4,294,855,000 seeds — the control.
3. Strip the remaining layers (H2: "strip the coats one by one")
1xz -dc out.bin > payload.bin # 398852 B -> 21,238,623 B ASCII
2# payload.bin = base64 (76-char lines) of a 15,722,097-byte JSFuck program (charset []()!+)
The JSFuck is Function("return eval")()( <inner> ); evaluating the inner
expression (with node, without running the slow full program) yields a 393 KB
javascript-obfuscator-style program. Deobfuscate it with npx webcrack. The
payload is a custom byte cipher: a splitmix64 keystream seeded by
xxhash64/ of the key, a Fisher-Yates S-box, per-byte round keys picking one
of {xor, add, rotate} in one of 6 orders, plus a 4-byte checksum.
1const cipherBytes = [126,120,134,76,92,84,146,16,121,17,151,240,230,181,137,153,166,146,210,58,
2 239,48,109,117,183,117,157,123,57,12,59,78,2,117,197,212,90,79,49,169,79,23,119];
3const playerKey = process.argv[2];
4const result = playerKey ? decryptPayload(cipherBytes, playerKey) : null;
5if (result === null) { console.error("wrong key"); process.exit(1); }
6console.log(result);
4. The last door's key (H2)
"the key is spoken by portions across the town" → the key is the prime
reconstructed from the shares, and it must be supplied in decimal (hex /
0x… / uppercase / the 'F' blob / the rot13 ids all fail the checksum):
1node payload_run.js 21388077551557335503598707706588121040060001228422848505354972680588693352330213
2FLAG = "d4rk{JsFAaAaA_0bfu5c4710n_<3}"
Complete solve script
faa_work-relative solve.py runs the whole chain (challenge JPEG → flag) in
~13 s. It parses the JPEG segments and validates share checksums, reconstructs the
prime by Lagrange interpolation mod 2^521-1, shells out to stegseek with the
ROT13 password, unwraps XZ → base64 → JSFuck (using node to evaluate the inner
expression), and re-implements the custom cipher in pure Python to decrypt the
43-byte ciphertext.
1python3 solve.py faa_work/chall-image/benjamin-chambon-WAWyV76C3t8-unsplash.jpg
The core of the script:
1Q = (1 << 521) - 1 # Mersenne prime 2^521-1 (proven by gcd-of-consistency)
2THRESHOLD = 3
3
4def recover_prime(jpg):
5 data = open(jpg, "rb").read()
6 segs = parse_segments(data)
7 shares = {}
8 for m, pl in segs:
9 try:
10 if m == 0xEB: v = _b32(pl[4:].decode()) # APP12 base32
11 elif m == 0xEC: v = _b36(pl[4:].decode()) # APP11 base36
12 elif m == 0xEF: continue # APP15 = 'F' blob, not a share
13 elif m == 0xE0: v = pl[14:] # JFIF extra 69 bytes (raw)
14 elif m == 0xE1 and pl.startswith(b"Exif"):
15 v = base64.b85decode(pl[pl.find(b"ASCII\x00\x00\x00") + 8:]) # UserComment base85
16 elif m == 0xE1:
17 v = base64.b64decode(re.search(rb"xmp:Label=\"([^\"]+)\"", pl).group(1)) # XMP base64
18 else: continue
19 except Exception: continue
20 if len(v) == 69 and hashlib.sha256(v[:67]).digest()[:2] == v[67:69]:
21 shares[v[0]] = int.from_bytes(v[1:67], "big") # checksum validated
22 tail = data[data.rfind(b"\xff\xd9") + 2:]
23 v = base64.a85decode(tail)
24 if len(v) == 69 and hashlib.sha256(v[:67]).digest()[:2] == v[67:69]:
25 shares[v[0]] = int.from_bytes(v[1:67], "big")
26 idx = sorted(shares)[:THRESHOLD]
27 secret = 0
28 for i, xi in enumerate(idx):
29 num = den = 1
30 for xj in idx:
31 if xj == xi: continue
32 num = num * (-xj) % Q
33 den = den * (xi - xj) % Q
34 secret = (secret + shares[xi] * num * pow(den, -1, Q)) % Q
35 return secret
36
37def extract_steg(jpg, out_xz):
38 password = "JNJlI76P3g8" # = ROT13("WAWyV76C3t8")
39 ...
40 subprocess.run(["stegseek", "-q", jpg, wl, out_xz], check=True)
41
42def jsfuck_to_obfuscated(jsfuck_path):
43 # JSFuck is: <Array.proto.at.constructor>("return eval")()( <INNER> )
44 # The last top-level call argument (INNER) evaluates to the obfuscated JS source.
45 ...
46 js = ("process.stdout.write(eval(require('fs').readFileSync(%r,'utf8')));" % tmp)
47 return subprocess.run(["node", "-e", js], capture_output=True, check=True).stdout
Actual output:
[1] prime (dec) = 21388077551557335503598707706588121040060001228422848505354972680588693352330213
[1] prime (hex) = b8b606e6b8290b478f06ba56d316d3933b3dd6a369885c76975c6b622d8b59b3e5
[2] steghide payload: 398852 bytes (XZ)
[3] xz -> base64 text: 21238623 bytes
[3] base64 -> JSFuck: 15722097 bytes
[3] JSFuck -> obfuscated JS: 393688 bytes
[4] flag: FLAG = "d4rk{JsFAaAaA_0bfu5c4710n_<3}"
Flag(s)
d4rk{JsFAaAaA_0bfu5c4710n_<3}
Notes / Pitfalls
- The prime is not the flag and not the steghide password. Confirmed with a
real
steghide extract. It is the key for the final cipher only, and only in decimal (hex /0x…/ upper / the0x46blob / the rot13 ids all return "wrong key"). stegseek --seeddoes not extract the payload — it only detects the seed. With steghide's default AES the password is still required (steghide derives the AES key from the passphrase), so seed ≠ key.- Validate the seed oracle against a long password. The whole password search
rested on
seed(pw) = XOR of the four little-endian uint32 of md5(pw). It was only trusted after an end-to-end embed test with a long hex password (steghide reportedab2e5048, matchingseed("<prime hex>")).seed('%x' % secret) == ab2e5048 != c6adb5de, i.e. the prime's hex form is not the password. - Never run the whole JSFuck. Executing the full program
evals the obfuscated JS and hangs for many minutes; extract and evaluate only the inner call argument. - The obfuscated payload is padded with ~370 KB of Lorem-ipsum as a decoy.
- The
0x46('F') blob is not a share. Its index byte is'F'(0x46) and its checksum (1040vs expected886f) does not fit the share scheme. It is the one thing that does not fit the Shamir set — but it is not the final key (the decimal prime is). - Do not assume the field. The modulus
2^521-1was established by gcd-of-consistency, not guessed.
Dead ends recorded in the source (do not re-run)
The notes document the long search before the two hints resolved it — recorded so nobody repeats it:
- Prime as the flag (
d4rk{21388077551557335503598707706588121040060001228422848505354972680588693352330213}and the hex form) — tried, wrong. - Prime as the steghide password in ~every representation: decimal, hex
(lower/upper/0x/zfill), base 2-62, base32/58/64/85/86, raw 33/32-byte big- and
, reversed, md5/sha1/sha224/sha256/sha384/sha512 of each, all
substrings, all ± affixes (FAA /
d4rk{}/prime/key=/ newline / NUL). - Wordlists: rockyou (14 M), darkc0de (1.47 M), Pwdb_top-1000000, rockyou-75, and themed musketeer lists (Athos/Porthos/Aramis/d'Artagnan, French forms, leet).
- Prime-keyed decryption of the
0x46blob: AES-CBC/ECB/CTR/CFB/OFB (128 & 256-bit), ChaCha20/Salsa20, a full AEAD authentication sweep (ChaCha20-Poly1305 + AES-GCM), RC4, repeating-XOR, OTP vsf(70), RSA mod q, GF(2^521-1) mul/div, degree-6 interpolation over all 7 points, PRNG keystreams — nothing authenticated. - Two-stage Shamir (reconstruct the prime, then interpolate again mod that
prime) — the same shares are not consistent mod q (
3-subsets mod q all equal? False). The recovered secret does not decode to ASCII directly, so there is a transform, not along_to_bytes. - The earlier attempt's correction: the krb5 keytab Brainfuck needs kvno-ascending concatenation.
Tools
python3 (stdlib: base64/hashlib/lzma/re/struct), stegseek 0.6, node v22,
npx webcrack.