zoukankan      html  css  js  c++  java
  • Python ZIP压缩文件破解

    # -*- coding:utf-8 -*-
    
    import zipfile
    import os
    import string
    import random
    
    
    class crackzip():
        def __init__(self, low=4, up=6):
            self.lownum = low
            self.upnum = up
            # 构造密码的字符串
            self.model = string.ascii_lowercase + '0123456789'
            # ZIP文件位置
            self.in_path = "C:\Users\10245\Desktop\test3.zip"
            # 解压位置
            self.out_path = "C:\Users\10245\Desktop\re\"
    
        def __iter__(self):
            return self
    
        def __next__(self):
            s = ''
            for i in range(random.randrange(self.lownum, self.upnum)):
                s += random.choice(self.model)
            return s
    
        def dict_zip(self):
            # 字典文档位置
            dic = "C:\Users\10245\Desktop\dict.txt"
            m = zipfile.ZipFile(self.in_path)
            names = [m.filelist[x].filename for x in range(len(m.filelist))]
            corr_name = []
            for name in names:
                corr_name.append(name.encode('cp437').decode('gbk'))
            with open(dic) as f:
                passwords = f.readlines()
            for password in passwords:
                try:
                    password = password.strip()
                    m.extractall(path=self.out_path, pwd=password.encode('utf-8'))
                    for n in range(len(names)):
                        os.rename(self.out_path + names[n], self.out_path + corr_name[n])
                    print ('[+][Success]文件:{0}  密码:{1}'.format(corr_name, password))
                    exit(0)
                except Exception as e:
                    print ('[-][Error]文件:{0}  密码:{1}'.format(corr_name, password))
    
        def str_zip(self):
            m = zipfile.ZipFile(self.in_path)
            # zip中的文件
            names = [m.filelist[x].filename for x in range(len(m.filelist))]
            corr_name = []
            sec_num1, sec_num2 = map(int, input('请输入密码位数范围:').split())
            for name in names:
                corr_name.append(name.encode('cp437').decode('gbk'))
            for password in crackzip(sec_num1, sec_num2):
                try:
                    password = password.strip()
                    m.extractall(path=self.out_path, pwd=password.encode('utf-8'))
                    for n in range(len(names)):
                        os.rename(self.out_path + names[n], self.out_path + corr_name[n])
                    print ('[+][Success]文件:{0}  密码:{1}'.format(corr_name, password))
                    exit(0)
                except Exception as e:
                    print ('[-][Error]文件:{0}  密码:{1}'.format(corr_name, password))
            m.close()
    
    
    if __name__ == '__main__':
        print ('''
        (1) 字典破解
        (2) 常用构造破解
        ''')
        m = crackzip()
        ch = int(input())
        if ch == 1:
            m.dict_zip()
        elif ch == 2:
            m.str_zip()

    字典破解,就是尝试常用密码文本中的密码。

    暴力破解,使用字符串构造密码,Python性能不咋样,所以没法直接构造全部密码,再一一尝试,用了迭代器,每次随机取值。

  • 相关阅读:
    systemtap分析软raid io拆分问题
    Profiling Java Application with Systemtap
    中国南方ORACLE用户组
    Docker 核心技术与实现原理
    The Internals of PostgreSQL
    Alone_Monkey 逆向IOS
    淘宝内核月报 2017
    Linux kernel engineer--trace
    你的按钮到底在帮助用户还是在误导用户?
    2020年值得你去试试的10个React开发工具
  • 原文地址:https://www.cnblogs.com/Mayfly-nymph/p/12728408.html
Copyright © 2011-2022 走看看