Can you login as an admin and get the flag?
tell me how to solve the challenege i have a nc connection to solve it against
Looking at the code now. Let me analyze the crypto and confirm my attack plan works by testing locally first.
The bugs I see:
encrypt_datauses a repeating 128-byte XOR key over a JSON token whose structure is almost entirely known plaintext → classic many-time-pad.- The token format is fixed:
{"session_id": "<64 hex>", "username": "<user>", "role": "user"}. With a 32-char username the plaintext is 146 bytes, so the tail wraps around the 128-byte key → we learn key[0..17] and key[80..127] exactly. - key[18..79] sits exactly over the random session_id — but every session_id byte is a hex char (16 options), so intersecting constraints from several logins pins every byte (statistically unique after ~4-8 logins).
- With the full key: decrypt our own token → learn a live session_id, re-encrypt
{"username": "admin", "role": "admin"}→ admin token →list_messagesshows the secret flag message.
Let me build and verify it:
Length mismatch — let me check the actual token structure locally:
146 is correct, so my script's interaction must be off. Let me debug the raw protocol:
Protocol is fine. Let me instrument solve.py to see what token it actually got:
Tokens decode to 114 bytes = empty username. Something in my interaction is off — let me trace it:
Registration works standalone, yet solve.py got empty-username tokens. Let me run solve.py with full I/O logging:
[object Object]
The trace shows correct interaction but tokens decode to 114 bytes. Let me measure precisely:
Token decodes to 114 bytes — a 32-char-username token should be 146. Let me instrument a local copy of the challenge to see the real plaintext:
Let me capture the debug line properly by redirecting stderr to a file:
The session_id is only 32 chars, not 64! Let me re-check the actual file on disk:
Found my error — os.urandom(16).hex() is 32 hex chars (2 per byte), not 64. So the token layout is:
0..15={"session_id": "→ key known16..47= 32-char random hex session_id → unknown key region (same hex-charset trick applies)48..63=", "username": "→ key known64..95= our 32-char username → key known96..113= tail → key known
Total 114 bytes with a 32-char username — no wrap needed. Let me fix the solver:
The statistical intersection converges slower than I estimated (hex ASCII chars cluster under XOR). Let me quantify how many logins are actually needed:
~60 logins → unique recovery in every trial. Updating the solver:
Found it — my candidate sets hold key bytes, but I used them directly as sid characters. The true sid char is t0[i] ^ k_i. Fixing:
It works locally — the forged admin token revealed the secret message. Let me verify reliability with two more runs and clean up:
Both runs succeeded. The solver is verified end-to-end against a local instance (3/3).
Yes — solved and verified. The solver is solve.py in the workspace (tested 3/3 against a local copy with a fake flag).
How the challenge breaks
The "encryption" is a repeating 128-byte XOR key over a JSON token whose format is completely predictable — a classic many-time-pad. Plus parse_token only validates that a claimed admin's username is in admins (and "admin" always is), so any well-forged admin token works.
Step 1 — Known plaintext from one login. Register a user named A×32 (max allowed length). Your token's plaintext is exactly:
offset 0..15 {"session_id": " → key[0..15]
offset 16..47 <32-char hex sid> (unknown — the only hidden part)
offset 48..63 ", "username": " → key[48..63]
offset 64..95 AAAAAAAAAAAA... → key[64..95] (we know our own username!)
offset 96..113 ", "role": "user"} → key[96..113]
So one login reveals 82 of the 114 key bytes the token touches.
Step 2 — Recover key[16..47] via the hex charset. Those bytes sit exactly over the random session_id, which you can't read yet — but every session_id byte is one of 16 hex characters. For each position the true key byte k must satisfy k ^ ciphertext[i] ∈ {0-9,a-f} for every token you collect. Intersecting that constraint across ~60 logins pins every byte (I simulated this: hex ASCII chars cluster under XOR, so a handful of tokens is not enough, but 60+ is deterministic — unique in 30/30 trials).
Step 3 — Forge an admin token. With the full key, decrypt your own token → you learn a still-valid session_id. Re-encrypt {"session_id": "<that sid>", "username": "admin", "role": "admin"} (only 87 bytes, touching only recovered key bytes) and use it with menu option 5 (List Messages) — the secret flag message from admin is printed.
Wrong sid guesses are harmless: the server just prints Session expired or invalid. and consumes nothing, so leftover ambiguous candidates can be enumerated safely.
Run it against your nc connection
pip install pwntools # if needed
python3 solve.py <host> <port>
(no args = attacks ./challenge.py locally with ./flag.txt). It registers the 32-char user, logs in ~60–120 times, recovers the key, forges the admin token, and prints the flag, e.g.:
Messages:
admin: The flag is: flag{...}
One tip: if the remote wraps the service with line buffering quirks, the prompts arrive the same way — the script already syncs on Enter your choice: , Enter username: etc., so it should work as-is.
can i have a writeup.md of th soultion
Done — writeup.md is in the workspace. It covers:
- Service analysis — what the token is and why admin's password doesn't matter
- The 4 bugs — repeating-key XOR (many-time-pad), predictable token JSON, hex-charset session_id, client-side role trust
- Known-plaintext layout — the exact offset table showing 82/114 key bytes from one login
- Hex-charset intersection — with the convergence math and the measured table (why ~60 logins, not 3)
- Token forgery — decrypting your own sid, forging the 87-byte admin token
- Usage —
python3 solve.py <host> <port> - Fix ideas — what the author should have done
All numbers in it (offsets, token sizes, convergence stats, 3/3 test runs) are the verified values from the local testing we did, not guesses.
