SEED Labs 2.0: MD5 Hash Collision

SEED Labs 2.0: MD5 Hash Collision
JohnnySeed Lab2.0: MD5 Hash Collision
Task1
首先编写一个内容为hello world的·prefix.txt文件
Question 1. If the length of your prefix file is not multiple of 64, what is going to happen?
在末尾补0
Question 2. Create a prefix file with exactly 64 bytes, and run the collision tool again, and see what happens.
创建了一个64比特的文件,生成的两个文件md5值还是相同的
通过bless文件查看两个文件的二进制,发现末尾没有继续添0了
Are the data (128 bytes) generated by md5collgen completely different for the two output files? Please identify all the bytes that are different.
构造出test.txt大小为128bytes
生成两个out文件,MD5值相同
查看二进制文件发现两个文件只有五处不同
Task 2: Understanding MD5’s Property
向两个文件添加后缀之后MD5的值还是相同的
Task 3: Generating Two Executable Files with the Same MD5 Hash
和指导文件里一样,我们先使用0x41填充xyz
数组
之后通过bless查看二进制中,xyz
数组数据的位置,如下图
从第12320再偏移200个字符都是数组的区域
取64(0x40)的倍数0x3040。十进制12352
1 | head -c 12352 code > prefix |
再使用md5collgen生成两个不同的前缀 a,b
生成的大小为12480,所以我们需要保留原始程序中12480之后的代码
1 | tail -c +12481 a.out > suffix |
之后拼接上不同的头 生成两个程序
给程序添加权限执行之后的结果进行比较之后发现不一样,但是MD5值是一样的:
Task 4: Making the Two Programs Behave Differently
首先编写一个代码:
这个就是一个好的代码
之后通过bless查看其对应的二进制:找到A B数组对应的地方,可以看到是从12320开始的
取64(0x40)的倍数0x3040。十进制12352,生成两个前缀
1 | head -c 12352 code > prefix |
查看发现在0x31c8处开始后面内容,在此截取后部分内容
1 | tail -c +12745 code > suffix |
把其中一个新前缀p的后32(字符A)+128(md5填充物)=16032(字符A)+128(MD5填充物)=160个字节截取出来:
1 | tail -c 160 p > middle |
数组的长度是200,200−160=40200−160=40,所以还需要填充40个字节给a和b数组,
两个数组相差0x3100−0x3020=0xE0=224字节,不是200字节,因此需要在a数组和b数组之间插入24个0x00
:
使用python生成40个字符串,由于python生成时会在末尾自动加上0A
,因此我们需要截取生成的文件
1 | python3 -c "print('\x00'*40)" > tmp |
1 | head -c 40 tmp > m40 |
开始拼接
1 | cat p m40 m24 middle m40 suffix > s |