SEED Labs 2.0: MD5 Hash Collision

Seed Lab2.0: MD5 Hash Collision

Task1

首先编写一个内容为hello world的·prefix.txt文件

image-20230925152442817

Question 1. If the length of your prefix file is not multiple of 64, what is going to happen?

在末尾补0

image-20230925153358169

Question 2. Create a prefix file with exactly 64 bytes, and run the collision tool again, and see what happens.

创建了一个64比特的文件,生成的两个文件md5值还是相同的

image-20230925153852263

通过bless文件查看两个文件的二进制,发现末尾没有继续添0了

image-20230925153948130

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

image-20230925154945912

生成两个out文件,MD5值相同

image-20230925155053404

image-20230925155122534

查看二进制文件发现两个文件只有五处不同

image-20230925155356513

image-20230925155420463

Task 2: Understanding MD5’s Property

向两个文件添加后缀之后MD5的值还是相同的

image-20230925160743368

Task 3: Generating Two Executable Files with the Same MD5 Hash

和指导文件里一样,我们先使用0x41填充xyz数组

之后通过bless查看二进制中,xyz数组数据的位置,如下图

image-20230925171322973

从第12320再偏移200个字符都是数组的区域

取64(0x40)的倍数0x3040。十进制12352

1
head -c 12352 code > prefix

再使用md5collgen生成两个不同的前缀 a,b

image-20230925171638195

生成的大小为12480,所以我们需要保留原始程序中12480之后的代码

1
tail -c +12481 a.out > suffix

image-20230925172054174

之后拼接上不同的头 生成两个程序

image-20230925172315877

给程序添加权限执行之后的结果进行比较之后发现不一样,但是MD5值是一样的:

image-20230925172503193

image-20230925172529564

Task 4: Making the Two Programs Behave Differently

首先编写一个代码:

image-20230925232043446

这个就是一个好的代码

image-20230925232107428

之后通过bless查看其对应的二进制:找到A B数组对应的地方,可以看到是从12320开始的

image-20230925232206718

取64(0x40)的倍数0x3040。十进制12352,生成两个前缀

1
2
head -c 12352 code > prefix
md5collgen -p prefix -o p q

查看发现在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
2
head -c 40 tmp > m40
head -c 24 tmp > m24

开始拼接

1
2
cat p m40 m24 middle m40 suffix > s
cat q m40 m24 middle m40 suffix > k

image-20230925232638244

image-20230925232655109