利用python破解zip压缩文件密码 您所在的位置:网站首页 zip文件解压密码一般是多少位数 利用python破解zip压缩文件密码

利用python破解zip压缩文件密码

2024-06-03 14:51| 来源: 网络整理| 查看: 265

在日常工作生活中,可能会遇到压缩文件后忘记解压密码的情况,也许你大概知道密码构成及位数,一个一个手动输入的试密码显然很麻烦,那么利用程序自动测试密码就非常方便

目录 zip密码字典破解报错处理 zip密码排列破解Excel密码排列破解

zip密码字典破解

1,新建一个zip压缩文件(破解测试.zip),设置密码为123456或987654

2,创建一个txt文件(密码字典.txt),保存可能的密码

from itertools import permutations def password_txt(): filename = r'E:\测试\密码字典.txt' with open(filename, 'w', encoding='utf-8') as file: # 写入数字10选6所有排列151200种 str_n = '0123456789' for i in permutations(str_n, 6): file.write('{}\n'.format(''.join(i))) print('所有排列写入完成') if __name__ == '__main__': password_txt()

3,编写python破解代码

import zipfile from threading import Thread from time import time i = 0 pwd_return = None # 多线程返回值,正确的密码 def extractfile(zfile, password): # 密码破解函数 try: zfile.extractall(pwd=bytes(password, 'utf8')) print('文件解压密码为: ', password) global pwd_return pwd_return = password return True except: return False # 以下为测试使用 #global i #i = i + 1 #print('密码错误第{}次\n'.format(i)) def extract1(): # 直接破解 start_time = time() zip_file = r'E:\测试\破解测试.zip' pass_file = r'E:\测试\密码字典.txt' zfile = zipfile.ZipFile(zip_file) pfile = open(pass_file) for line in pfile.readlines(): # 按行读取密码 pwd = line.strip('\n') if extractfile(zfile, pwd): # 直接调用函数,非多线程 print('密码{},用时{:.2f}秒'.format(pwd, time()-start_time)) break # 跳过剩余密码 def extract2(): # 多线程破解 start_time = time() zip_file = r'E:\测试\破解测试.zip' pass_file = r'E:\测试\密码字典.txt' zfile = zipfile.ZipFile(zip_file) pfile = open(pass_file) for line in pfile.readlines(): pwd = line.strip('\n') t = Thread(target=extractfile, args=(zfile, pwd)) # 运用子进程加快运行 t.start() if pwd_return != None: break # 跳过剩余密码 print('密码{},用时{:.2f}秒'.format(pwd_return, time()-start_time)) if __name__ == '__main__': extract1()

4,测试结果 测试数字10选6所有排列151200种密码

密码extract1()耗时(秒)extract2()耗时(秒)第17047行密码1234561.763.2第151200行密码98765410.8628.76

可以发现多线程并没有什么作用;测试过程中还发现,在不使用多线程时CPU占用 0 else 0 count_e = num*piece if num > 0 else count_max if count_s > count_max: print('超出范围,最大排列数为{}'.format(count_max)) return for i in permutations(str_n, m): if count >= count_s and count



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有