-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcrack_pw.py
47 lines (39 loc) · 1.16 KB
/
crack_pw.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
import sys
import zipfile
import itertools
filename = ""
try:
filename = sys.argv[1];
except:
print "The filename was not a valid string"
exit(1)
#characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
characters = "abcdefghijklmnopqrstuvwxyz"
zipFile = zipfile.ZipFile(filename, "r")
#iterate all possible lengths of the password
for leng in range(1, len(characters)+1):
print "lenght of password: ", leng
#create an iterator over the cartesian product of all possible permuations
it = itertools.product(characters, repeat=leng)
#iterate all created permutations
for passw in it:
try:
#join the tupel to a string and set the password
passwd = ''.join(passw)
zipFile.setpassword(passwd)
"""
try to extract the files from the file
if the password is wrong, an exception is thrown,
(RuntimeError), which is caught in the except part
"""
zipFile.extractall()
#if there was no error the password will be shown and the programm exits
print "The password is: ", passwd
exit()
except RuntimeError:
pass
except zipfile.BadZipfile:
pass
except Exception as e:
pass
print "no pw found..."