0x00 Zip加密文件字典破解Python实现
本例使用Python zipfile模块用来做zip格式编码的压缩和解压缩,顺带使用了optparse模块和threading模块。
0x01 代码实现
import zipfile
import os
from optparse import OptionParser
from threading import Thread
def extractFile(zFile, password):
try:
zFile.extractall(pwd=password)
print '[+] Found password ' + password + '\n'
except:
pass
def checkFile(filename):
if not os.path.isfile(filename):
print '[-] ' + filename + ' does not exist.'
exit(0)
if not os.access(filename, os.R_OK):
print '[-] ' + filename + ' access denied.'
exit(0)
def main():
parser = optparse.OptionParser(usage="usage%prog " + "-f -d ", version="%prog v1.0")
parser.add_option('-f', '--filename', dest='zipfile', type='string', help='specify zip file')
parser.add_option('-d', '--dictionary', dest='dicfile', type='string', help='specify dictionary file')
(options, args) = parser.parse_args()
if (options.zipfile == None) | (options.dicfile == None):
print parser.usage
exit(0)
else:
zip_file = options.zipfile
dic_file = options.dicfile
checkFile(zip_file)
checkFile(dic_file)
zFile = zipfile.ZipFile(zip_file)
passFile = open(dic_file)
for line in passFile.readlines():
password = line.strip('\n')
t = Thread(target=extractFile, args=(zFile, password))
t.start()
if __name__ == '__main__':
main()
0x10 效果