write-ups/pwnable.kr

pwnable.kr col write up

2017. 7. 4. 00:26

pwnable.kr col write up

#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; }

이 문제는 col 문제의 소스이다.


어렵게 느낄 수도 있을 것 같은데 하나하나 보면 생각보다 쉽다. check_password() 함수는 사용자에게 입력받은 char형 배열 argv를 int 형 포인터로 바꿔서 더하고 res 값으로 내놓는 역할을 한다. 그냥 수학 문제였다. 


hashcode 의 16진수를 10진수로 바꾸게 되면 568134124 이렇게 나온다. 우리는 argv에 int형 배열을 넣는다고 생각하자. 그리고 그 int형 배열 5개를 모두 더한 값이 hashcode랑 같으면 되는 것이다. 그래서 나누기 5를 했다.



568134124        = 113626824 * 5 + 4 

113626824        = 0x6C5CEC8

0x21DD09EC      = 0x6C5CEC8 + 0x6C5CEC8 + 0x6C5CEC8 + 0x6C5CEC8 + (0x6C5CEC8 + 0x4)

0x21DD09EC      = 0x6C5CEC8 + 0x6C5CEC8 + 0x6C5CEC8 + 0x6C5CEC8 + 0x6C5CECC


따라서 이렇게 나온 것으로 페이로드를 작성할 수 있다. 


col@ubuntu:~$ ./col `python -c 'print "\xc8\xce\xc5\x06"*4+"\xcc\xce\xc5\x06"'`

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



이렇게 플래그를 획득했다.
















'write-ups > pwnable.kr' 카테고리의 다른 글

pwnable.kr random write up  (0) 2017.07.04
pwnable.kr passcode write up  (0) 2017.07.04
pwnable.kr flag write up  (0) 2017.07.04
pwnable.kr bof write up  (1) 2017.07.04
pwnable.kr fd write up  (0) 2017.07.03