[pwnable.kr] collision(3 pts) :: Write-Up

두비니

·

2019. 11. 9. 00:39

 

 

 

 

 

 

Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!

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

 

 

 

 

col@prowl:~$ ls
col  col.c  flag
col@prowl:~$ nl col.c
     1	#include <stdio.h>
     2	#include <string.h>
     3	unsigned long hashcode = 0x21DD09EC;
     4	unsigned long check_password(const char* p){
     5		int* ip = (int*)p;
     6		int i;
     7		int res=0;
     8		for(i=0; i<5; i++){
     9			res += ip[i];
    10		}
    11		return res;
    12	}
       
    13	int main(int argc, char* argv[]){
    14		if(argc<2){
    15			printf("usage : %s [passcode]\n", argv[0]);
    16			return 0;
    17		}
    18		if(strlen(argv[1]) != 20){
    19			printf("passcode length should be 20 bytes\n");
    20			return 0;
    21		}
       
    22		if(hashcode == check_password( argv[1] )){
    23			system("/bin/cat flag");
    24			return 0;
    25		}
    26		else
    27			printf("wrong passcode.\n");
    28		return 0;
    29	}

 

보면 hashcode가 있고, 제가 입력한 첫번째 전달인자가 check_password를 한 값이 hashcode와 같아야 하네요.

 

check_password를 확인해보면, 우선 const char* 형이였던 p를 int* 형으로 바꾸고, 이를 4바이트씩 짤라서 더해주네요. 그렇게 더한 res의 값이 0x21DD09EC여야하네요. 

 

그러면 hashcode의 값을 5로 나눈 값을 4번 반복해서 입력해주면 되겠네요!

 

 

응 아니야

 

사실 여기서 한참을 해멨는데,

 

65CCEC8*5 = 21DD09E8이더라구요.

 

 

프로그래머 계산기라 나누기를 하면 나머지는 버리고 보여주나봅니다. 후....

 

따라서 4개는 똑같이, 5번째는 4를 더한 값을 넣어주면

 

 

 

daddy! I just managed to create a hash collision :)