-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (61 loc) · 2.32 KB
/
main.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
from concurrent.futures import ThreadPoolExecutor
from itertools import product
from time import time
import rarfile
rarfile.UNRAR_TOOL = "UnRAR.exe"
class RARCracker:
def __init__(self, file, save_file=None, path=None, workers=30, chars=None):
self.cracked = False
self.file = file
self.path = path
self.save_file = save_file
self.time_started = time()
self.workers = workers
self.chars = chars or "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$&*-_+=~`.?"
def save_try(self, password):
with open(self.save_file, "a") as f:
f.write(f"{password}\n")
def crack(self, password):
try:
if not self.cracked:
rf = rarfile.RarFile(self.file)
if self.save_file:
self.save_try(password)
rf.extractall(self.path, pwd=password)
print(f"[+] Password found: {password}")
print(f"Elapsed time: {time() - self.time_started:.0f} seconds")
if self.save_file:
self.save_try(f"{password} << Cracked!")
self.cracked = True
else:
return
except rarfile.RarWrongPassword:
pass
def main(self):
length = 1
count = 0
save_file = None
if self.save_file:
save_file = open(self.save_file, "r").read()
if 'Cracked!' in save_file:
print("[!] File already cracked!")
return
while True:
with ThreadPoolExecutor(max_workers=self.workers) as executor:
for password in product(self.chars, repeat=length):
password = ''.join(password)
# Check if the password is already in save_file
if save_file:
if password in save_file:
continue
executor.submit(self.crack, password)
count += 1
if self.cracked:
break
if self.cracked:
break
length += 1
print(f"Trying length: {length}, count: {count}")
if __name__ == '__main__':
rar = RARCracker('test.rar') # Test password is ab5
rar.main()