Course contentsShow
← Security
Lesson 789 of 3,05216. Web Security - Authentication MechanismsFree lesson

Weak Secret Keys and Brute Force

Cracking HMAC-signed JWTs with weak secrets using dictionary and brute-force attacks.

Weak Secret Keys and Brute Force

What you'll learn: How attackers crack HMAC-signed JWTs when weak secrets are used to sign them.

The Vulnerability

When a JWT is signed with HMAC (like HS256), the signature acts as a seal proving the token hasn't been tampered with. However, this seal is only as strong as the secret key used to create it. If the secret is weak—like "secret", "password123", or a common word—attackers can discover it through brute-force or dictionary attacks, then forge valid tokens to impersonate any user.

Think of it like a lock: HMAC is a strong lock mechanism, but if you use "1234" as your combination, the lock becomes meaningless.

How the Attack Works

Attackers obtain a valid JWT (perhaps intercepted or from a test account). They then:

  1. Dictionary attack: Try common passwords and phrases from wordlists against the JWT to see if any produces the correct signature
  2. Brute-force attack: Systematically try all possible key combinations of increasing length

Tools like hashcat and jwt_tool automate this process. If the secret is weak, it can be cracked in seconds or minutes.

The Danger

Once an attacker discovers your signing secret, they can:

  • Forge tokens with any claims (user ID, roles, permissions)
  • Bypass authentication entirely
  • Escalate privileges to admin level
  • The breach is invisible—forged tokens look completely legitimate

Prevention

Always use cryptographically random secrets with sufficient entropy (at least 256 bits for HS256). Never use dictionary words, default values, or predictable patterns. Your secret should be as random as the HMAC algorithm is strong.

Key Takeaway: A strong HMAC algorithm with a weak secret is like a titanium safe with a sticky note password—the attacker will always target the weakest link, and weak secrets can be cracked to forge valid JWTs.