-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdedjwt.py
98 lines (86 loc) · 3.08 KB
/
dedjwt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/env python3
import jwt
import time
from colorama import Fore, Style
from concurrent.futures import ThreadPoolExecutor
import psutil
import sys
Red = Fore.RED
Green = Fore.GREEN
Cyan = Fore.CYAN
Blue = Fore.BLUE
Bold = Style.BRIGHT
Reset = Style.RESET_ALL
def brute_force_jwt(encoded, password):
try:
payload = jwt.decode(encoded, password, algorithms=['HS256'])
return password
except jwt.InvalidKeyError:
pass
except jwt.ExpiredSignatureError:
pass
except Exception as e:
pass
return None
def get_num_threads():
cpu_usage = psutil.cpu_percent()
if cpu_usage < 60:
return 8
elif cpu_usage < 80:
return 4
else:
return 2
def load_passwords(password_list):
try:
with open(password_list, 'rb') as file:
return [line.strip().decode('latin-1') for line in file]
except FileNotFoundError:
print(f"[{Red}{Bold}ERR{Reset}] Password list file not found, Exiting.")
sys.exit(1)
except Exception as e:
print(f"[{Red}{Bold}ERR{Reset}] An error occurred while loading passwords: {str(e)}" )
sys.exit(1)
def save_found_password(success, output_file):
with open(output_file, 'a') as file:
file.write(success + '\n')
def main():
banner = """
╔╦╗╔═╗╔╦╗ ╦╦ ╦╔╦╗
║║║╣ ║║ ║║║║ ║
═╩╝╚═╝═╩╝╚╝╚╩╝ ╩ v1.2
JWT Bruter by Asbawy
"""
print(f"{Red}{banner}{Reset}")
encoded = input(f"{Blue}[+]{Reset} Enter JWT token: ")
try:
jwt.decode(encoded, options={'verify_signature': False})
except jwt.InvalidTokenError:
print(f"[{Red}{Bold}ERR{Reset}] Invalid JWT token, Exiting.")
sys.exit(1)
password_list = input(f"{Blue}[+]{Reset} Enter the passwords list: ")
output_file = input(f"{Blue}[+]{Reset} Enter the output file for found passwords (optional): ")
passwords = load_passwords(password_list)
print(f"[{Cyan}{Bold}INFO{Reset}] Starting brute force with {Green}{len(passwords)} passwords{Reset}.")
start_time = time.time()
success = None
with ThreadPoolExecutor(max_workers=get_num_threads()) as executor:
passwords_tested = 0
for secret in passwords:
result = executor.submit(brute_force_jwt, encoded, secret)
passwords_tested += 1
if result.result():
success = result.result()
if output_file:
save_found_password(success, output_file)
break
sys.stdout.write(f"\r[{Cyan}{Bold}INFO{Reset}] Passwords tested: {Green}{passwords_tested}{Reset}")
sys.stdout.flush()
if success:
print(f"\n[{Green}DONE{Reset}] Token decoded with the following password: [{Green}{Bold}{success}{Reset}]")
else:
print(f"\n[{Red}{Bold}ERR{Reset}] Failed to decode token.")
end_time = time.time()
elapsed_time = end_time - start_time
print(f"[{Cyan}INFO{Reset}] Elapsed time: {Bold}{Cyan}{elapsed_time:.2f} seconds{Reset}")
if __name__ == "__main__":
main()