fd

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)

 

本题的目的是理解什么是fd也就是文件描述符,一般情况下,0为标准输入流,1为标准输出流,2为标准错误流,其余打开的文件fd由3开始顺序往下标

程序源码为

#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;

}

当给程序未传递参数时会提示要传一个数字作为第一个参数,因此为了让程序从键盘读入,应该让fd为0,那么传入0x1234也就是4660作为参数,然后输入LETMEWIN回车即可

posted @ 2021-08-01 23:07  hktk1643  阅读(584)  评论(0编辑  收藏  举报