【问题标题】:Generate a password from SHA3-512 hash value从 SHA3-512 哈希值生成密码
【发布时间】:2021-05-14 18:06:06
【问题描述】:

我是 python 新手,目前正在攻读 IT 硕士学位。我正在从哈希值中解码密码。

这就是我目前的设置方式。我知道这是错误的,任何帮助将不胜感激。

import itertools
import time
from Crypto.Hash import SHA3_512

# Function to brute force the password
def tryPassword(passwordSet):
    start = time.time()

    # Allowed characters in the password
    chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=[{]}|:;'\",<.>/?"
    
    attempts = 0

    for value in range(1, 9):
        # Build up a string to test against, character by character
        for letter in itertools.product(chars, repeat=value):
            attempts += 1
            letter = ''.join(letter)
            hash_object = SHA3_512.new()
            hash_object.update((letter).encode("utf-8"))

            tmp_hash = hash_object.hexdigest()
            print(tmp_hash)

            #if the string we are building matches the password given to us, return from the function
            if tmp_hash == passwordSet:
                end = time.time()
                distance = end - start
                return (attempts, distance)


password = input("Password >")
tries, timeAmount, = tryPassword(password)
print("The password %s was cracked in %s tries and %s seconds!" % (password, tries, timeAmount))

【问题讨论】:

标签: python hash sha brute-force


【解决方案1】:

既然目的是破解哈希密码,那应该是函数的参数,而不是纯文本密码。

然后在循环中它需要对每个候选密码进行哈希处理,并将哈希值与输入进行比较。

import itertools
import time
from Crypto.Hash import SHA3_512

def hash_password(password):
    hash_object = SHA3_512.new()
    hash_object.update(password.encode("utf-8"))
    return hash_object.hexdigest()

def tryPassword(hashed_pass):
    start = time.time()

    # Allowed characters in the password
    chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=[{]}|:;'\",<.>/?"
    
    attempts = 0

    for value in range(1, 9):
        # Build up a string to test against, character by character
        for letter in itertools.product(chars, repeat=value):
            attempts += 1
            candidate = ''.join(letter)

            #if the string we are building matches the password given to us, return from the function
            if hash_password(candidate) == hashed_pass:
                end = time.time()
                distance = end - start
                return (attempts, distance, password)

password = input("Password > ")
tmp_hash = hash_password(password)

tries, timeAmount, found_password = tryPassword(tmp_hash)
print("The password %s was cracked in %s tries and %s seconds!" % (found_password, tries, timeAmount))

【讨论】:

  • 感谢您抽出宝贵时间帮助我!我跑的程序来破解低于这个密码:11af05af85d7656ee0f2e3260760bccdc2af88dee449f682ab2e367003856166edc045c4164a4d543ea4a43d6dd022d3c290866f2d2a7a92a38400bd3a5f7ab0这是不告诉我密码输出:密码11af05af85d7656ee0f2e3260760bccdc2af88dee449f682ab2e367003856166edc045c4164a4d543ea4a43d6dd022d3c290866f2d2a7a92a38400bd3a5f7ab0在900920次尝试和1558.3180966377258秒破解 SPAN>
  • 该函数不返回匹配的候选者,它只返回尝试次数和时间。
  • 你可以使用return attempts, distance, candidate
  • 我无法让该程序正确运行。我已经更新了能够产生相同输出的原始代码。如何更新它以告诉我找到的密码?
  • 请不要更改问题,现在我的回答没有上下文。如果您想展示您尝试过的内容,请将其添加到问题中,但不要理会原始代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-15
  • 2015-10-23
  • 2016-02-06
  • 2015-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多