初识彩虹表
1. 散列链
1.1 背景
大部份资料来自维基百科:彩虹表
对于一个用户认证系统,一般不会明文储存用户的密码,而是储存其加密摘要,用户输入密码时,生成加密摘要与储存的密码摘要进行比对,相同则允许其访问请求。
假设黑客盗取了散列后的密码表,由于记录的是密码计算后获得的摘要,因此黑客无法直接使用这份密码表获取权限,为了获得正确的密码,有以下几种方法进行攻击:
- 暴力破解
- 字典攻击
- 使用预先计算好的散列链
其中,暴力破解在进行计算时的时间成本过高;字典攻击需要的空间成本过高;因此有了提前构筑计算好的散列链,牺牲一些时间换空间,目前这种做法在破解哈希中是常见的。
1.2 简介
大部份资料来自维基百科:彩虹表
假设有哈希方程
使用wikipedia上的例子,它构建了假设密码集合P是6个字符长,Hash值有32bit长,长度K=4(应该是)的散列链如下:
对于生成的散列链,只记录其初始密码(起点)和末尾密码(终点),即在生成查找表时只记录起点和终点。
对于查找,不再赘述,直接截图了。
在查找的途中,可能会出现误报(false alarm)的情况如下图:
这是因为对生成的散列链,若有节点发生了碰撞,这就意味着若表中的任意两条链中的某一节点发生碰撞,就会导致其链上的大部分节点都将相同。这是由于设计的归约函数R没有抗碰撞性导致的,而为了能正确的覆盖掉可能的明文,所以R不会具有抗碰撞性。
为了解决简单的哈希链中的碰撞问题,彩虹表选用一系列相关的归约函数R1,…,Rk来代替原先的归约函数R。这样,如果两条哈希链发生碰撞并且重合,那么它们的碰撞必定发生在相同的位置,从而它们的终点也将相同。这样可以通过后处理来排序哈希链,从而找出并移除所有终点相同,因而可能是重复的链,并生成新的链来将整个表补充完整。这样得到的表中的链可能有碰撞的部分,但它们不会发生链的重合,从而大幅降低了碰撞的次数。
2.彩虹表
2.1 使用工具
生成彩虹表使用到的工具是RaninbowCrack,这个工具提供了rtgen,rtsort,rcrack等程序,可完成对彩虹表的生成、排序和查找等操作。
2.2 具体使用
官方文档里给出了详细的用法以及各个参数的详细说明,这里就不再赘述了,附上官方说明:Rainbow Table Generation and Sort(彩虹表的生成与排序)
2.3 例子说明
运行环境为Windows10系统,尝试使用RainbowCrack工具执行对如下字符串的散列的破解:
- 有字符串"cryptography",使用md5计算获得的HEX散列为"e0d00b9f337d357c6faa2f8ceae4a60d"
- 使用rtgen生成彩虹表,使用语句如下:
//使用md5算法,在小写字母集合里,构筑1~12位的密码集合生成彩虹表,单链长度为3800,生成的链数量为33554432条 rtgen md5 loweralpha 1 12 0 3800 33554432 0 //运行效果如下 rainbow table md5_loweralpha#1-12_0_3800x33554432_0.rt parameters hash algorithm: md5 hash length: 16 charset name: loweralpha charset data: abcdefghijklmnopqrstuvwxyz charset data in hex: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a charset length: 26 plaintext length range: 1 - 12 reduce offset: 0x00000000 plaintext total: 99246114928149462 sequential starting point begin from 0 (0x0000000000000000) generating... 196608 of 33554432 rainbow chains generated (0 m 33.1 s) 393216 of 33554432 rainbow chains generated (0 m 32.1 s) 589824 of 33554432 rainbow chains generated (0 m 31.8 s) 786432 of 33554432 rainbow chains generated (0 m 31.1 s) ......//中间的省略了 33423360 of 33554432 rainbow chains generated (0 m 37.7 s) 33554432 of 33554432 rainbow chains generated (0 m 23.2 s)
生成的彩虹表大小有512MB,花了我差不多85min左右才生成成功。运行的时候CPU直接跑满了。
- 对生成的彩虹表进行排序:
//该命令会对当前目录下的所有彩虹表进行排序 rtsort . //运行效果如下 .\md5_loweralpha#1-12_0_3800x33554432_0.rt: 7087034368 bytes memory available loading data... sorting data... writing sorted data...
- 接下来尝试查找表
rcrack . -h e0d00b9f337d357c6faa2f8ceae4a60d //运行结果如下: 1 rainbow tables found memory available: 5781658009 bytes memory for rainbow chain traverse: 60800 bytes per hash, 60800 bytes for 1 hashes memory for rainbow table buffer: 2 x 536870928 bytes disk: .\md5_loweralpha#1-12_0_3800x33554432_0.rt: 536870912 bytes read disk: finished reading all files statistics ---------------------------------------------------------------- plaintext found: 0 of 1 total time: 0.45 s time of chain traverse: 0.42 s time of alarm check: 0.00 s time of disk read: 0.19 s hash & reduce calculation of chain traverse: 7216200 hash & reduce calculation of alarm check: 0 number of alarm: 0 performance of chain traverse: 17.06 million/s performance of alarm check: 0.00 million/s result ---------------------------------------------------------------- e0d00b9f337d357c6faa2f8ceae4a60d <not found> hex:<not found>
对于生成的这个表,没有查找到"critography"对应的散列值,尝试对"hello"的散列值"5d41402abc4b2a76b9719d911017c592"进行查询,成功找到对应明文。
rcrack . -h 5d41402abc4b2a76b9719d911017c592 1 rainbow tables found memory available: 5857804288 bytes memory for rainbow chain traverse: 60800 bytes per hash, 60800 bytes for 1 hashes memory for rainbow table buffer: 2 x 536870928 bytes disk: .\md5_loweralpha#1-12_0_3800x33554432_0.rt: 536870912 bytes read disk: finished reading all files plaintext of 5d41402abc4b2a76b9719d911017c592 is hello statistics ---------------------------------------------------------------- plaintext found: 1 of 1 total time: 0.41 s time of chain traverse: 0.38 s time of alarm check: 0.00 s time of disk read: 0.17 s hash & reduce calculation of chain traverse: 7216200 hash & reduce calculation of alarm check: 1 number of alarm: 1 performance of chain traverse: 19.19 million/s performance of alarm check: 0.00 million/s result ---------------------------------------------------------------- 5d41402abc4b2a76b9719d911017c592 hello hex:68656c6c6f
对于查表失败的结果,可以尝试改变table_index
参数的值,使用不同的归约函数产生新的彩虹表,这样就有可能覆盖到之前查表失败的hash值对应的明文。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix