900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 0043__暴力破解rar和zip加密压缩包

0043__暴力破解rar和zip加密压缩包

时间:2019-07-30 12:52:16

相关推荐

0043__暴力破解rar和zip加密压缩包

1、/qq_39985298/article/details/106683514?utm_medium=distribute.pc_relevant.none-task-blog-title-5&spm=1001.2101.3001.4242

2、/ysy950803/article/details/52939708

###

# 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))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。