【问题标题】:How to implement a reduced rainbow table in python如何在python中实现一个减少的彩虹表
【发布时间】:2019-07-18 18:55:28
【问题描述】:

我正在尝试了解彩虹表的工作原理,并尝试在 python 中实现一个,但没有取得多大成功。

我有一些代码本质上是在文本文件中创建一个字典,其中明文字符串映射到它们的哈希值,但不知道如何调整它以生成简化的彩虹表。

temp = itertools.product("abcdefghijklmnopqrstuvwxyz", repeat=5)
f = open("passwords.txt", "w")
for pw in temp:
    p = ''.join(pw)
    encode = hashlib.md5(p.encode()).hexdigest() 
    f.write(p + " " + encode + "\n")
f.close()

我遇到了归约函数并且有点理解它们,因此将其定义为:

def reduction(hash):
    return hash[:5]

但我不知道从这里做什么:(

如何调整此代码以生成缩小的彩虹表?

【问题讨论】:

  • 直接下载怎么样?
  • @OlvinR​​oght 我试图找到符合我特定键空间的彩虹表,但它们都大得多,文件大小也非常大
  • 您的磁盘空间有限还是有什么问题?
  • @OlvinR​​oght 不,它只是网上的大小是很多 GB,它们涵盖的键空间与这个案例无关
  • @Adi219 我认为这个问题更适合您为什么要实现缩减功能。你现在拥有的是一个有效的彩虹表,它只是没有减少。

标签: python hash rainbowtable


【解决方案1】:

您的缩减功能应该生成一个由您的字符集和长度为 5 的字符组成的密码(在您的情况下)。这是一个将整数作为输入的示例。

import hashlib
chars="abcdefghijklmnopqrstuvwxyz"
chars_len = len(chars)

def reduce(i):
    # reduces int i to a 5 char password
    # think of i as a number encoded in base l
    pwd=""
    while len(pwd)<5:
        pwd = pwd + chars[ i%chars_len ]
        i = i // chars_len
    return pwd


table=[]
# generate 10 chains of 1000 pwd, print start and end
for s in range(0,10):
    # we can use reduce to generate the start of a chain
    start=reduce(s)

    p=start
    for i in range(0,1000):
        # hash
        h=hashlib.md5(p.encode('ascii')).hexdigest()
        # reduce
        p=reduce(int(h,16))

    table.append([start,p])

print (table)

您现在有一个可以破解大约 10k 个密码但仅使用 20 个密码空间的表!

请注意,对于真正的彩虹表,您必须对每个步骤使用不同的归约函数。例如rainbow_reduce(i,k) = reduce(i+k)

使用该表从哈希中查找密码作为练习:-)(或另一个问题)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2019-05-28
    相关资源
    最近更新 更多