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

    转载仅为学习,不会商用。
    欢迎转载原创,附文链接。
  • 相关阅读:
    Go实现常用软件设计模式二:工厂模式
    Go实现常用软件设计模式一:单例模式
    单调栈的介绍以及一些基本性质
    Go实现常用软件设计模式三:生成器模式
    gin领域层:用户实体编写和值对象(初步)
    gin巧用Context传递多种参数
    依赖倒置原则(DIP)
    领域层:用户实体和值对象(2)构造函数
    div嵌套多个点击事件,点击后如何阻止多次事件触发冒泡
    MySQL自娱—7.DDL语言
  • 原文地址:https://www.cnblogs.com/xdd1997/p/12594734.html
Copyright © 2020-2023  润新知