-
Notifications
You must be signed in to change notification settings - Fork 11
/
crack_AES256.py
193 lines (159 loc) · 3.9 KB
/
crack_AES256.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import aes
import hashlib
import base64
from Crypto import Random
from Crypto.Cipher import AES
def decrypt(encrypted, passphrase):
cipher = AES.new(passphrase, AES.MODE_CBC)
return cipher.decrypt(base64.b64decode(encrypted))
DecodeAES = lambda secret, e: aes.decryptData(secret, base64.b64decode(e))
def sha256(x):
return hashlib.sha256(x).digest()
def Hash(x):
if type(x) is str:
x = x.encode("utf-8")
return sha256(sha256(x))
def pw_decode(s, password):
if password is None:
return s
secret = Hash(password)
try:
d = DecodeAES(secret, s)
# d = decrypt(s,secret)
except Exception as e:
raise Exception("Invalid password")
return d
def try_pw(encoded_seed, pw_cand):
seed = ""
try:
seed = pw_decode(encoded_seed, pw_cand)
except Exception:
seed = ""
finally:
pass
return seed
def chk_seed(seed):
if len(seed) == 0:
return False
for cnt, c in enumerate(seed, start=1):
if cnt > 32:
return True
i = ord(c)
if i < 48:
return False
if i > 57:
if i < 97:
return False
if i > 102:
return False
return True
def xselections(items, n):
if n == 0:
yield []
else:
for i in range(len(items)):
for ss in xselections(items, n - 1):
yield [items[i]] + ss
# Numbers = 48 - 57
# Capital = 65 - 90
# Lower = 97 - 122
numb = list(range(48, 58))
cap = list(range(65, 91))
low = list(range(97, 123))
choice = 0
# while int(choice) not in range(1,8):
# choice = raw_input('''
# 1) Numbers
# 2) Capital Letters
# 3) Lowercase Letters
# 4) Numbers + Capital Letters
# 5) Numbers + Lowercase Letters
# 6) Numbers + Capital Letters + Lowercase Letters
# 7) Capital Letters + Lowercase Letters
# : ''')
#
choice = 3
poss = []
if choice == 1:
poss += numb
elif choice == 2:
poss += cap
elif choice == 3:
poss += low
elif choice == 4:
poss += numb
poss += cap
elif choice == 5:
poss += numb
poss += low
elif choice == 6:
poss += cap
poss += low
poss += numb
elif choice == 7:
poss += cap
poss += low
bigList = [chr(i) for i in poss]
special = False
if special:
bigList.extend(
(
".",
" ",
"_",
"-",
"+",
"/",
"*",
"!",
"?",
"'",
'"',
"#",
"$",
"%",
"(",
")",
"[",
"]",
"^",
"{",
"}",
"@",
",",
";",
":",
)
)
def test():
encoded_seed = "Ww9jsiumblVPSM5owcLS6wODqxh0YDLIg/g+mNv+nuNP+f7yyhqOomTlK9tDv8xV0kYt/nUDeTZNtUOr3Zfp2w=="
# encoded_seed = 'QJA7vVqVDsUM1CaKVJXVSvO0e8hkQUsQbE5YqfguJX3Fs+1WP5XDSAjtxQU5L2fQiS7p5+zJ58B2lftmiZaa5g=='
# encoded_seed = 'VsIJxlznWkfRauhF6sGvjdZxt3qtWDdVQjbE+KFtKXjarc7IfcJxbWq9LACWVO7t8Rqwp+/OvbJHsxzwZ6Ys8Q=='
cnt = 0
cnt_good = 0
MIN = 1
MAX = 14
for i in range(MIN, MAX + 1):
for s in xselections(bigList, i):
t = "".join(s)
pw_cand1 = t
cnt += 1
if cnt % 1000 == 0:
print("trying:", pw_cand1)
seed = try_pw(encoded_seed, pw_cand1)
if chk_seed(seed):
print(f"pw is good: {pw_cand1}")
print(seed)
cnt_good += 1
break
print("cnt: %d" % cnt)
print("cnt_good: %d" % cnt_good)
def test1():
encoded_seed = "Ww9jsiumblVPSM5owcLS6wODqxh0YDLIg/g+mNv+nuNP+f7yyhqOomTlK9tDv8xV0kYt/nUDeTZNtUOr3Zfp2w=="
seed = try_pw(encoded_seed, "test")
if chk_seed(seed):
print("ok")
print(seed)
test()