ticarpi / jwt_tool

:snake: A toolkit for testing, tweaking and cracking JSON Web Tokens
GNU General Public License v3.0
5.46k stars 670 forks source link

JWT Attack Playbook HS Advice for RS Algorithm #88

Open joswr1ght opened 2 years ago

joswr1ght commented 2 years ago

When using a playbook scan, I thought it odd that jwt_tool suggests HS attacks when the algorithm is RS (and doesn't suggest RS attacks):

$ python jwt_tool.py -rh 'Authorization: Foo eyJhb...' -t 'https://test-target.willhackforsushi.com/api/v1/capabilities' -M pb
...
Token header values:
[+] alg = "RS256"
...
LAUNCHING SCAN: JWT Attack Playbook
...
The following additional checks should be performed that are better tested manually:
[+] Try testing HS token against weak password configurations by running the following hashcat cracking options:
(Already testing against passwords in jwt-common.txt)
Try using longer dictionaries, custom dictionaries, mangling rules, or brute force attacks.
hashcat (https://hashcat.net/hashcat/) is ideal for this as it is highly optimised for speed. Just add your JWT to a text file, then use the following syntax to give you a good start:

[*] dictionary attacks: hashcat -a 0 -m 16500 jwt.txt passlist.txt
[*] rule-based attack:  hashcat -a 0 -m 16500 jwt.txt passlist.txt -r rules/best64.rule
[*] brute-force attack: hashcat -a 3 -m 16500 jwt.txt ?u?l?l?l?l?l?l?l -i --increment-min=6
[+] Try waiting for the token to expire ("exp" value set to: 2022-11-02 07:57:35 (UTC))
Check if still working once expired.

It looks like lines 1514 and 1518 check headDict['alg'] for the algorithm type, but this value is changed somewhere else (also noted at line 1377 where is is saved as origalg).

This is a tiny issue, PR incoming.