-
Notifications
You must be signed in to change notification settings - Fork 5
/
zipcracker.py
90 lines (77 loc) · 2.64 KB
/
zipcracker.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
#!/usr/bin/python
import argparse
import zipfile
import os
import sys
from time import time
VERSION = '1.0'
AUTHOR = "AneoPsy"
def _cli_opts():
'''
Parse command line options.
@returns the arguments
'''
mepath = unicode(os.path.abspath(sys.argv[0]))
mebase = '%s' % (os.path.basename(mepath))
description = '''Zip cracker.'''
desc = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(prog=mebase,
description=description,
formatter_class=desc,
)
parser.add_argument('-f', '--file',
action='store',
help='zip file',
required=True)
parser.add_argument('-w', '--word_list',
action='store',
help='word_list file',
required=True)
parser.add_argument('-V', '--version',
action='version',
version='%(prog)s v' + VERSION + " by " + AUTHOR)
args = parser.parse_args()
return args
def main(args):
try:
zip_ = zipfile.ZipFile(args.file)
except zipfile.BadZipfile:
print "Please check the file's path. It doesn't seem to be a zip file."
sys.exit(1)
password = None
i = 0
c_t = time()
try:
max_lines = sum(1 for line in open(args.word_list, 'r'))
except Exception:
print "Error: wordlist not found!"
sys.exit(1)
with open(args.word_list, "r") as f:
passes = f.readlines()
for x in passes:
i += 1
password = x.split("\n")[0]
try:
zip_.extractall(pwd=password)
t_t = time() - c_t
print "\n\nPassword cracked: %s\n" % password
print "Took %f seconds to crack the password. That is, "\
"%i attempts per second." % (t_t, i / t_t)
sys.exit(1)
except Exception:
pass
output = "%*d / %d | %6.2f%% -> %s\r" % (len(str(max_lines)),
i,
max_lines,
100 * i / max_lines,
password
)
sys.stdout.write(output)
sys.stdout.flush()
if __name__ == '__main__':
args = _cli_opts()
try:
main(args)
except KeyboardInterrupt:
print "\nExit..."
sys.exit(1)