自己動(dòng)手寫跑字典解密zip加密文件斧蜕。本文以python3.6 版本闺骚,window環(huán)境
# coding=UTF-8
"""
用字典暴力破解ZIP壓縮文件密碼
"""
import zipfile
import optparse
from threading import Thread
def extractFile(zFile, password):
try:
#3.x 版本必須加上.encode('ascii')烈掠,3.x版本不能自動(dòng)支持ascii碼了
zFile.extractall(pwd=password.encode('ascii'))
print("[+] Found password " + password + "\n")
except:
pass
def main():
parser = optparse.OptionParser("usage%prog " + "-f <zipfile> -d <dictionary>")
parser.add_option("-f", dest="zname", type="string", help="specify zip file")
parser.add_option("-d", dest="dname", type="string", help="specify dictionary file")
(options, args) = parser.parse_args()
if(options.zname == None ) |(options.dname == None):
print(parser.usage)
exit(0)
else:
zname = options.zname
dname = options.dname
zFile = zipfile.ZipFile(zname)
passFile = open(dname)
for line in passFile.readlines():
password = line.strip('\n')
t = Thread(target=extractFile,args=(zFile, password))
t.start()
if __name__ == "__main__":
main()
接著就可以在終端執(zhí)行
python unzip.py -f evil.zip -d dictionary.txt
unzip.py 即這個(gè)程序
evil.zip 需要解密的文件
dictionary.txt 字典文件肌索,即保存密碼的文件可以多個(gè)換行分開
本文參照《python絕技》一書胰默,書本是python2.7版粱栖,linux 環(huán)境下的。本文以python3.6版本慌闭,windows環(huán)境下别威。