用python编写渗透工具下载_Python编写渗透工具学习笔记一 | 0x06 Zip包破解程序

0x06 Zip包破解程序

介绍zipfile的使用

实现思路:

从密码文件中读取密码,然后逐个尝试去破解压缩包

主要使用zipfile库的extractall()方法,其中pwd参数指定密码

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

工具源码:#!/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 password ' + password + '\n'

except:

pass

def main():

parser = optparse.OptionParser("usage %prog "+\

"-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)

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值