Zip加密文件字典破解Python实现

最近在看《Violent Python》,记录一些代码实现。

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 <zipfile> -d <dicitonary>", 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()
</dicitonary></zipfile>

0x10 效果


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值