#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;
}
ssh로 연결해준 뒤 argv를 설정해 바이너리를 실행하면 됩니다.
코드를 보면 char 포인터를 int 포인터로 변환시켜
for 문을 활용해 4바이트 씩 더해서 변수 res에 저장합니다.
최종적으로 res가 hashcode인 0x21DD09EC가 되어야 합니다.
hashocde를 4개로 나누면
0x06C5CEC8 * 3 + 0x06C5CECC로 표현할 수 있습니다.
최종 익스플로잇 코드는 다음과 같습니다.
(리틀엔디안을 사용해줘야 합니다)
from pwn import *
s = ssh(user='col',host='pwnable.kr',port=2222,password='guest')
pay = ['./col', b'\xC8\xCE\xC5\x06'*4 + b'\xCC\xCE\xC5\x06']
r = s.process(executable='./col',argv=pay)
r.interactive()
$ python3 ex.py
[+] Connecting to pwnable.kr on port 2222: Done
[*] col@pwnable.kr:
Distro Ubuntu 16.04
OS: linux
Arch: amd64
Version: 4.4.179
ASLR: Enabled
[+] Starting remote process bytearray(b'./col') on pwnable.kr: pid 5262
[*] Switching to interactive mode
daddy! I just managed to create a hash collision :)
[*] Got EOF while reading in interactive
'write-up(pwn) > pwnable.kr' 카테고리의 다른 글
[pwnable.kr] passcode write-up (0) | 2023.06.14 |
---|---|
[pwnable.kr] flag write-up (0) | 2023.05.13 |
[pwnable.kr] bof write-up (0) | 2023.05.01 |
[pwnable.kr] fd write-up (0) | 2023.04.29 |