├── CrackJWT ├── CrackJWT.py ├── keys.txt └── requirements.txt └── readme.md /CrackJWT/CrackJWT.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 3 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | import jwt 6 | import termcolor 7 | from colorama import init 8 | 9 | 10 | init(autoreset=True) 11 | def check_input(): 12 | """检查输入""" 13 | if len(sys.argv) != 3: 14 | print("Usage: "+sys.argv[0]+" jwt_str"+" keys.txt") 15 | exit(1) 16 | 17 | 18 | def print_sign(): 19 | BANNER = r""" 20 | _ ___ _ _ _____ 21 | | | |_ || | | ||_ _| 22 | ___ _ __ __ _ ___ | | __ | || | | | | | 23 | / __|| '__| / _` | / __|| |/ / | || |/\| | | | 24 | | (__ | | | (_| || (__ | < /\__/ /\ /\ / | | 25 | \___||_| \__,_| \___||_|\_\ \____/ \/ \/ \_/ 26 | (v 1.1) 27 | """ 28 | print(BANNER) 29 | 30 | 31 | def crack_key(): 32 | """爆破jwt秘钥""" 33 | jwt_str = sys.argv[1] 34 | passwd = sys.argv[2] 35 | with open(passwd) as f: 36 | for line in f: 37 | key = line.strip() 38 | try: 39 | jwt.decode(jwt_str,verify=True,key=key, algorithms=['HS256']) 40 | print(termcolor.colored(r"[+]","green"),"found key successfully-->",termcolor.colored(key,"green")) 41 | break 42 | except ( 43 | jwt.exceptions.ExpiredSignatureError, jwt.exceptions.InvalidAudienceError, 44 | jwt.exceptions.InvalidIssuedAtError, 45 | jwt.exceptions.InvalidIssuedAtError, jwt.exceptions.ImmatureSignatureError 46 | ): 47 | print(r"[+] found key successfully!!! -->",termcolor.colored(key,"green")) 48 | break 49 | except jwt.exceptions.InvalidSignatureError: 50 | print(r"[-] try key -->", key) 51 | continue 52 | else: 53 | print(termcolor.colored(r"[+] Done! no key was found","yellow")) 54 | 55 | 56 | if __name__ == '__main__': 57 | check_input() 58 | print_sign() 59 | crack_key() 60 | -------------------------------------------------------------------------------- /CrackJWT/keys.txt: -------------------------------------------------------------------------------- 1 | 000000 2 | 1234 3 | 123456 4 | 12345678 5 | user 6 | test 7 | 0000 8 | 123abc 9 | abc123 10 | $admina$ 11 | $admin$ 12 | root 13 | manage 14 | qwert 15 | -------------------------------------------------------------------------------- /CrackJWT/requirements.txt: -------------------------------------------------------------------------------- 1 | cffi 2 | colorama 3 | cryptography 4 | pycparser 5 | PyJWT 6 | six 7 | termcolor 8 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # JWT秘钥爆破脚本 2 | 3 | ## 说明 4 | 支持签名算法为`HS256`的密钥爆破 5 | ## 用法 6 | ```python 7 | python3 -m pip install -r requirements.txt 8 | 9 | python3 CrackJWT.py jwt_str keys.txt 10 | 11 | ``` 12 | ## 示例 13 | ![image](https://user-images.githubusercontent.com/37563697/226532626-24acf2a6-1728-4512-8749-84d8aa82d4de.png) 14 | 15 | ## 参考 16 | https://www.freebuf.com/vuls/211842.html 17 | --------------------------------------------------------------------------------