如何利用python破解zip加密文件
作者:??蓝星部队???? 时间:2022-11-27 17:51:30
前言:
日常工作中,会遇到一些加密的zip文件,但是因为某些原因或者时间过长,密码不知道了。但是zip文件中文件有很重要很必须。那么,我们试一试万能的Python,暴力破解密码。
一、破解zip加密文件的思路
准备一个加密的zip文件。
zipfile模块可以解压zip文件。
解压时可以提供密码zfile.extractall("./", pwd=password.encode("utf8"))
itertools.permutations实现全字符的全排列。
通过函数itertools.permutations("abc", 3)实现全字符的全排列:abc/acb/bca/bac/cab/cba
二、实例代码演示
0、zip的压缩方式
本文介绍的zip文件知道密码一共是4位的,密码字符的范围是a-z1-0。并且不存在重复字符的,不会有“aabb”的密码。zip压缩时是选择了zip传统加密!
1、解压zip文件
导入zipfile模块,使用其中的extractall()函数。
import itertools
filename = "readme.zip"
# 创建一个解压的函数,入参为文件名和密码
# 并使用try-except,避免报错中断程序。
def uncompress(file_name, pass_word):
try:
with zipfile.ZipFile(file_name) as z_file:
z_file.extractall("./", pwd=pass_word.encode("utf-8"))
return True
except:
return False
2、实现密码字符的全排列
import zipfile
import itertools
filename = "readme.zip"
# 创建一个解压的函数,入参为文件名和密码
# 并使用try-except,避免报错中断程序。
def uncompress(file_name, pass_word):
try:
with zipfile.ZipFile(file_name) as z_file:
z_file.extractall("./", pwd=pass_word.encode("utf-8"))
return True
except:
return False
# chars是密码可能的字符集
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
for c in itertools.permutations(chars, 4):
password = ''.join(c)
print(password)
result = uncompress(filename, password)
if not result:
print('解压失败。', password)
else:
print('解压成功。', password)
break
文件压缩时,一些注意的事项:
三、密码是几位未知,也可以破解密码
查过一些资料,zip压缩文件密码最长为12位,在原来的程序上增加上一个for循环就可以实现破解密码了。
import zipfile
import itertools
filename = "readme.zip"
def uncompress(file_name, pass_word):
try:
with zipfile.ZipFile(file_name) as z_file:
z_file.extractall("./", pwd=pass_word.encode("utf-8"))
return True
except:
return False
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
for i in range(12):
for c in itertools.permutations(chars, i):
password = ''.join(c)
print(password)
result = uncompress(filename, password)
if not result:
print('解压失败。', password)
else:
print('解压成功。', password)
break
来源:https://juejin.cn/post/7091925727817236488
标签:python,破解,zip,加密,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
深入解析MySQL索引的原理与优化策略
2024-01-19 02:29:02
python中使用百度音乐搜索的api下载指定歌曲的lrc歌词
2023-06-14 06:23:07
使用Python写一个量化股票提醒系统
2022-04-19 14:35:42
![](https://img.aspxhome.com/file/2023/0/65890_0s.jpg)
Python Flask-Login实现用户会话管理
2023-06-05 13:13:50
![](https://img.aspxhome.com/file/2023/9/90589_0s.png)
怎样保存模型权重和checkpoint
2023-04-12 00:45:00
![](https://img.aspxhome.com/file/2023/1/67741_0s.jpg)
Python request设置HTTPS代理代码解析
2023-01-15 00:48:24
Python数据结构与算法中的栈详解(3)
2022-01-19 14:38:24
![](https://img.aspxhome.com/file/2023/4/67384_0s.png)
机器学习的框架偏向于Python的13个原因
2023-09-28 06:24:42
![](https://img.aspxhome.com/file/2023/8/112008_0s.jpg)
python 实现围棋游戏(纯tkinter gui)
2023-11-23 16:13:04
![](https://img.aspxhome.com/file/2023/4/92074_0s.gif)
MYSQL各字段的长度是多少?
2009-10-28 18:32:00
Python 数据化运营之KMeans聚类分析总结
2023-11-13 02:27:26
![](https://img.aspxhome.com/file/2023/4/97404_0s.png)
SQL脚本语言学习(黑客篇)
2008-02-29 13:09:00
python中doctest库实例用法
2022-07-22 16:52:30
go zero微服务实战性能优化极致秒杀
2023-06-17 03:45:30
![](https://img.aspxhome.com/file/2023/4/86304_0s.jpg)
7分钟读懂Go的临时对象池pool以及其应用场景
2024-02-05 17:22:17
Python爬虫实战之网易云音乐加密解析附源码
2022-08-28 04:03:58
![](https://img.aspxhome.com/file/2023/5/134915_0s.png)
详解Node.js读写中文内容文件操作
2024-05-03 15:55:07
提升设计品质的8个布局方案[译]
2010-03-18 16:06:00
![](https://img.aspxhome.com/file/UploadPic/20103/18/01-33s.jpg)
Django如何实现RBAC权限管理
2021-05-20 19:14:27
![](https://img.aspxhome.com/file/2023/1/103361_0s.png)
浅谈Keras参数 input_shape、input_dim和input_length用法
2021-02-19 13:24:40