python zip暴力破解

首先我们要导入三个模块
zipfile zip模块
optparse 解析命令行选项模块
threading 线程模块

parser = optparse.OptionParser(‘xxxxx’)
这个是定义好optparse模块

add_option(‘-f’, dest=’zname’, type=’string’,\
help=’specify zip file’)

  '-f' 是设定的一个命令参数 
  dest='zname'   这个代表的是我们在获取命令行值的属性
  例如 :运行zippass.py -f opti
  print options.zname
  结果为:opti

(options, args) = parser.parse_args()
print options
结果为:{zname:opti} 这是一个对象
我们通过判断这个用户是否输入过相对应内容
然后通过判断,只要有其中一个命令参数不存在 , 我们就退出程序
if (options.zname == None) | (options.dname == None):
exit(0)

 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

我们通过zipfile.ZipFIle(zname)导入压缩包
zname 就是我们在-f eval.zip 这个内容
通过命令行参数,我们在这里设定-f 的内容为压缩包的名称

我们通过open(dname) 打开字典文件
这个dname的值就是 -d dictionary.txt 这个内容
然后通过for line in passFile.readlines(): 来循环字典进行破解
Thread()方法是线程的一个方法.
target=extractFile 这个是方法名
args=(zFile,password) 这个是方法参数
t.start() 启动线程

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

这个是最重要的一部分,开始破解.
通过接受到的参数 zFile password
zFile.extractall(pwd=password) 开始尝试参数, 是否是压缩包密码.
如果是就找到显示的密码
如果不是就进入
except:
pass

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

这个是最后运行的结果
这里写图片描述
程序源码连接:https://pan.baidu.com/s/1boQGHIn

#!/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 <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()
要使用Python破解zip文件,可以使用zipfile模块提供的解压缩功能。首先,你需要导入zipfile模块。然后,使用ZipFile()函数打开需要解压缩的zip文件,并指定打开模式为读取模式。接下来,你可以使用extractall()函数将zip文件中的所有文件解压缩到指定的目录中。以下是一个示例代码,展示了如何使用Python破解zip文件: ```python import zipfile zip_file = zipfile.ZipFile('example.zip', 'r') zip_file.extractall() zip_file.close() ``` 在这个示例中,我们假设有一个名为example.zipzip文件需要解压缩。首先,我们使用ZipFile()函数打开这个zip文件,并将其赋值给zip_file变量。然后,我们使用extractall()函数将zip文件中的所有文件解压缩到当前目录下。最后,我们使用close()函数关闭zip文件。 请注意,这只是一个示例代码,你需要根据实际情况修改文件名和路径。同时,为了成功破解zip文件,你可能需要提供相应的破解算法或密码字典。具体的破解过程可能因破解目标的不同而有所差异。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [python 暴力破解zip文件](https://blog.csdn.net/qq_51768842/article/details/125323094)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Python实现解压缩Zip文件(附完整源代码)](https://blog.csdn.net/CodeWG/article/details/131076338)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值