Void
[pwnable.kr] collision 본문
$ ssh col@pwnable.kr -p2222
col@pwnable.kr's password:
____ __ __ ____ ____ ____ _ ___ __ _ ____
| \| |__| || \ / || \ | | / _] | |/ ]| \
| o ) | | || _ || o || o )| | / [_ | ' / | D )
| _/| | | || | || || || |___ | _] | \ | /
| | | ` ' || | || _ || O || || [_ __ | \| \
| | \ / | | || | || || || || || . || . \
|__| \_/\_/ |__|__||__|__||_____||_____||_____||__||__|\_||__|\_|
- Site admin : daehee87@khu.ac.kr
- irc.netgarage.org:6667 / #pwnable.kr
- Simply type "irssi" command to join IRC now
- files under /tmp can be erased anytime. make your directory under /tmp
- to use peda, issue `source /usr/share/peda/peda.py` in gdb terminal
You have mail.
Last login: Sat Jan 18 18:40:17 2025 from 211.105.38.94
col@pwnable:~$ ls
col col.c flag
서버에 있는 파일을 확인해보면 바이너리, 소스코드, flag가 있다. col.c를 확인해보자.
//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;
}
argv에서 값을 가져온다. passcode의 길이는 20byte여야 하고, check_password()의 리턴값이 hashcode여야 한다.
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;
}
p는 passcode이다. int형으로 바꿔서 res에 값을 추가하고, 이 값을 리턴한다.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t |
만약 "abcdefghijklmnopqrst"를 입력하면 res에 0x64636261(dcba) ......가 더해질 것이다. 이유는 리틀 엔디안 때문이다. 그래서 0x61626364를 더하고 싶다면, "dcba"를 입력해야 한다. 또한 argv에는 NULL값을 입력할 수 없다. 그래서 0x01010101을 4번 입력한후, 마지막에 0x21DD09EC- 0x01010101*4=0x1DD905E8를 입력하면 된다.
python -c "print(b'\x01'*16+b'\xe8\x05\xd9\x1d')"
이 코드를 활용해서 argv에 전달하면 된다. b'\x01'을 16번 출력하고, 마지막에 0x1DD905E8를 리틀엔디안으로 패킹했다.
인자로 전달할 때는 "$(....)"로 전달할 수 있다.
col@pwnable:~$ ./col "$(python -c "print(b'\x01'*16+b'\xe8\x05\xd9\x1d')")"
daddy! I just managed to create a hash collision :)
daddy! I just managed to create a hash collision :)
'pwnable.kr' 카테고리의 다른 글
| [pwnable.kr] brain fuck (0) | 2025.01.19 |
|---|---|
| [pwnable.kr] flag (0) | 2025.01.19 |
| [pwnable.kr] bof (0) | 2025.01.19 |
| [pwnable.kr] fd (0) | 2025.01.18 |