Pwnable-fd

打开Ubuntu输入ssh [email protected] -p2222,连接之后输入密码guest

 之后就是ls -l看看里面的文件和权限,fd、fd.c、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;
}

要获得flag就要使buf的内容等于LETMEWIN,我们如何让buf的内容等于LETMEWIN,我们先看看read函数的fd

当fd等于0的时候,是标准输入,意味着你可以获得一次通过键盘输入字符串的机会,我们就要利用这次机会把LETMEWIN输入到buf,获得flag

fd如何等于0,atoi是把字符串转换成整型数的一个函数,我们可以看到只要传入4660就可以让它们相减使fd等于0,4660是0x1234的十进制数

mommy! I think I know what a file descriptor is!!

猜你喜欢

转载自www.cnblogs.com/gaonuoqi/p/11743646.html
fd
今日推荐