collision

0

Daddy told me about cool MD5 hash collision today.

I wanna do something like that too!

ssh col@pwnable.kr -p2222 (pw:guest)

col.c源码如下:

#include <stdio.h>
#include <string.h>
unsigned long hashcode = 0x21DD09EC;
unsigned long check_password(const char* p){
	int* ip = (int*)p;
	int i;
	int res=0;
	for(i=0; i<5; i++){
		res += ip[i];
	}
	return res;
}

int main(int argc, char* argv[]){
	if(argc<2){
		printf("usage : %s [passcode]\n", argv[0]);
		return 0;
	}
	if(strlen(argv[1]) != 20){
		printf("passcode length should be 20 bytes\n");
		return 0;
	}

	if(hashcode == check_password( argv[1] )){
		system("/bin/cat flag");
		return 0;
	}
	else
		printf("wrong passcode.\n");
	return 0;
}

首先确定输入的长度为20 bytes,然后分析check_password这个函数,要使hashcode == check_password( argv[1] ) 这个条件成立,即将hashcode = 0x21DD09EC 传参给check_password

check_password分析:将20 bytes的字符串拆分成5个子串,分别转换成int,最后求和等于0x21DD09EC。

可以构造 16 * '\x00' + '\xEC\x09\xDD\x21',但是0x09对应ascii是Horizontal tab,会隔断,所以调整一下,0x21DD09EC - 4 * 0x02020202 = 0x19D501E4 ,由此构造出16 * '\x02' + '\xE4\x01\xD5\x19'

Terminal:

col@ubuntu:~$ ./col `python -c "print 16 * '\x02' + '\xE4\x01\xD5\x19'"`
daddy! I just managed to create a hash collision 🙂

exp如下:

from pwn import *
payload = 16 * '\x02' + '\xE4\x01\xD5\x19'
s = ssh(user='col', host='pwnable.kr', port=2222, password='guest')
p = s.process(['/home/col/col', payload])
print p.recv()
s.close()

Leave A Reply

苏ICP备16066660号-1

苏公网安备 32011502010432号