测试压缩文件1.zip,密码本:password.txt
import zipfile
#pip3 install rarfile
import rarfile
import threading
import itertools as its
# 判断线程是否需要终止
flag = True
words = '0123456789abcdefghijklmnopqrstuvwxyz' # 涉及到生成密码的参数
# 生成密码字典
def get_password(min_digits, max_digits, words):
"""
:param min_digits: 密码最小长度
:param max_digits: 密码最大长度
:param words: 密码可能涉及的字符
:return: 密码生成器
"""
while min_digits <= max_digits:
pwds = its.product(words, repeat=min_digits)
for pwd in pwds:
yield ''.join(pwd)
min_digits += 1
def extract(password, file):
try:
PWD = str(password)
file.extractall(pwd=PWD.encode()) # zip解压缩
# file.extractall(pwd=password)#rar解压缩
print("压缩包的密码是:{}".format(password))
global flag
flag = False
except Exception:
print(Exception)
pass
def main():
file = zipfile.ZipFile("./1.zip") # 压缩文件
# file = rarfile.RarFile("pwd.rar")
passwords = open('password.txt', encoding="utf-8") # 密码字典
for line in passwords.readlines(): # 逐行读取密码
if flag is True:
password = line.strip('\n') # 去掉回车
t = threading.Thread(target=extract, args=(password, file))
t.start() # 开始
t.join() # Parent父线程会等待child子线程运行完再继续运行
if __name__ == '__main__':
main()
很多人破解都发现失败,查资料知道,破解只能单纯破解传统加密方式的zip,rar包,直接加密加密的不能进行破解,是由于两种加密方式不同,zipfile里没有提供AES-256(直接加密) 的破解算法