python快速破解zip压缩文件
原创目录
3、itertools.permutations实现全字全排。
前言:
在日常工作中,你会遇到一些加密的zip文件,但由于某些原因或时间太长,密码不知道。
但是zip文件中的文件是非常重要和必要的。那么,让我们来试试万能的Python,暴力破解密码。
一、破解zip加密文件的想法:
1,准备一个加密的zip文件。
2、zipfile该该模块可以解压缩缩zip文件。
解压时可提供密码zfile.extractall("./", pwd=password.encode("utf8"))
3、itertools.permutations实现全字全排。
通过函数itertools.permutations("abc", 3)实现全字全排:abc/acb/bca/bac/cab/cba
2.实用代码:
1,实现解压缩zip文件:
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
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该文件可能知道密码是4比特,这个角色大致是a-z1-0。而且没有重复的字符,就不会有aabb“密码。
zip当加压时,它被选中了。zip传统加密!
3.几个密码可能在不知情的情况下被破解:
我查了一些信息,zip加密程度最高的密码是12位,则可以按如下方式修改程序:
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
添加上一个for循环。
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除