1、打开压缩软件,新建压缩文件,这里使用Bandizip;
2、点击添加或将文件拖进来,点击设置密码-输入密码-开始压缩;
zipcrack.py代码如下(示例):
# -*- encoding = 'utf-8' -*-
import zipfile
import optparse
def extractFile(zFile,password):
"""
解压函数
"""
try:
zFile.extractall(pwd=password.encode('utf-8'))
print('[+] Password = ' + password + '\n')
return True
except:
return
def main():
parser = optparse.OptionParser("usage:" + "-f -d " )
parser.add_option('-f', dest='zname', type='string', help='specify zip file')
parser.add_option('-d', dest='dname', type='string', help='Password dictionary')
(options, args) = parser.parse_args()
if(options.zname == None) | (options.dname == None):
print(parser.usage)
exit(0)
else:
zname = options.zname
dname = options.dname
zFile = zipfile.ZipFile(zname)
try:
passFile = open(dname, 'r', )
with open(dname, 'r', encoding = 'utf-8') as passFile:
for line in passFile.readlines():
password = line.strip('\n')
flag = extractFile(zFile, password)
if flag:
print('爆破成功')
break
except Exception:
print('错误输入')
if __name__ == '__main__':
main()
运行命令如下:
python zipcrack.py -f file.zip -d password.txt
import time
from typing import List
from tqdm import tqdm
from itertools import chain
from zipfile import ZipFile
start = time.time()
# chr(97) -> 'a' 这个变量保存了密码包含的字符集
dictionaries = [chr(i) for i in
chain(range(97, 123), # a - z
range(65, 91), # A - Z
range(48, 58))] # 0 - 9
#dictionaries.extend(['.com', 'www.']) # 添加自定义的字符集
#dictionaries = [chr(i) for i in range(48, 58)] # 0 - 9
file_name = "hello.zip"# 你的文件路径
def all_passwd(dictionaries: List[str], maxlen: int):
# 返回由 dictionaries 中字符组成的所有长度为 maxlen 的字符串
def helper(temp: list, start: int, n: int):
# 辅助函数,是个生成器
if start == n: # 达到递归出口
yield ''.join(temp)
return
for t in dictionaries:
temp[start] = t # 在每个位置
yield from helper(temp, start + 1, n)
yield from helper([0] * maxlen, 0, maxlen)
zfile = ZipFile(file_name, 'r') # 很像open
def extract(zfile: ZipFile, pwd: str) -> bool:
# zfile: 一个ZipFile类, pwd: 密码
try:
zfile.extractall(path='.', pwd=pwd.encode('utf-8')) # 密码输入错误的时候会报错
now = time.time() # 故使用 try - except 语句
print(f"Password is: {pwd}") # 将正确的密码输出到控制台
return True
except:
return False
# 用 bool 类型的返回值告诉主程序是否破解成功 (意思就是返回 True 了以后就停止)
#lengths = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] # 密码长度
lengths = [4] # 密码长度
total = sum(len(dictionaries) ** k for k in lengths) # 密码总数
for pwd in tqdm(chain.from_iterable(all_passwd(dictionaries, maxlen) for maxlen in lengths), total=total):
if extract(zfile, pwd): # 记得extract函数返回的是bool类型的哦
break
pip3 install tqdm==4.50.2
安装好后,运行破解脚本即可!
分享:
想像力比知识更重要。因为知识是有限的,而想像力是无限,它包含了一切,推动着进步,是人类进化的源泉。——爱因斯坦