最近由前輩推薦,去到http://pwnable.kr/開始人生中第一次正經的刷題。 Toddler's Bottle.... :(
第一題fd主要是爲了介紹玩法
ssh [email protected] -p2222 (pw:guest)
源碼如下:
#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;
}
輸入參數必須大於等於2,argv[0]指向程序運行的全路徑名,之後從argv[1]開始即爲實際傳入的參數。
File descriptor 0爲stdin,0x1234=4660。
構造輸入:
fd@ubuntu:~$ ./fd 4660
LETMEWIN
good job :)
mommy! I think I know what a file descriptor is!!