检查.rar文件密码的最快方法-rarfile extractall除外

问题描述

因此,我使用了下面的代码,根据教程编写了一个.rar密码“ cracker”。它工作正常,但是当文件很大时非常慢。我能找到的最好原因是,每当您输入错误的密码时,它都会在拒绝密码之前提取整个文件。使用小文件不是什么大问题,但是使用大文件会大大减慢该过程。

有没有一种方法可以针对迭代的哈希仅检查密码的哈希版本?

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},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密码。但是,使用脚本的某些部分生成单词列表仍然非常快速且实用。

我使用的

wordlist生成器:

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