Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向现有Python脚本添加多处理?_Python_Multithreading_Multiprocessing_Cracking - Fatal编程技术网

向现有Python脚本添加多处理?

向现有Python脚本添加多处理?,python,multithreading,multiprocessing,cracking,Python,Multithreading,Multiprocessing,Cracking,我正在尝试将多处理添加到现有密码破解程序中,其源位于此处: 该脚本工作得很好,但速度非常慢,添加多处理肯定会加快速度。我在网上(和这里)找了一些例子,我碰到了一堵信息过载的墙,我就是想不起来。我发现用户Camon在这里发布了一篇非常有用的帖子(发布在这里:),但我不知道如何在脚本中实现它 def crack_keystore(keystore, dict): wordlist = open(dict, 'r') hash = get_hash_algorithm(keystore) count

我正在尝试将多处理添加到现有密码破解程序中,其源位于此处:

该脚本工作得很好,但速度非常慢,添加多处理肯定会加快速度。我在网上(和这里)找了一些例子,我碰到了一堵信息过载的墙,我就是想不起来。我发现用户Camon在这里发布了一篇非常有用的帖子(发布在这里:),但我不知道如何在脚本中实现它

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!")
最大进程数是计算机的核心数

关于多重处理,您可以里德

请发布一份而不是一份完整的回购协议。而且,这是一个非常开放的问题。你到底想要什么?了解Python中多处理的资源?简单的介绍?