【Pwnable】[Toddler's Bottle]--fd
Description:
Mommy! what is a file descriptor in Linux?
*try to play the wargame your self but if you are ABSOLUTE beginner, follow this tutorial link:
https://youtu.be/971eZhMHQQw
ssh [email protected] -p2222 (pw:guest)
Solution:
先认识三个函数:
atoi函数:传送门–atoi函数
strcmp函数:传送门–strcmp函数
read函数:传送门–read函数
再了解main函数里面的三个变量:
int argc,char* argv[]:传送门–argc argv
char* envp[]:环境变量
连接端口后用ls指令查看当前文件夹下有什么文件,发现了fd fd.c flag三个文件
用cat指令查看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;
}
这里看read函数,fd==0时才能够标准输入
fd == 0为标准输入
fd == 1为标准输出
fd == 2为标准错误输出
所以我们要使atoi(argv[1])-0x1234为0,再继续输入LETMEWIN后回车即可。
Flag:
mommy! I think I know what a file descriptor is!!