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

  • 相关阅读:
    ruby计算平方和开方
    Silverlight中DataGrid翻页或者滚动时CheckBox/RadioButton显示的问题
    bat文件设置ip地址
    gcc编译多线程
    TCP Nagle算法
    fork父子进程 信号处理
    Unix守护进程的创建示例
    inline内联函数
    volatile类型
    ioctl获取接口名称、IP地址、MAC地址、广播地址等
  • 原文地址:https://www.cnblogs.com/dudeyouth/p/6111834.html
Copyright © 2020-2023  润新知