PP{y0u_4r3_7h3_5rv3r_n0w::LEKgDiYHMyGN}
Three flags, three independent breaks of a PIR-backed password manager — every one at the integration layer, never the (genuinely sound) crypto.
Summary
A "privacy-preserving" password manager: a Flask app (:8081) that generates diceware
passphrases by fetching each word from a separate Rust single-server PIR service
(:8080). Three independent bugs, one per flag.
(warmup)
POST /reset_passwordtakes the wordlist URL straight from the request body. That URL is where the app is supposed to fetch words, so the attacker becomes the PIR server. In the InsPIR/Paillier scheme the server homomorphically combines the client's one-hot ciphertexts; because we know the client's public modulusnwe can fabricate ciphertexts that the client'sextractdecrypts to any word we like. The app then stores that word as the user's main password → we can set the password of any user exceptFlagUserand log in.(user) The wordlist server never deletes its per-request files and serves its whole root (which contains
tmp/) statically —GET /tmp/leaks every PIR query ever made, including the six used to buildFlagUser's password. The app also gives us a Paillier decryption (/reset_passwordstores the decrypted plaintext in an entry we can read). One call decrypts a whole batch at once, because Paillier decryption is a group homomorphism:D(∏ ct_i^{w_i}) = Σ w_i·D(ct_i). Choosingw_i = (0x30+pos_i)·256^ipacks the recovered one-hot positions into 24 ASCII bytes.(admin)
Flask'sSECRET_KEYis the admin diceware passphrase (generate_password(CLIENT_ADMIN, …)).POST /_app_keyruns the same generation with our wordlist URL and throws the plaintext away — butlook_up_wordaborts the whole loop on the first word whose decrypted bytes are not valid UTF-8 (.decode()raises). Replyingct_j · E(0x7f)decrypts to0x7f(valid) or0x80(invalid UTF-8), so the number of POSTs we receive equalshot_index + 1— a decryption oracle for the admin key. 24 calls → 6 words → forge a Flask session withis_admin=True→GET /flag.
The underlying PIR scheme itself is sound; every break is at the integration layer
(attacker-controlled wordlist URL, static file server exposing tmp/, discarded plaintext
- a decode-error oracle).
Solution / Exploit
Exploit: diceware_exploit.py (needs --web, --wl, --listen-port,
--callback-url — the URL the challenge container can reach you on).
1python3 diceware_exploit.py \
2 --web http://TARGET:8081 --wl http://TARGET:8080 \
3 --listen-port 9090 --callback-url https://my-tunnel.example.com
0. The target
web/app/diceware.py:
1def generate_password(client_name, wordlist):
2 words = [look_up_word(client_name, [secrets.choice(DICE) for _ in range(DICE_COUNT)], wordlist).decode()
3 for _ in range(PASSPHRASE_LENGTH)]
4 return ' '.join(words)
PASSPHRASE_LENGTH = 6, DICE_COUNT = 4, dice ∈ {1..6}. look_up_word shells out to
inspire query <client.bin> /dev/stdout d0-1 d1-1 d2-1 d3-1 to produce a postcard-
serialized Paillier one-hot query, POSTs it to wordlist, and pipes the response back
through inspire extract, which decrypts and returns the word. generate_client makes one
2048-bit Paillier keypair per client (admin, users).
1. Warmup — be the PIR server
The one-hot query is 4 selectors of length 6; selector s contains 6 ciphertexts, the
roll-1-th of which encrypts 1, the rest 0. The server is supposed to reply with
∑_s c_{s,hot} (the plaintext of its DB slot). Paillier is additively homomorphic with
g = n+1, so E(x) = E(1)^x mod n². We have n from the query, and multiplying the six
ciphertexts of a selector gives E(1) for that selector. Therefore:
1E1 = prod(selectors[0]) % n2 # == E(1)
2cts = [pow(E1, 1, n2)]*7 + [pow(E1, t, n2)] # decode() -> plaintext t
inspire extract decodes these 8 ciphertexts into the integer t, which becomes the word
bytes. So we reply with 8 ciphertexts that turn into any chosen string.
/reset_password accepts the wordlist URL and calls generate_password(CLIENT_USERS, url)
— six words, all from our server. We return "pwnednow" six times, so the stored main
password is "pwnednow pwnednow pwnednow pwnednow pwnednow pwnednow". It refuses
username == "FlagUser" (403), but "Warmup User" is fair game. Log in with the
known password → the warmup flag is in the warmup user's entries.
2. User — leak tmp/, then one-shot decrypt the batch
wordlist_server/src/main.rs writes every query to tmp/<8rand>.query and never unlinks
it, and it serves the whole root statically:
actix_files::Files::new("/", ¶ms.root)
.show_files_listing() // /tmp/ is listable
.use_hidden_files() // dotfiles too
root is . = /var/www, which contains tmp/. So:
1curl http://TARGET:8080/tmp/ | grep -o '/tmp/[a-z0-9]*\.query'
gives every PIR query ever made — group them by modulus n (each client has its own key).
FlagUser's password was generated with the users client, so its 6 queries are right
there.
Now the decryption oracle: /reset_password accepts a wordlist URL, decrypts into a
value, and stores it in our own entry list, which we can read:
1app.reset_password(app.user, {"kind": "decrypt", "ct": c})
2digits = re.findall(r"New main password from[^<]*</b>: <code>(.*?)</code>", app.entries())
inspire extract decrypts with the users client key. Decryption is a group
homomorphism, so feeding it ∏ ct_i^{w_i} yields Σ w_i·D(ct_i). Each query's 6
ciphertexts are the one-hot vector for that word; its plaintext is 1 at the hot slot. To
learn all four digits of a word at once we weight slot i of selector s of query q by
(0x30 + i)·256^(4q+s). The sum then is a 24-byte ASCII string
"dddddddd…" where each group of 4 chars is a word's dice rolls:
1c = 1
2for q,(name,sel,ts) in enumerate(user_q[:6]):
3 for s in range(len(sel)):
4 for i,ct in enumerate(sel[s]):
5 c = c * pow(ct, (0x30+i) * (256 ** (4*q+s)), n2) % n2
6app.reset_password(app.user, {"kind":"decrypt","ct":c})
Decode digits → 6 words (via index = d0*216 + d1*36 + d2*6 + d3 into
eff_short_wordlist_1.txt) → FlagUser's password. The 6-word order is ambiguous
(Last-Modified has 1-second resolution, so several queries share a timestamp), so we try
the recovered order then all 6! = 720 permutations until /login as FlagUser
succeeds.
3. Admin — turn "throw the key away" into a key oracle
app.py:
1@app.post('/_app_key')
2def _WIP_app_key():
3 generate_password(CLIENT_ADMIN, str(request.form.get('wordlist', DEFAULT_WORDLIST)))
4 raise NotImplementedError("changing the app key not implemented")
SECRET_KEY was set at boot to the admin passphrase. /_app_key regenerates it with
our URL and discards the plaintext — but generate_password aborts on the first word whose
extract output fails bytes.decode() (invalid UTF-8), and we control the decrypted bytes.
Reply ct_j · E(0x7f) so the plaintext is 0x7f (valid ASCII) or 0x80 (invalid UTF-8),
and the loop stops at the hot word:
1ct = (leaked_ct_for_slot_j * pow(E1, 0x7f, n2)) % n2
2cts = encode_decrypt(n2, n, E1, ct) # decode() -> 0x7f + (0 if cold, 1 if hot)
The number of POSTs we receive before the connection dies equals hot_index + 1, i.e. the
dice value of that position. 24 calls (4 dice positions × 6 words) recover the entire
passphrase word-by-word — again with one permutation check, this time via the flag:
1ck = forge_session(" ".join(cand), {"user_name": "admin", "is_admin": True})
2requests.get(WEB + "/flag", cookies={"session": ck})
Flask signs its session cookie with URLSafeTimedSerializer(SECRET_KEY, salt="cookie-session", signer_kwargs={"key_derivation":"hmac","digest_method":hashlib.sha1}) — is_admin=True
gets us the admin flag.
Flags
PP{y0u_4r3_7h3_5rv3r_n0w::LEKgDiYHMyGN} # warmup
PP{k3y_r3u53_41l0wS_r3sp0ns3_r3u5e::JsvKvFPyfnuK} # user
PP{g00d_r34ct10n_71m3::IvJY5DkQH3VN} # admin
Notes / Pitfalls
FlagUseris the one user you cannot reset (reset_password403s on it) — that is precisely why the user flag needs thetmp/leak + decryption oracle instead of the warmup trick.- Query-format decoding. The query is
postcard-serialized: a varint modulus, a varint count of selectors, each a varint length then varint-limbBigUints (32-bit limbs). The exploit re-implementsrd_varint/rd_biguint/wr_biguintand theResponse::Okframing (0⇒ Ok, thenlen, then each ciphertext). encode_decrypt. To makedecode()evaluateD(ct), pass ciphertextsE(1)^{A}andE(1)^{B}at the two slots wheredecodesplits a ciphertext intoA = ct mod n,B = ct // n mod n— matching the InsPIR decomposition of product ciphertexts.- Word ordering is not recoverable from the leak.
use_last_modified(true)gives 1-second mtime resolution, so ties are common; brute the ≤720 permutations and let the login (or the/flagfetch) confirm. Picking the password from the entries page rather than assuming order saves a lot of grief. - Rate limiting on the wordlist server (
--rate-interval 60 --rate-burst 20): the admin stage makes4·6 = 24/reset-style calls. Batch/reuse a connection and expect occasional429s; retry rather than assume the oracle misread. - Everything is per-client. Group leaked queries by modulus, not by filename; the
usersandadminclients have distinct keys and must not be mixed. - The PIR crypto (
inspire/src/{pir,pallier}.rs) is genuinely a correct InsPIR/Paillier implementation — unlike the challenger's claim that "the database server can be fully untrusted", the client trusting the server's URL and the file server exposingtmp/are what broke it.