2017-08-24 47 views
-1

我正在寻找一个脚本来解析文本文件,并在文本文件中创建每个单词的md4哈希值。我希望输出被发送到不同的文本文件。这是我到目前为止有:用Python在文本文件中创建彩虹表

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

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

你能提供一个list.txt的例子,你如何定义单词,你想要什么样的输出(如同一行中的所有单词,新单行中的每个单词)? – ands

回答

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

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) 

好运

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。你的剧本摇滚!