python - 检查 .rar 文件密码的最快方法 - 除了 rarfile extractall
问题描述
所以我根据教程编写了一个小 .rar 密码“破解器”,使用下面的代码。它工作正常,但是当文件很大时非常慢。我能找到的最好理由是,当您输入错误的密码时,它经常会在拒绝密码之前提取整个文件。小文件不是什么大问题,但大文件会大大减慢处理速度。
有没有办法根据迭代哈希检查密码的哈希版本?
import itertools
import rarfile
import time
rarfile.UNRAR_TOOL = "path"
rar = rarfile.RarFile("path")
done = False
n = 0
inputList = ["A","B","1","2"]
class h():
startword = ""
rep = 1
start = 0
itrTot = 0
f = open("save.txt")
for x,each in enumerate(f):
if x == 0:
h.rep = int(each)
else:
h.start = int(each)-3
f.close()
if h.start < 0:
h.start = 0
h.itrTot = len(inputList)**h.rep
def pw_guess():
res = itertools.product(inputList, repeat=h.rep)
for guess in res:
yield guess
start_time = time.time()
while True:
guess_generator = pw_guess()
for guess in guess_generator:
n += 1
if h.startword == "":
h.startword = guess
else:
if guess == h.startword:
h.rep += 1
n = 0
h.itrTot = len(inputList)**h.rep
h.start = 0
print("next rotation, itr rep: "+str(h.rep))
h.startword = ""
break
if n < h.start:
continue
txt = f"({n}/{h.itrTot}, {round((100/h.itrTot)*n,2)}%) - {h.rep}: {''.join(guess)}"
print(txt)
try:
rar.extractall(path="path",members=None,pwd=''.join(guess))
print("Pass found!")
print(str(n) + " - " + str(h.rep) + ": " + str(''.join(guess)))
done = True
txt2 = f"({n}/{h.itrTot}, {round((100/h.itrTot)*n,2)}%) - {h.rep}: {''.join(guess)}\n"
f = open("pass.txt", "a")
f.write(txt2)
f.close()
break
except:
f = open("save.txt", "w")
f.write(str(h.rep) + "\n" + str(n))
f.close()
if done:
end_time = time.time()
break
print("End time: " + str(end_time-start_time))
解决方案
开膛手约翰就是答案。在 2 分钟内检查了 +20k 个密码。但是使用部分脚本生成单词表,仍然非常快速且功能强大。
我使用的单词表生成器:
import itertools
inputList = ["A","B","C","D","1","2","3","4","5"]
itr = 7
WL_path = "path"
f = open(WL_path,"w")
f.write("")
f.close()
class h():
startword = ""
rep = 1
itrTot = 0
txt = ""
h.itrTot = len(inputList)**itr
print("Wordlist length: " + str(h.itrTot))
def pw_guess():
res = itertools.product(inputList, repeat=h.rep)
for guess in res:
yield guess
while True:
guess_generator = pw_guess()
for guess in guess_generator:
if h.startword == "":
h.startword = guess
else:
if guess == h.startword:
h.rep += 1
print("next rotation, itr rep: " + str(h.rep))
h.startword = ""
break
h.txt = ''.join(guess)
f = open(WL_path, "a")
f.write(h.txt+"\n")
f.close()
if h.rep > itr:
break
推荐阅读
- laravel - 如何更新行并返回updated_at?
- javascript - 在 `createGlobalStyle` 中使用样式化组件的规则
- java - Spring:将 webServiceTemplate 信封“env”更改为“soapenv”
- reactjs - “确切”导致空白页制作模式
- json - SWIFT4 将 JSON 解码结果发送到类进行处理
- c++ - 在 Windows/MSVC 上将 C++ gRPC 与 Bazel 集成?
- azure - Azure Function Timeout on Consumption Plan
- cluster-analysis - 当我对特征进行标准化时,K-means 找到了一个单例集群(批发客户数据集)
- http - Ionic 使用 Oauth 检索和操作数据,需要帮助
- wpf - ComboBox SelectionChanged 事件处理程序中的 InvalidCastException