admin管理员组文章数量:1632315
前言
最近老是遇到一些加密的压缩包,还不给密码……其中最过分的就是Adobe Audition CC贴吧吧主分享盗版软件压缩版,还搞收费,交钱才能知道解压密码,这操作真是秀到我了……
话不多说,直接开始尝试暴力破解
源码
###
# Winrar 加密: 源文件压缩成数据段;将数据段加密
# 对于同一个源文件而言,不加密,只压缩获取的数据段是一样的;
# 但加密时,就算密码一致加密完rar文件的数据段是不一样的,这是由于加密的密钥依赖于一个Salt(8字节的密钥,用来加密时使用,存放在rar文件头中)
# 加密流程: 将明文密码与salt一起,通过HASH算法,生成两个16字节的密钥(AES参数和initVector) 循环加密
# 解密流程: 将解密后的数据块进行解压缩,然后解压成源文件,对该文件进行CRC校验,存在rar文件中的源文件CRC校验码比较,相同则密码正确,不相同则密码错误
import threading
from unrar import rarfile
import zipfile
import os
import itertools
import sys
import time
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("file")
parser.add_argument("extract")
def decode_rar(rar_file, pwd, extract_path):
try:
rar_file.extractall(extract_path, pwd = pwd)
except:
#print('wrong')
pass
else:
print('password is', pwd)
sys.exit(0)
def decode_zip(zip_file, pwd, extract_path):
try:
zip_file.extractall(extract_path, pwd=pwd)
except:
#print('wrong')
pass
else:
print('password is', pwd)
sys.exit(0)
def create_pwd(words, repeatNum):
dict = itertools.product(words, repeat = repeatNum)
with open('./password.txt', 'w') as f:
for it in dict:
f.write(''.join(it) + '\n')
def get_pwd():
with open('./password.txt','r') as f:
for pwd in f:
yield pwd.strip()
def main(file, extract_path):
# 创建密码
if not (os.path.exists('./password.txt')):
create_pwd('./password.txt')
pwds = get_pwd()
suffix = os.path.splitext(file)[1][1:]
if suffix == 'zip':
zip_file = zipfile.ZipFile(file, 'r')
for pwd in pwds:
t = threading.Thread(target=decode_zip, kwargs={'zip_file': zip_file, 'pwd': pwd, 'extract_path': extract_path})
t.start()
elif suffix == 'rar':
rar_file = rarfile.RarFile(file)
for pwd in pwds:
t = threading.Thread(target=decode_rar, kwargs={'rar_file': rar_file, 'pwd': pwd, 'extract_path': extract_path})
t.start()
else:
print("暂不支持该格式")
if __name__ == '__main__':
args = parser.parse_args()
start_time = time.time()
#密码创建 默认为4位纯数字
create_pwd('1234567890', 4)
print('create password time: %fs' % (time.time() - start_time))
main(args.file, args.extract)
print('run time: %fs' % (time.time() - start_time))
使用方法
python myunrar.py 压缩文件路径 解压路径
另外,密码需要自己改。
改create_pwd(‘1234567890’, 4)就好了, 第一个参数为密码的字符构成,第二个参数为密码位数,这是做排列组合的,因此字符构成中不需要出现重复字符。
感想
遇到加密者用中文加密,或者位数很长的密码,着实难以破解,毕竟现在只能通过遍历密码尝试暴力破解。
或许了解了加密原理,可以找到巧妙的破解方法,降低时间复杂度O(N)
版权声明:本文标题:暴力破解rar和zip加密压缩包 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729115126a1187227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论