Menu

Cracking a weak JWT secret with hashcat, and the fix
📰

Cracking a weak JWT secret with hashcat, and the fix

DEV Community: api·Rocky·about 8 hours ago
#77hTHn54
#devtoapi#devto#dev#secret#token
Long article (507 words) — no AI summary yet.
Reading 0:00
15s threshold

A JWT can be attacked entirely offline. The server never sees the attempts, so there is no failed-login count to watch and nothing to lock out.

Why HS256 allows it

An HS256 token is signed with a single shared secret. The same secret that creates the signature also checks it. If you have one valid token, you have a target to test guesses against on your own machine.

A token looks like three base64url parts joined by dots: header, payload, signature. The signature is an HMAC over the first two parts. Guess the key, recompute the HMAC, compare. Match means you found it.

The attack

Save the full token on one line in token.txt , then:

hashcat -m 16500 token.txt wordlist.txt

Enter fullscreen mode

Exit fullscreen mode

Mode 16500 is JWT. With a wordlist such as rockyou, a secret that is a common word, a product name or a default like secret comes back quickly. Once recovered, build a new token with the claims you want, for instance "role": "admin" , and sign it with the recovered key.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.