HIGH jwt cracking

Jwt Cracking Attack

How Jwt Cracking Works

JSON Web Token (JWT) cracking is a brute-force attack targeting the cryptographic secrets used to sign or encrypt JWTs. Unlike JWT attacks that exploit weak algorithms or implementation flaws, cracking focuses on recovering the secret key through computational force.

A JWT consists of three parts: header, payload, and signature, separated by dots. The signature proves the token's integrity and authenticity. When attackers don't have the secret key, they can attempt to crack it by generating millions of candidate keys and checking which one produces a valid signature for a given token.

The attack typically follows this process:

  • Capture a valid JWT from an API response or network traffic
  • Extract the header to determine the algorithm (HS256, HS384, HS512)
  • Generate candidate keys from dictionaries, common passwords, or entropy sources
  • Compute signatures for each candidate key and compare against the captured token
  • When a match is found, the attacker can forge arbitrary tokens

Success depends on key strength. Short keys (under 16 characters), common passwords, or keys derived from predictable values are vulnerable. A 12-character alphanumeric key might be cracked in hours on modern hardware, while a 32-character random key would take centuries.

Tools like jwt_tool, hashcat, and custom scripts automate this process. Attackers often use GPU acceleration to test billions of keys per second. The attack is particularly effective against development or staging environments where weak secrets are common.

Jwt Cracking Against APIs

APIs become vulnerable to JWT cracking when they accept unsigned or weakly signed tokens, or when attackers can obtain a valid token through other means. The attack has several practical applications against API security.

First, if an API accepts unsigned tokens or falls back to insecure algorithms like 'none', cracking becomes trivial. Attackers simply remove the signature and modify the payload. More commonly, they capture a token from a legitimate user and attempt to crack the secret.

Once cracked, attackers can create tokens with elevated privileges. They might change the role claim from 'user' to 'admin', or modify the userId to access another user's data. This enables horizontal privilege escalation and data theft.

APIs without proper token validation are especially vulnerable. Some implementations only check the signature without validating claims like expiration (exp), issuer (iss), or audience (aud). Even with valid signatures, these tokens can be exploited.

Real-world examples include CVE-2017-11424 where a Node.js library accepted malformed tokens, and CVE-2018-0114 where Cisco devices had weak default secrets. Attackers also target APIs that expose tokens in URLs, logs, or error responses, making capture easier.

The attack is particularly dangerous for APIs using symmetric keys (HS256) rather than asymmetric keys (RS256). With symmetric keys, the same secret signs and verifies tokens, so cracking gives full control. Asymmetric keys require the private key for signing, making cracking much harder.

Detection & Prevention

Detecting JWT cracking attempts requires monitoring for unusual authentication patterns. Look for repeated failed token validations with slight variations, high authentication failure rates from single IP addresses, or tokens with similar structures being rejected.

Implement rate limiting on authentication endpoints to slow down brute-force attempts. Use exponential backoff for repeated failures. Monitor authentication logs for anomalies and set up alerts for unusual patterns.

Prevention starts with strong key management. Use randomly generated secrets of at least 32 characters for HS256 tokens. Store secrets in secure vaults, not in code repositories or configuration files. Rotate secrets regularly and immediately after any suspected compromise.

Prefer asymmetric algorithms (RS256, ES256) for APIs where possible. The public key can verify tokens without exposing the private signing key. This limits the impact if tokens are captured.

Validate all claims in tokens: expiration, issuer, audience, and any custom claims relevant to your application. Don't accept tokens from unexpected issuers or for wrong audiences. Implement token revocation mechanisms using blocklists or short expiration times with refresh tokens.

middleBrick's API security scanner includes JWT-specific checks that detect weak token implementations, missing claim validation, and algorithm vulnerabilities. The scanner tests whether your API accepts unsigned tokens, falls back to insecure algorithms, or has other JWT-related weaknesses. It provides specific findings with remediation guidance, helping you identify and fix vulnerabilities before attackers can exploit them.

For continuous protection, middleBrick's Pro plan offers scheduled scanning that can detect new JWT vulnerabilities as your API evolves. The GitHub Action integration lets you fail builds if security scores drop, preventing vulnerable JWT implementations from reaching production.

Frequently Asked Questions

How long does it take to crack a JWT token?
Cracking time depends on key strength and available computing power. A weak 8-character password might be cracked in seconds using GPU acceleration. A 16-character random key could take hours to days. Strong 32+ character keys are practically uncrackable with current technology. The attack's success rate is directly proportional to key entropy and inversely proportional to key length.
Can JWT cracking be detected by security tools?
Yes, tools like middleBrick can detect JWT vulnerabilities that make cracking easier. The scanner checks for weak algorithms, missing claim validation, acceptance of unsigned tokens, and other implementation flaws. It also tests for excessive authentication failures and other brute-force indicators. However, active cracking attempts during runtime require monitoring systems to detect the high-volume authentication failures characteristic of brute-force attacks.