forked from mnismt/CompressedCrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrack.py
139 lines (126 loc) · 4.33 KB
/
crack.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
import zipfile
import rarfile
import os
import sys
from threading import Thread
import argparse
from itertools import product
import time
parser = argparse.ArgumentParser(description='CompressedCrack v1.0.1 by ThanhMinh', epilog='Use the -h for help')
parser.add_argument('-i','--input', help='Insert the file path of compressed file', required=True)
parser.add_argument('rules', nargs='*', help='<min> <max> <character>')
# Const Character
CHARACTER = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\\:;\"'<>,.?/"
class Check:
def __init__(self, Arg):
self.type = None
self.rules = False
self.startLength = None
self.maxLength = None
self.character = None
# Check Rules
if len(Arg) >= 4:
self.getData(Arg)
self.rules = True
elif len(Arg) == 0 or len(Arg) > 2:
parser.print_help()
parser.exit()
# Check File Exist
if (self.CheckFileExist(Arg)):
self.getType(Arg)
else:
print ('No such file or directory: ',Arg[1])
parser.exit()
def CheckFileExist(self, Arg):
if (os.path.isfile(Arg[1])):
return True
else:
return False
def getData(self, Arg):
try:
self.startLength = int(Arg[2])
self.maxLength = int(Arg[3])
except ValueError:
print ('Value Error')
parser.exit()
if self.startLength > self.maxLength:
print ('Length Error')
parser.exit()
if len(Arg) == 5:
self.character = Arg[4]
def getType(self, Arg):
if os.path.splitext(Arg[1])[1] == ".rar" or os.path.splitext(Arg[1])[1]==".zip":
self.type = os.path.splitext(Arg[1])[1]
else:
print ('Extension Error')
parser.exit()
class Handler:
def __init__(self, rules, typeCompress, startLength, maxLength, character):
self.rules = rules
self.location = sys.argv[2]
self.type = typeCompress
self.startLength = startLength
self.maxLength = maxLength
if not character:
self.character = CHARACTER
else:
self.character = character
self.result = False
self.GetFile()
self.CheckRules()
def GetFile(self):
# Khai báo file
if self.type == '.zip':
self.FileCrack = zipfile.ZipFile(self.location)
else:
self.FileCrack = rarfile.RarFile(self.location)
def Brute(self,password):
try:
if self.type == '.zip':
tryPass = password.encode()
else:
tryPass = password
print (tryPass)
self.FileCrack.extractall(pwd=tryPass)
print ('Complete')
print('Time:',time.clock() - self.start_time,'s')
print ('Password:',password)
self.result = True
except:
pass
def CheckRules(self):
self.start_time = time.clock()
print ('Cracking...')
if not self.rules:
length = 1
while True:
self.SendRequest(length)
if self.result:
return
length += 1
else:
for length in range(self.startLength, self.maxLength + 1):
self.SendRequest(length)
if self.result:
return
if not self.result:
print ('Cannot find password with this rules')
return
def SendRequest(self,length):
listPass = product(self.character, repeat=length)
for Pass in listPass:
tryPass = ''.join(Pass)
# Multi Thread:
# nThread = Thread(target=self.Brute, args=(tryPass, ))
# nThread.start()
# Single Thread:
self.Brute(tryPass)
if self.result:
return
def main():
check = Check(sys.argv[1:])
args = parser.parse_args()
rarfile.UNRAR_TOOL = "UnRAR.exe"
Handling = Handler(check.rules, check.type, check.startLength, check.maxLength, check.character)
if __name__ == '__main__':
main()