把上面那个脚本的待解密的md5改成文件读取的
时间: 2024-04-20 10:22:53 浏览: 18
如果你想将待解密的 MD5 值从文件中读取而不是直接在代码中指定,你可以进行以下修改:
```python
import hashlib
def crack_md5(wordlist_path, hashes_path):
with open(wordlist_path, 'r') as wordlist_file:
wordlist = wordlist_file.read().splitlines()
with open(hashes_path, 'r') as hashes_file:
target_hashes = hashes_file.read().splitlines()
for password in wordlist:
md5_hash = hashlib.md5(password.encode()).hexdigest()
if md5_hash in target_hashes:
print(f"Password found: {password}")
target_hashes.remove(md5_hash)
if len(target_hashes) == 0:
print("All passwords cracked!")
return
print("Password not found in wordlist!")
# 示例用法
wordlist_path = "wordlist.txt"
hashes_path = "hashes.txt"
crack_md5(wordlist_path, hashes_path)
```
在修改后的代码中,我们新增了一个参数 `hashes_path`,用于指定存储待解密 MD5 值的文件路径。我们使用 `open` 函数打开这两个文件,并分别读取其内容。然后,在密码破解的循环中,我们将待解密密码和 MD5 哈希值进行比对。
请确保 `wordlist.txt` 文件包含一行一个的密码,`hashes.txt` 文件包含一行一个的 MD5 哈希值,与示例代码保持一致。