下边代码包含了暴力破解,使用字典破解zip的密码
from zipfile import ZipFile
import os
from tqdm import tqdm
def passwd(path, pwd):
# 获取文件的后缀名
suffix_name = os.path.splitext(path)[-1][1:]
# print(suffix_name)
# 如果是zip文件
if suffix_name == 'zip':
# 开始读zip文件
with ZipFile(path, 'r') as zip:
# print("当前尝试的密码是:%s"%(pwd))
# 解压到指定文件目录下
try:
# print(pwd.encode('utf-8'))
zip.extractall("./target", pwd=pwd.encode('utf-8'))
print("解压成功,密码是:%s"%(pwd))
return True
except Exception as e: # 添加一个异常处理
pass
def create_pwd(words,i):
# 通过导入这包来设置枚举序列
import itertools as its
# 设置基础需要枚举的字符集
# 这个base的意思就是把words集合的字符取repeat次组合
# 打印出来
base = its.product(words, repeat=i)
# 一般需要把这个打印函数注释 因为这个函数运行很消耗时间的
for i in base:
# print(''.join(i))
yield ''.join(i) # 把这个函数制作成一个迭代器
if __name__ == '__main__':
dir = "./20.zip"
words = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+."
#使用暴力破解,最高9位数密码
for i in range(1, 9):
pwd = create_pwd(words, i)
for p in pwd:
flag = passwd(dir, p)
if flag == True:
break
#使用字典
# with open("1.txt", "r") as f:
# for line in tqdm(f):
# line = line.strip()
# flag = passwd(dir, line)
# if flag == True:
# break
点击访问博客查看更多内容 |
---|