python zip文件密码爆破

本文介绍了一个使用Python编写的ZIP文件密码破解程序。该程序通过读取字典文件中的密码尝试解锁指定的ZIP文件,并支持单线程及多线程破解方式。文章还讨论了密码编码及线程同步的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/env
# coding=UTF-8
import zipfile
import threading
import os
import sys
class CrackZip:
    def __init__(self):
        self._result = None
    def run(self,zFile,password):
        try:
            zFile.extractall(pwd=password)
            print("Found Passwd:",password)
            print('Password=',password)
            self._result=password
        except:
            pass
    def getPass(self):
        return self._result

def checkFile(path):
    flag=False
    if not os.path.isfile(path):
        flag=False
        print('[-] %s文件不存在',path)
    return flag
def main():
    cz=CrackZip()
    if len(sys.argv)>=3:
        zipPath=sys.argv[1]
        dictionaryPath=sys.argv[2]
        flag=(len(sys.argv)>3 and sys.argv[3]=='-t')
        typeName=None
        if not checkFile(dictionaryPath):
            if dictionaryPath[-3:]!='txt':
                print('字典不是txt文件')
                return
        if not checkFile(zipPath):
            if zipPath[-3:]!='zip':
                print('只能爆破zip文件')
                return
        zFile=zipfile.ZipFile('test.zip','r')
        passFile=open(dictionaryPath,'r')
        for line in passFile.readlines():
            password=line.strip('\n').encode('utf-8')
            if flag:
                False
                t=threading.Thread(target=cz.run,args=(zFile,password))
                t.start()
            else:
                cz.run(zFile,password)
                password=cz.getPass()
                typeName='SingleThread'
                if password:
                    return
        if typeName=='SingleThread':
            print("字典里找不到密码")
    else:
        print('命令不正确,格式为:python zip.py zipPath dictionaryPath')
        return
if __name__=='__main__':
    main()
        

 

遇到了以下问题:

  1. 字典里获取出来的字符需要编码(utf-8)才能被extractall识别  

  2. 开启线程爆破后如何检测所有线程执行完毕?(提示爆破失败)

 

转载于:https://www.cnblogs.com/dudeyouth/p/6111834.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值