Python破解加密的zip文件
测试环境
环境 | 版本 |
---|---|
系统 | uos |
Python版本 | Python3 |
创建一个.zip格式的压缩文件并且设置压缩密码,这里设置密码为:123654
运行Python代码破解压缩密码,破解需要用到一个密码字典,代码引自原来Python破解受密码保护的zip文件这么简单,不担保一定成功
import zipfile
from tqdm import tqdm
wordlist = "/home/uos/Desktop/wordlists/rockyou.txt" #密码字典路径
zip_file = "/home/uos/Desktop/package.zip" #压缩文件路径
zip_file = zipfile.ZipFile(zip_file)
n_words = len(list(open(wordlist, 'rb')))
print("total passwords to test:", n_words)
with open(wordlist, "rb") as wordlist:
for word in tqdm(wordlist, total=n_words, unit="word"):
try:
zip_file.extractall(pwd=word.strip())
except:
continue
else:
print("[+] Password found: ", word.decode().strip())
exit(0)
print("[!] Password not found, try other wordlist!")
成功破解后输出结果
/home/uos/PycharmProjects/pythonProject1/venv/bin/python /home/uos/PycharmProjects/pythonProject1/main.py
total passwords to test: 14344392
0%| | 297/14344392 [00:00<15:09, 15765.07word/s]
[+] Password found: 123654
Process finished with exit code 0
- 密码字典如何获取
可以在kali系统的/usr/share/wordlists
目录下拷贝一份到uos系统中或者百度rockyou.txt文件 - 运行代码报错,没有zipfile模块
打开终端执行pip3 install zipfile
安装zip模块 - 是否可以100%破解
破解速度与成功率和压缩密码的长度和复杂度有关,简单密码比较容易破解,复杂密码破解时间比较长甚至会破解失败