JWT Pentesting: Free Tools & Labs Guide
In this article
This guide walks you through the practical steps to start testing JSON Web Tokens (JWTs) for security vulnerabilities using only free tools and intentionally vulnerable labs. You'll learn how to decode tokens, identify common weaknesses like algorithm confusion and weak signing secrets, and exploit them in a safe, legal environment. By the end, you'll have a repeatable methodology you can apply to authorized penetration tests.
What You'll Need
- A computer with internet access (Windows, macOS, or Linux).
- A modern web browser (Chrome, Firefox, or Edge) with developer tools.
- Basic understanding of HTTP requests and responses.
- Familiarity with command-line tools (terminal or command prompt).
- Optional but helpful: Python 3 installed, and a tool like Burp Suite Community Edition (free) or OWASP ZAP.
Step-by-Step
- Learn the JWT structure. A JWT is three base64url-encoded parts separated by dots: header.payload.signature. The header typically contains the algorithm (e.g., HS256, RS256). The payload contains claims (like user ID or role). The signature is used to verify the token hasn't been tampered with. Decode a sample token at jwt.io to see the structure.
- Set up a free vulnerable lab. Use a deliberately insecure application designed for training. Options include:
- PortSwigger's Web Security Academy (free) – has dedicated JWT labs under “JWT authentication vulnerabilities”.
- DVWA (Damn Vulnerable Web Application) – install locally, but it's not JWT-focused.
- OWASP Juice Shop – a modern vulnerable web app with JWT challenges. Run it locally via Docker or npm.
- Intercept and capture a JWT. Log into the lab application with the provided credentials. Use your browser's developer tools (or Burp/ZAP) to inspect the HTTP requests. Look for an
Authorization: Bearer <token>header or a cookie containing the token. Copy the token. - Decode and analyze the token. Use jwt.io or a local tool like
jwt_tool(a free Python script) to decode the token. Note the algorithm (e.g., HS256, RS256) and the claims. Check if the claims are predictable (e.g.,{"user":"admin"}). - Test for algorithm confusion. This is a classic attack. If the server accepts the algorithm specified in the header without verifying it against a whitelist, you can change the algorithm to
noneor to a symmetric algorithm (like HS256) when the server expects asymmetric (RS256).- None algorithm: Change the header to
{"alg":"none"}, remove the signature (leave the third part empty), and modify the payload. Send the token to the server. If it accepts it, you've bypassed authentication. - RS256 to HS256: If the server uses RS256 (asymmetric), you can try to use the server's public key (often exposed) as the HMAC secret for HS256. Tools like
jwt_toolautomate this.
- None algorithm: Change the header to
- Test for weak signing secrets. If the token uses HS256 (symmetric), the secret might be weak. You can brute-force it using a wordlist. Tools like
hashcatorjwt_toolcan do this. For example, withjwt_tool:python3 jwt_tool.py <token> -C -d /usr/share/wordlists/rockyou.txt. If the secret is found, you can forge arbitrary tokens. - Test for payload tampering. Even if you can't crack the secret, you can try to modify the payload (e.g., change
"admin":falseto"admin":true) and see if the server validates the signature. If it doesn't, you can escalate privileges. Always test this on the lab, not on real systems. - Practice on the labs. PortSwigger's JWT labs have multiple levels: algorithm confusion, weak signing key, and more. Work through each one. The solution explanations are available if you get stuck, but try to solve them yourself first.
- Document your findings. For each test, note the vulnerability, the exploit, and the impact. This is good practice for real penetration testing reports.
Common Mistakes
- Forgetting to change the algorithm back. When testing algorithm confusion, you might leave the token with
alg:noneand forget to restore it, causing confusion in later tests. - Not checking the server's response. Sometimes the server returns a generic 401 error. Always check the response body and status code to see if your modified token was accepted (e.g., 200 OK vs 401).
- Using the wrong secret for HS256. When cracking, make sure you're using the correct format. Some tools expect the token without the trailing dot.
- Assuming all JWTs are vulnerable. Many implementations are secure. The labs are designed to be vulnerable, but real-world apps may have proper validation.
Tips
- Use a proxy tool. Burp Suite Community (free) or OWASP ZAP make it easy to intercept and modify requests. They also have extensions like “JWT Editor” (Burp) to manipulate tokens.
- Learn the difference between HS256 and RS256. HS256 is symmetric (one secret), RS256 is asymmetric (private/public key pair). The attack vectors differ.
- Check for JWK and jku headers. Some servers allow you to inject a malicious JSON Web Key Set (JWKS) URL. This is advanced but covered in some labs.
- Automate with scripts. Once you understand the manual process, write a Python script using
requestsandPyJWTto automate token forgery. - Stay legal. Only test on systems you own or have explicit permission to test. The labs are safe, but real-world testing requires authorization.
Troubleshooting
- The lab doesn't load or gives an error. PortSwigger's labs sometimes require a free account. Refresh the page, or try a different browser. If using Docker for Juice Shop, ensure Docker is running and the port is correct.
- My modified token is always rejected. Double-check the base64url encoding. Remember to replace
+with-and/with_, and remove padding=. Use a tool likejwt_toolto encode properly. - jwt_tool or hashcat isn't working. Ensure you have the latest version and that your wordlist path is correct. For hashcat, you need to specify the hash type (e.g.,
-m 16500for JWT HS256). - I can't find the JWT in the request. Look in the
Authorizationheader, but also check cookies, URL parameters, or POST body. Use the browser's network tab and search for “jwt” or “token”. - The algorithm confusion attack doesn't work. The server may have a whitelist of allowed algorithms. Try the
noneattack first, then RS256→HS256. If both fail, move on to the next lab.
Frequently Asked Questions
What is the difference between HS256 and RS256?
HS256 uses a single shared secret to sign and verify tokens (symmetric). RS256 uses a private key to sign and a public key to verify (asymmetric). The attack for HS256 is brute-forcing the secret; for RS256, it's algorithm confusion if the server mishandles the key.
Can I test JWT vulnerabilities on any website?
No. Only test on systems you own or have written permission to test. Unauthorized testing is illegal and unethical. Use dedicated labs like PortSwigger's or OWASP Juice Shop.
What is the best free tool for JWT pentesting?
There's no single best. jwt_tool is excellent for manual exploitation, Burp Suite Community with the JWT Editor extension is great for intercepting and modifying, and hashcat for cracking secrets. Start with jwt_tool.
How do I know if a JWT is vulnerable?
Common signs: the algorithm is not enforced (you can change it), the secret is weak (e.g., “secret”, “password”), or the server doesn't verify the signature. The labs will teach you to test these systematically.
Do I need to know programming to start?
No, but it helps. You can use GUI tools like Burp and jwt.io for basic tests. For advanced attacks like writing scripts, basic Python knowledge is beneficial.
What should I do after I find a JWT vulnerability?
Document it clearly: the type, the steps to reproduce, and the potential impact. In a real engagement, report it to the owner. In a lab, you can read the solution and compare your approach.