question
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 fd@pwnable.kr -p2222 (pw:guest)
solutionl
连上ssh后,查看根目录文件发现存在fd.c
,fd
,flag
三个文件,显然flag
是需要获取的内容
通过ls -la
查看文件权限
发现当前用户没有权限查看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;
}
从源码中,可以看到关键在于怎么通过if 语句检查,如果 buf 变量的值为 LETMEWIN 字符串,就可以执行/bin/flag,也就可以获得flag。
查看read方法
man read
通过man命令可以获得read函数的使用方法,参数,以及返回值类型。如果fd为0的话,程序将从stdin读入数据放入到buf
所以只需要让 fd 的值等于 0,再通过终端命令行输入 LETMEWIN,就可以让 buf 的值等于输入的字符串,从而顺利通过 if 语句的检查。
所以,我们只需要让程序运行的第一个命令参数等于 0x1234 即可,转换成 10 进制的值是 4660。
pwn
成功获取flag~