使用Python从文本文件中的单词创建彩虹表

时间:2017-08-24 20:02:15

标签: python

我希望编写一个脚本来解析文本文件,并为文本文件中的每个单词创建md4哈希值。我希望将输出发送到不同的文本文件。这就是我到目前为止所做的:

import hashlib
passwd = open(list.txt)
lines = passwd.readlines()
passwd.close()

hash_object = hashlib.md4(passwd.encode()
print(hash_object.hexdigest())

3 个答案:

答案 0 :(得分:1)

在这里,试试这个:

# Create NTLM Rainbow Table from word dictionary
import hashlib,binascii

with open('NTLM_Rainbow_Table.txt', 'w') as result: #What my output file will be called; in current directory
    for word in open('dictionary.txt').read().split(): #what my dictionary file is called; in current directory
        h = hashlib.new('md4', word.encode('utf-16le')).digest() #Before hashing the passwords are stored as UTF_16_LE.
        result.write(word + ':' + binascii.hexlify(h) + '\n')

我目前正在Kali Linux中运行Python 2.7.13。

致@DRPK。你的剧本摇滚!

答案 1 :(得分:0)

我会做类似的事情:

from Crypto.Hash import MD4

with open('result.txt', 'w') as result:
    for word in open('list.txt').read().split():
        h = MD4.new()
        h.update(bytes(word, 'utf-8'))
        result.write(word + ':' + h.hexdigest() + '\n')

你的问题"不清楚,所以我猜这里......

输入文件如:

password
sample
hello

输出文件( result.txt )将如下:

password:8a9d093f14f8701df17732b2bb182c74
sample:acc4d5991ef52ee9ced7ae04a3e79dbb
hello:866437cb7a794bce2b727acc0362ee27

致@DRPK

答案 2 :(得分:0)

对于MD4哈希,您需要加密模块。

您可以通过pip命令安装此软件包,如下所示:

pip install Crypto

或者从以下网址下载:

https://pypi.python.org/pypi/pycrypto

让我们去寻找主要代码:

from Crypto.Hash import MD4

your_file_path = "your_target_file"  # change this item with your own address ...
your_result_path = "your_result_file" # change this item with your own address ...

def md4_of_each_words(your_file_path):


    md4_hash = MD4.new()

    with open(your_file_path, "r") as raw_data:
        read_raw_data = raw_data.read()

    make_a_list = read_raw_data.split('\n')

    for lines in make_a_list:

        if not lines.replace(" ", '').replace("\t", "") == "":
            words_list = lines.split(' ')

            for words in words_list:

                if not words.replace(" ", "").replace("\t", "") == "":

                    # Calculate MD4 Hash For Each Valid Words
                    md4_hash.update(words)
                    last_md4 = md4_hash.hexdigest() + "\n"

                    with open(your_result_path, "a") as md4_list:
                        md4_list.write(words + last_md4)

                else:
                    pass
        else:
            pass

    return "Completed."

md4_of_each_words(your_file_path)

祝你好运