pwnable/pwnable.kr
[pwnable.kr] fd
ineiw
2022. 3. 8. 21:41
먼저 ssh 로 접속합니다.,
접속후 파일 리스트를 보면
fd@pwnable:~$ ls
fd fd.c flag
flag 가 보입니다. 해당 플래그파일을 읽으면 되는것같습니다.
fd.c 파일을 봅니다.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[32];
int main(int argc, char* argv[], char* envp[]){
if(argc<2){
printf("pass argv[1] a number\n");
return 0;
}
int fd = atoi( argv[1] ) - 0x1234;
int len = 0;
len = read(fd, buf, 32);
if(!strcmp("LETMEWIN\n", buf)){
printf("good job :)\n");
system("/bin/cat flag");
exit(0);
}
printf("learn about Linux file IO\n");
return 0;
}
buf 의 값이 LETMEWIN 이면 되는것 같습니다. 이때 read 함수로 buf 의 값을 받습니다.
len = read(fd, buf, 32);
read 의 fd 값이 0 일때 읽는다는 뜻이므로 fd 가 0이 되어야 합니다.
fd 는 argv[1] 즉 바이너리를 실행할때의 인자값 - 0x1234 입니다. 따라서 인자값이 0x1234 이면 fd 값은 0이됩니다.
int fd = atoi( argv[1] ) - 0x1234;
0x1234 는 16진수이므로 10진수로 바꿔주면 4660가 됩니다.
따라서 argv[1] 에 4660 을 준다면 buf 에 값을 줄수있게되고
적절한 문자열을 준다면
system("/bin/cat flag")가 실행되면서 flag 파일이 출력되게됩니다.
fd@pwnable:~$ ./fd 4660
LETMEWIN
good job :)