Python爆破Zip密码
涂寐 Lv5

声明:文中所涉及的技术、思路和工具仅供以安全为目的的学习交流使用,任何人不得将其用于非法用途以及盈利等目的,否则后果自行承担!
本文首发于涂寐’s Blogs:http://localhost:4000/article/49fe31ad.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project :python黑客
@File :Zip压缩包爆破.py
@IDE :PyCharm
@Author :涂寐
@Date :2022/2/24 0:01
"""

from pyzipper import ZipFile, AESZipFile


# 文件存在性检测
def exist(filename):
try:
with open(filename, 'r') as fp:
fp.close()
except:
print(filename + ' 文件不存在!!!')
exit(0)


# 读取字典
def read_dicts(filename):
# 打开压缩包,存入字典
with open(filename, 'r') as fp:
# strip() :默认删除开头或末位的空格|换行符
# readlines() :读取所有行(直到结束符 EOF)并返回列表
# 使用列表解析,对列表中读取到的每一行首尾去换行,更快捷的生成新的列表
dicts = [pwd.strip('\n') for pwd in fp.readlines()]
fp.close()
return dicts
return Falsh


# 单例解密
def case(zip_file, pwd):
try:
zip_file.extractall(pwd=str.encode(pwd))
print('滴!您得到一枚密码:' + pwd)
return 1
except Exception as e:
pass


# 爆破
def blast(zip_file, dicts):
for pwd in read_dicts(dicts):
if case(zip_file, pwd) == 1:
exit(0)


def main(dict_file, zip_file):
# 存在性检测
exist(dict_file)
exist(zip_file)

# Zip Crypto 算法加密的 zip 压缩包
open_zip = ZipFile(zip_file)
# 调用爆破方法
blast(open_zip, dict_file)
# 关闭压缩包
open_zip.close()

# AES-256 算法加密的 zip 压缩包
# 安装 pip install pyzipper
open_zip = AESZipFile(zip_file)
blast(open_zip, dict_file)
open_zip.close()


if __name__ == '__main__':
# 字典
dict_file = './makings/1dicts.txt'
# zip 压缩包
zip_file = './test_8606.zip'

main(dict_file, zip_file)

 评论