Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 - Fatal编程技术网

为什么我的Python暴力散列破解程序现在可以工作?

为什么我的Python暴力散列破解程序现在可以工作?,python,Python,我已经编写了一个Python哈希强制脚本。但是,蛮力函数不起作用。它将接受用户输入哈希并在所有迭代中循环。但是,我可以在输出上看到它已经找到了散列,但是它不会中断循环 散列是sha256,输入是“blah”,它将找到blah的散列,但不会中断循环 谢谢你的洞察力 代码是: def bruteforce(passwordHash, hashtype): #bruteforce not working? wordlist = "abcdefghijklmnopqrstuvwxyz

我已经编写了一个Python哈希强制脚本。但是,蛮力函数不起作用。它将接受用户输入哈希并在所有迭代中循环。但是,我可以在输出上看到它已经找到了散列,但是它不会中断循环

散列是sha256,输入是“blah”,它将找到blah的散列,但不会中断循环

谢谢你的洞察力

代码是:

def bruteforce(passwordHash, hashtype): #bruteforce not working?

    wordlist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+{}:;',./?-="
    y=''
    length=1
    wordlistHash=''
    passwordHash=passwordHash

    while wordlistHash != passwordHash:
        for c in itertools.product(wordlist, repeat=length):
            word = y.join(c)
            if hashtype == 'sha256':
                wordlistHash = hashlib.sha256(word.encode("utf-8")).hexdigest()
                print(f"Trying password: {word}:{wordlistHash}")
            elif hashtype == 'md5':
                wordlistHash = hashlib.md5(word.encode("utf-8")).hexdigest()
                print(f"Trying password: {word}:{wordlistHash}")
            elif hashtype == 'sha1':
                wordlistHash = hashlib.sha1(word.encode("utf-8")).hexdigest()
                print(f"Trying password: {word}:{wordlistHash}")
            else:
                print("Please either enter a sha256, md5 or sha1 hash and restart the script")
                exit()
                if wordlistHash == passwordHash:
                    print(f"Found password: {word}")
                    break
        length=length + 1

这是新的脚本,我只是简单地补充了一下

if wordlistHash == passwordHash:
    print(f"Found password: {word}")
    break
在每个,
if elif
语句之后,否则,程序将仅在输入不正确时显示密码(因为您将密码放在最后一个else语句中)。我不知道我是否清楚,希望有帮助,以下是新计划:

import hashlib
import itertools

def bruteforce(passwordHash, hashtype): #bruteforce not working?

    wordlist = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+{}:;',./?-="
    y=''
    length=1
    wordlistHash=''
    passwordHash=passwordHash

    while wordlistHash != passwordHash:
        for c in itertools.product(wordlist, repeat=length):
            word = y.join(c)
            if hashtype == 'sha256':
                wordlistHash = hashlib.sha256(word.encode("utf-8")).hexdigest()
                print(f"Trying password: {word}:{wordlistHash}")
                if wordlistHash == passwordHash:
                    print(f"Found password: {word}")
                    break
            elif hashtype == 'md5':
                wordlistHash = hashlib.md5(word.encode("utf-8")).hexdigest()
                print(f"Trying password: {word}:{wordlistHash}")
                if wordlistHash == passwordHash:
                    print(f"Found password: {word}")
                    break
            elif hashtype == 'sha1':
                wordlistHash = hashlib.sha1(word.encode("utf-8")).hexdigest()
                print(f"Trying password: {word}:{wordlistHash}")
                if wordlistHash == passwordHash:
                    print(f"Found password: {word}")
                    break
            else:
                print("Please either enter a sha256, md5 or sha1 hash and restart the script")
                exit()


        length=length + 1

bruteforce('8B7DF143D91C716ECFA5FC1730022F6B421B05CEDEE8FD52B1FC65A96030AD52', 'sha256')

因为,排队之后,

print("Please either enter a sha256, md5 or sha1 hash and restart the script")
您放置了一个
exit()
函数。如果你想让休息时间开始工作,就排好队

if wordlistHash == passwordHash:
    print(f"Found password: {word}")
    break

在if语句之外

只需修复缩进就更简单了。