python破解zip密码

今天写了个小脚本,用于暴力破解zip密码

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
import zipfile
from threading import Thread
import optparse

def testZipPasswd(zfile,passWord):
try:
zfile.extractall(pwd=passWord)
print("[+] Found Password: "+str(passWord,encoding="utf-8"))
except Exception as e:
#print(e)
pass
def decodeZipPasswd(zfile,passfile):
with open(passfile) as f:
zfile = zipfile.ZipFile(zfile)
for i in f.readlines():
i = i.replace("\n","")
t = Thread(target=testZipPasswd,args=(zfile, i.encode(encoding="utf-8")))
t.start()
if __name__ == "__main__":
parser = optparse.OptionParser("python zip.py -f <zipfile> -p <passfile>")
parser.add_option("-f",dest='zname',type='string',help='specify zip file')
parser.add_option("-p",dest='passwd',type='string',help='specify password file')
(options,args) = parser.parse_args()
if options.zname ==None or options.passwd==None:
print(parser.usage)
exit(0)
else:
decodeZipPasswd(options.zname,options.passwd)