老是忘记rar文件设置的密码,于是乎网上找到了一篇不错的文章。py暴力破解。<部分摘抄>
from unrar import rarfileimport osimport itertools as itsimport timefrom concurrent.futures import ThreadPoolExecutordef get_pwd(file_path, output_path, pwd):'''判断密码是否正确:param file_path: 需要破解的文件路径,这里仅对单个文件进行破解:param output_path: 解压输出文件路径:param pwd: 传入的密码:return:'''# 传入被解压的文件路径,生成待解压文件对象file = rarfile.RarFile(file_path)# 输出解压后的文件路径out_put_file_path = 'rar/{}'.format(file.namelist()[0])file.extractall(path=output_path, pwd=pwd)try:# 如果发现文件被解压处理,移除该文件os.remove(out_put_file_path)# 说明当前密码有效,并告知print('Find password is "{}"'.format(pwd))return Trueexcept Exception as e:# 密码不正确print('"{}" is nor correct password!'.format(pwd))# print(e)return Falsedef get_password(min_digits, max_digits, words):"""密码生成器:param min_digits: 密码最小长度:param max_digits: 密码最大长度:param words: 密码可能涉及的字符:return: 密码生成器"""while min_digits <= max_digits:pwds = its.product(words, repeat=min_digits)for pwd in pwds:yield ''.join(pwd)min_digits += 1file_path = 'rar/test.rar'output_path = 'rar'# 密码范围# words = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' # 涉及到生成密码的参数words = '01a'pwds = get_password(4, 4, words)# 开始查找密码start = time.time()while True:pwd = next(pwds)if get_pwd(file_path, output_path, pwd=pwd):breakend = time.time()print('程序耗时{}'.format(end - start))
😁 作者:Teddy (公众号:鸡仓故事汇)
ok!到这里就大功告成,小编(Teddy)在这里先感谢大家的到来。
虽然不是太详细,小编已经很努力,给小编来个一键三连(点赞,关注,收藏),小编会越来越努力。。。