将多处理添加到现有 Python 脚本?



我正在尝试将多处理添加到现有的密码破解程序,其来源位于此处:https://github.com/axcheron/pyvboxdie-cracker

该脚本运行良好,但速度真的很慢,添加多处理肯定会加快速度。我在网上(和这里(寻找了一些例子,我已经遇到了一堵完整的信息过载的墙,我只是无法理解它。我在这里找到了用户Camon的一篇非常有用的帖子(发布在这里:Python多处理密码破解程序(,但我看不出如何在脚本中实现它。

def crack_keystore(keystore, dict):
wordlist = open(dict, 'r')
hash = get_hash_algorithm(keystore)
count = 0
print("n[*] Starting bruteforce...")
for line in wordlist.readlines():
kdf1 = PBKDF2HMAC(algorithm=hash, length=keystore['Key_Length'], salt=keystore['Salt1_PBKDF2'],
iterations=keystore['Iteration1_PBKDF2'], backend=backend)
aes_key = kdf1.derive(line.rstrip().encode())
cipher = Cipher(algorithms.AES(aes_key), modes.XTS(tweak), backend=backend)
decryptor = cipher.decryptor()
aes_decrypt = decryptor.update(keystore['Enc_Password'])
kdf2 = PBKDF2HMAC(algorithm=hash, length=keystore['KL2_PBKDF2'], salt=keystore['Salt2_PBKDF2'],
iterations=keystore['Iteration2_PBKDF2'], backend=backend)
final_hash = kdf2.derive(aes_decrypt)
if random.randint(1, 20) == 12:
print("t%d password tested..." % count)
count += 1
if binascii.hexlify(final_hash).decode() == binascii.hexlify(keystore['Final_Hash'].rstrip(b'x00')).decode():
print("n[*] Password Found = %s" % line.rstrip())
exit(0)
print("t[-] Password Not Found. You should try another dictionary.")

这是我需要编辑的脚本部分,Carmon 的示例具有将单词列表拆分为块的功能,并且每个进程都有自己的块。我实现它的问题是单词列表仅在函数内部填充(在其他任务完成后,repo 上的完整源代码(。我将如何实现此部分的多处理?感谢您的任何帮助。

from multiprocessing import Process
# keystore = some_value
# dict1, dict2, dict3, dict4
proc_1 = Process(target=crack_keystore, args=(keystore, dict1))
proc_2 = Process(target=crack_keystore, args=(keystore, dict2))
proc_3 = Process(target=crack_keystore, args=(keystore, dict3))
proc_4 = Process(target=crack_keystore, args=(keystore, dict4))
proc_1.start()
proc_2.start()
proc_3.start()
proc_4.start()
proc_1.join()
proc_2.join()
proc_3.join()
proc_4.join()
print("All processes successfully ended!")

进程的最大计数不得超过 CPU 的内核数。

最新更新