d4rk{w3_br0ught_0urs3lv3s_h3r3_7ars}c0de
A 300-point reverse of a distributed raymarcher: the flag lives in the server's signed-distance field, and the WASM client scrambles every query so you can never see it directly.
Summary
The "game" is a distributed raymarcher. client.wasm (4241 bytes) walks rays in the
browser and asks the server for the scene's distance at each point — the server holds the
scene. The flag is a 3D-extruded text card inside that server-side distance field, at
x≈0…134, y≈-2…2, z≈0. The client can never show it plainly because it truncates every
coordinate to a period of 8 world units before sending it, so the text card gets tiled into
a scrambled "pattern" that looks like a fractal sponge (the challenge's "secrets behind its
patterns"). The solve is to reverse the wasm, learn the uplink framing (plaintext count +
XOR-scrambled points), then talk to the server directly with full-range coordinates to read
the un-tiled object.
Live target: https://<target>
Solution / Exploit
1. Recon
GET /→ pagestad1a-3d,<canvas width=128 height=128>, loadsglue.js.GET /glue.js→ instantiatesclient.wasm, opensws://host/ws, forwards server frames toon_frame, drivestick()on rAF, key presses →on_key(code).GET /client.wasm→ 4241 bytes.
Route fuzz (ffuf, ~73 paths): only /, /glue.js, /client.wasm, /ws exist.
2. Reversing client.wasm
wasm-objdump -x / wasm-decompile / wasm2wat.
- Imports:
env.present,env.ws_send,env.js_cos,env.js_sin. - Exports:
rx_buf, on_frame, on_key, progress, init, tick. - One data segment:
Z\xd1 7\xc4at0x10000— a 4-byte XOR key.
Key memory layout (byte addresses, from the .wat):
| address | contents |
|---|---|
0x10000 |
4-byte XOR key 5a d1 37 c4 |
0x18030 / 0x18034 / 0x18038 / 0x1803c |
throttle / state / count / iteration |
0x10010 |
rx buffer (server frames) |
0x98010 |
object-id list (uint16) |
0x67F20 |
per-object positions (12 floats each) |
0x98040 |
framebuffer base (128×128×4 RGBA) |
0xA80E0 |
saved camera poses (32 slots × 24 B) + saved frame snapshots |
Uplink framing (f_g): ws_send(0x2A80B0, 6*count+2).
Frame = [count:int16LE, PLAINTEXT] followed by 6*count bytes = count × (x,y,z):int16LE,
XOR'd with the 4-byte key 5a d1 37 c4 (payload only; the count is cleartext).
The truncation bug (f_g, per coordinate):
v = (floor(p*0.125 + 0.5) * -8.0 + p) * 128.0 // = 128 * (p - 8*round(p/8))
i.e. the client sends p mod 8 (a 128-units-per-world-unit fixed point in [-512,512]). The
client can therefore only ever sample one 8×8×8 periodic cell — that is the tiling that hides
the flag.
Downlink (on_frame): len == 2*count; each int16 = round(distance * 128) at the
corresponding query point. The client colours with d/128; it is otherwise a pure SDF .
3. Talking to the oracle
Frame = writeUInt16LE(count) ++ xor(6*count bytes of int16 xyz). Any valid frame gets a
reply of 2*count bytes (XOR'd with the same key). Raw probes:
pt [0,0,0] -> 102 (d = 0.797)
pt [1,2,3]*128 -> 77 (d = 0.602)
pt [0.5,.5,.5] -> 38 (d = 0.297)
So d = reply/128 (world units), clamped to int16. A len not of the form 2*count is dropped.
4. Reading the scene
2D slice scans of the field (ops/rect.js, ops/scan2.js) render sign/|d| as pixels.
- Slices through
z≈0show a rounded-rectangle "card" spanningx≈0…134, y≈-2…2. - The caption is extruded 3D text.
ops/sdf/full_xy.png(x=-20…145, y=-18…18, z=0) shows it in full; flip it vertically (full_xy_flipv.png) because the render maps+ydownward.- High-res halves:
ops/sdf/half1_xy_fv.png,ops/sdf/half2_xy_fv.png.
Read off the card: d4rk{ w3_br0ught_0urs3lv3s_h3r3_7ars } c0de
- half1:
d4rk{w3_br0ught_0urs - half2:
s3lv3s_h3r3_7ars}c0de
Volume checks (ops/sdf/xz_y0_fv.png, yz_x60_fv.png, extent line-scan to x=255) confirm
this is the only object; nothing follows c0de, and there is no second text line.
5. Proof images
ops/sdf/full_xy.png (flip vertically) / half1_xy_fv.png + half2_xy_fv.png.
Flag(s)
d4rk{w3_br0ught_0urs3lv3s_h3r3_7ars}
Alternates
- The literal 3D text line inside the server-side scene reads
d4rk{w3_br0ught_0urs3lv3s_h3r3_7ars}c0de— the trailingc0desits after the closing}and reads as the author/handler tag (d4rk+ flag +c0de⇒ "d4rkc0de"). The glyph order in the SDF clearly shows the}beforec0de. If the platform rejects the brace-delimited form, the only non-guessed alternative is the full literal with the tag inside the braces.
Notes / Pitfalls
- The client is not the game. All the scene data lives server-side; the wasm is just a
ray-walker plus an oracle client. Attacking the client alone gets you nothing — you must talk
to
/wsdirectly. - The
p mod 8truncation is the whole trick. It is what turns the flag card into a fractal-sponge "pattern". Reversing it means sending full-range coordinates instead of the truncated ones. - Only the payload is encrypted. The
countfield is cleartext; only the6*countbytes of int16 coordinates are XOR'd with5a d1 37 c4. - Frame length is a filter. A reply whose length is not
2*countis dropped by the client — useful for sanity-checking your own oracle client. - Flip vertically when reading slices. The render maps
+ydownward, so the flag card appears upside-down until you flip it (full_xy_flipv.png). - Exhaustive route fuzz found nothing else. ~73 paths probed; only
/,/glue.js,/client.wasm,/wsexist.