python脚本暴力破解压缩文件

import zipfile
import itertools

filename = '解压文件.zip'  # 文件名字


def uncompress(filename, password):  # 参数
    try:  # 如果解压成功返回true
        with zipfile.ZipFile(filename) as zfile:  # 使用zipfile模块中的zipfile函数打开文件filename作为zfile
            zfile.extractall("./", pwd=password.encode('utf-8'))  # extraxtall()对文件zifile文件第一个参数路径 ,与py脚本的相对路径,第二个参数解码格式
            return True
    except:  # 解压失败抛出异常
        return False


flog = 0
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'            # 列出所有密码可能的数字
le = len(chars) + 1
ch = [i for i in range(0, le)]  # 快速生成密码个数的可能性
for i in ch:
    for c in itertools.permutations(chars, i):  # itertools.permutations(chars,i) 在chars中的字符中选了六个列出所有组合
        password = "".join(c)  # 将列出的六位字符拼接起来
        result = uncompress(filename, password)
        if not result:
            print("解压失败", password)
        else:
            print('解压成功', password)
            flog = 1
        if flog == 1:
            break  # 解压成功后退出循环

  • 注意解压文件与python脚本的相对路径位置
  • 注意可以对密码的可能字符是未知,更具实际情况来修改脚本,中密码的可能字符

猜你喜欢

转载自blog.csdn.net/qq_53075298/article/details/120406620