zoukankan      html  css  js  c++  java
  • python使用密码本破解压缩文件(rar.zip)密码(本次为6位数字)

    转发链接:https://blog.csdn.net
    原文作者:平底锅锅锅

    参考链接:https://blog.csdn.net

    说明:好像只能破解zip格式,而且由rar转成zip的也不能破解...

    目录:

    一、生成密码本

    二、破解zip(已测试通过)

    三、破解rar(待更新)

    一、生成密码本

    f = open('sixPassdict.txt','w')
    for id in range(1000000):
        password = str(id).zfill(6)+'
    '
        f.write(password)
    f.close()

    二、暴力破解zip

    import sys
    import zipfile
    import rarfile
    import threading
    import datetime
    import os
    import subprocess
    import getopt
    
    i = 0
    fileGet = ""
    
    class MyThread(threading.Thread):
        def __init__(self, func, args, name=''):
            threading.Thread.__init__(self)
            self.name = name
            self.func = func
            self.args = args
            self.result = self.func(*self.args)
    
        def get_result(self):
            try:
                return self.result
            except Exception:
                return None
    
    
    def extractFile(fileExtr, password, fileType):
        try:
            encodestr = str.encode(password)
            if (fileType == "zip"):
                fileExtr.extractall(pwd=str.encode(password))
            else:
                fileExtr.extractall(pwd=password)
            global i
            i = i + 1
            print("search count : %d,real password is : %s" % (i, password))
            return password
        except:
            i = i + 1
            print("search count : %d,test password : %s, err:%s" % (i, password, sys.exc_info()[0]))
            pass
    
    
    def mainStep():
        path = input("please input path:")
        #输入方式如:F:desktop123456001.zip
    
        try:
            if os.path.exists(path) == False:
                print("%s : path error!" % (path))
                return
            type = os.path.splitext(path)[-1][1:]
            if type == "zip":
                fileGet = zipfile.ZipFile(path)
                with fileGet as z:
                    for l in z.infolist():
                        is_encrypted = l.flag_bits & 0x1
                        if is_encrypted:
                            print("have password ")
                            break
                        else:
                            pass
                fileGet = zipfile.ZipFile(path)
    
            elif type == "rar":
                fileGet = rarfile.RarFile(path)
                with fileGet as z:
                    if z.needs_password():
                        print("have password ")
                    else:
                        print("no password")
                        return
            else:
                print("file not right")
                return
    
            pwdLists = open("D:File_GitPythonXdd破解压缩包密码sixPassdict.txt")
            startTime = datetime.datetime.now()
    
            for line in pwdLists.readlines():
                Pwd = line.strip('
    ')
                t = MyThread(extractFile, (fileGet, Pwd, type))
                t.start()
                if (t.get_result() is Pwd):
                    break
            endTime = datetime.datetime.now()
            timeSpan = endTime - startTime
            print("search time:%ss" % (timeSpan.total_seconds()))
    
        except:
            print("err:%s" % sys.exc_info()[0])
    
    
    if __name__ == '__main__':
        mainStep()

    转载仅为学习,不会商用。
    欢迎转载原创,附文链接。
  • 相关阅读:
    centos 7 配置 keepalived,主机高可用
    centos 7 安装 nginx
    windows10 设置虚拟网卡/ip
    c#程序以管理员权限运行
    关于js中属性那些事
    centos 7 问题集锦
    几个Git仓库开源软件的比较
    grpc proto3 初体验
    windows下maven安装配置(本地仓库配置)
    navicat premium patch/keygen instruction
  • 原文地址:https://www.cnblogs.com/xdd1997/p/12594734.html
Copyright © 2011-2022 走看看