-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzipcracker_threading.py
More file actions
executable file
·129 lines (116 loc) · 4.8 KB
/
zipcracker_threading.py
File metadata and controls
executable file
·129 lines (116 loc) · 4.8 KB
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
import argparse
import pyzipper
import itertools
import string
import time
import threading
import multiprocessing
from ctypes import c_char_p, c_char, c_bool
# Default values
DEFAULT_PREFIX = ''
NUMSET = '0123456789'
CHARSET = 'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
DEFAULT_ALPHABET = NUMSET + CHARSET
# Password length contains the prefix!
DEFAULT_MIN_LENGTH = 1
DEFAULT_MAX_LENGTH = 6
found_password = multiprocessing.Value(c_bool, False)
class ZipIt():
def __init__(self, fzipAES, prefix, alphabet, minlength, maxlength):
self.fzipAES = fzipAES
self.prefix = prefix
self.alphabet = alphabet
self.minlength = minlength
self.maxlength = maxlength
# Test to open the zip file with word as password. Return the word if success, None otherwise.
def testing(self, word):
print("[x] TESTING WITH " + word)
try:
self.fzipAES.setpassword(word.encode())
self.fzipAES.extractall()
return True
except (KeyboardInterrupt, SystemExit):
raise
except:
return False
# Return the password if it founds it, None otherwise.
def crackit(self, length, found):
length = length[0]
found = found[0]
print("[x] TESTING WITH LENGTH " + str(length))
for chars in itertools.product(self.alphabet, repeat=length):
if found.value == True:
break
else:
word = self.prefix + ''.join(list(chars))
result = self.testing(word)
if result == True:
found.value = True
print("[+++++++] PASSWORD FOUND: " + word)
break
def start(self):
count_range = range(self.minlength, self.maxlength + 1)
processes = []
# Pour chaque taille on lance un thread différent
for l in count_range:
p = multiprocessing.Process(target=self.crackit, args=([length], [found_password]))
processes.append(p)
start = time.time()
print('[x] CRACKING')
for p in processes:
p.start()
for p in processes:
p.join()
if found_password == False:
print("[-] NO PASSWORD FOUND.")
end = time.time()
done = end - start
print("Done in " + str(done) + "seconds.")
# Initialize zip files input and start cracking. Print the result.
def init(input, prefix, alphabet, minlength, maxlength):
fzipAES = pyzipper.AESZipFile(input)
zi = ZipIt(fzipAES, prefix, alphabet, minlength, maxlength)
zi.start()
# Initialize the arguments.
def parse_args():
parser = argparse.ArgumentParser(description='A simple program to crack zip password')
parser.add_argument('--input', '-i', action='store', type=str, required=True, help='zip file to crack')
alphabet = parser.add_mutually_exclusive_group(required=False)
alphabet.add_argument('--with-int', '-wi', action='store_true', required=False, help='use only integers')
alphabet.add_argument('--with-chr', '-wc', action='store_true', required=False, help='use only french alphabet')
alphabet.add_argument('--all', action='store_true', required=False, help='use integers and french alphabet')
alphabet.add_argument('--alphabet', '-a', action='store', type=str, required=False, help='use integers and french alphabet')
parser.add_argument('--prefix', '-p', action='store', type=str, required=False, help='prefix password')
parser.add_argument('--min', action='store', type=int, required=False, help='min password length, default is ' + str(DEFAULT_MIN_LENGTH))
parser.add_argument('--max', action='store', type=int, required=False, help='max password length, default is ' + str(DEFAULT_MAX_LENGTH))
return parser
if __name__ == '__main__':
parser = parse_args()
args = parser.parse_args()
prefix = DEFAULT_PREFIX
alphabet = DEFAULT_ALPHABET
minlength = DEFAULT_MIN_LENGTH
maxlength = DEFAULT_MAX_LENGTH
if args.min != None:
minlength = args.min
if args.max != None:
maxlength = args.max
if args.prefix != None:
prefix = args.prefix
if (minlength <= len(prefix)) or (maxlength <= len(prefix)):
print('Error: verify the prefix you choose and the min and max password length.')
parser.print_usage()
exit(0)
minlength = minlength - len(prefix)
maxlength = maxlength - len(prefix)
if args.with_int:
alphabet = NUMSET
elif args.with_chr:
alphabet = CHARSET
elif args.all:
alphabet = NUMSET + CHARSET
elif args.alphabet:
alphabet = args.alphabet
else:
alphabet = DEFAULT_ALPHABET
init(args.input, prefix, alphabet, minlength, maxlength)