python---项目4-Zip文件口令破解脚本,zipfile,optparse,thread

python—Zip文件口令破解脚本
主要使用zipfile库的extractall()方法,其中pwd参数指定密码

参考:https://www.cnblogs.com/bergus/p/4811293.html
https://iask.sina.com.cn/b/7ys9HurjMxl.html
http://blog.csdn.net/a464057216/article/details/47375999
https://www.cnblogs.com/captain_jack/archive/2011/01/11/1933366.html

1、要解开的zip的加密的test.zip文件信息
python---项目4-Zip文件口令破解脚本,zipfile,optparse,thread_第1张图片

2、文件配置信息

root@kali:~/python/anquangongji# ls 
creakzipfile.py    pingip_false.txt  scanftpbanner.py       test.zip
dictionaryzip.txt  pingip_true.txt   scanhostsingalport.py  vulnbanners.txt
root@kali:~/python/anquangongji# cat dictionaryzip.txt 
asd123456
qwe123456
zxc123456
123456
root@kali:~/python/anquangongji# 

3、脚本代码

#脚本源码:
root@kali:~/python/anquangongji# 
root@kali:~/python/anquangongji# cat creakzipfile.py 
#!/usr/bin/python
#--*-- coding:utf-8 --*--

import zipfile
import optparse
from threading import Thread

def extractFile(zFile,password):
    try:
        zFile.extractall(pwd=password)
        print "[+] Found Pasword :" + password + "\n"
    except:
        pass

def main():
    #creakzipfile.py为脚本文件, 为破解zip文件, 为破解字典,都在同一目录下
    parser = optparse.OptionParser("[*] Usage: ./creakzipfile.py -f  -d ")
    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)

    zFile = zipfile.ZipFile(options.zname)
    passFile = open(options.dname)
    for line in passFile.readlines():
        line = line.strip("\n")
        t = Thread(target=extractFile,args=(zFile,line))
        t.start()

if __name__ == "__main__":
    main()

root@kali:~/python/anquangongji# 

4、脚本运行情况:
代码中导入了optparse库解析命令行参数,调用OptionParser()生成一个参数解析器类的示例,parser.add_option()指定具体解析哪些命令行参数,usage输出的是参数的帮助信息;同时也采用了多线程的方式提高破解速率。

运行结果:

root@kali:~/python/anquangongji# 
root@kali:~/python/anquangongji# clear
root@kali:~/python/anquangongji# python creakzipfile.py -f test.zip -d dictionaryzip.txt 
[+] Found Pasword :qwe123456

root@kali:~/python/anquangongji#

你可能感兴趣的:(pyhton开发,python,破解,zip)