zoukankan      html  css  js  c++  java
  • python zip文件密码爆破

    #!/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('
    ').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. 开启线程爆破后如何检测所有线程执行完毕?(提示爆破失败)

  • 相关阅读:
    k8s使用
    7月3日课堂笔记
    7月6日课堂笔记
    画倒三角形
    6月29日课堂笔记
    understand试用笔记一阅读VS2010项目
    Spring Boot 入门(九)使用RabbitMQ
    Spring Boot 入门(十一)使用Schedule
    Spring Boot 入门(十三)使用Elasticsearch
    学习MySQL
  • 原文地址:https://www.cnblogs.com/dudeyouth/p/6111834.html
Copyright © 2011-2022 走看看