-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecryption.py
112 lines (94 loc) · 3.24 KB
/
decryption.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
import threading, os, signal, hashlib, base64, sys
iterations = 1000
DIV = 2500
begin = [0, 1000, 2500, 5000, 7500]
quit = False
def signalHandler(signo, arg):
global quit
quit = True
#print("Receive a signal %d, quit %d" %(signo, quit))
def findPasswd(hashStr, saltStr):
"Find the password of the Parental Contol"
signal.signal(signal.SIGTERM, signalHandler)
signal.signal(signal.SIGINT, signalHandler)
if os.path.exists("result.txt"):
os.remove("result.txt")
task_list = []
t1 = threading.Thread(target=matchSmallNumberHash,args=(1000, hashStr, saltStr))
task_list.append(t1)
t2 = threading.Thread(target=matchHash,args=(2500, hashStr, saltStr))
task_list.append(t2)
t3 = threading.Thread(target=matchHash,args=(5000, hashStr, saltStr))
task_list.append(t3)
t4 = threading.Thread(target=matchHash,args=(7500, hashStr, saltStr))
task_list.append(t4)
t5 = threading.Thread(target=matchHash,args=(10000, hashStr, saltStr))
task_list.append(t5)
for t in task_list:
t.start()
for t in task_list:
t.join()
def getHash(key, salt):
Hash = hashlib.pbkdf2_hmac('sha1', bytes(key.encode()), base64.b64decode(salt), iterations)
Hash = base64.b64encode(Hash)
return Hash
def sendSignal():
os.kill(os.getpid(), signal.SIGINT)
def compare(newStr, oldStr, passwd):
if newStr == bytes(oldStr.encode()):
print("****** Found it!!!!! ****** The password is ", passwd)
with open("result.txt", "w") as f:
BUF = "Password: " + passwd + "\n"
f.write(BUF)
sendSignal()
return True
return False
def matchSmallNumberHash(count, hashStr, saltStr):
keyStr = ""
global quit
for i in range(0, 10):
keyStr = "000" + str(i)
newHash = getHash(keyStr, saltStr)
compare(newHash, hashStr, keyStr)
if (quit):
return
for i in range(10, 100):
keyStr = "00" + str(i)
newHash = getHash(keyStr, saltStr)
compare(newHash, hashStr, keyStr)
if (quit):
return
for i in range(100, count):
keyStr = "0" + str(i)
newHash = getHash(keyStr, saltStr)
compare(newHash, hashStr, keyStr)
if (quit):
return
def matchHash(count, hashStr, saltStr):
"Compare the new hash which generated by key & salt with hashStr"
global quit
for i in range(begin[int(count/DIV)], count):
newHash = getHash(str(i), saltStr)
compare(newHash, hashStr, str(i))
if (quit):
return
def usage():
print("Usage:")
print(" %s \"axo6VEI3Tn2ekTeLxA8KBBmH7CA=\" \"GuCyTQ==\"" % sys.argv[0])
def main():
if len(sys.argv) == 3:
hashKey = sys.argv[1]
salt = sys.argv[2]
if len(hashKey) != 28 or len(salt) != 8:
print("Please input the right Hash key and salt value!")
usage()
return
findPasswd(hashKey, salt)
if not quit:
print("Sorry, cannot find the password for this hash key and salt!!!")
print("Please check the hash key and salt are right or not!")
else:
print("Please input the right arguments!!")
usage()
# Call the main function
main()