fd
{"author": ["ret2basic"]}

Source Code

1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
char buf[32];
5
int main(int argc, char* argv[], char* envp[]){
6
if(argc<2){
7
printf("pass argv[1] a number\n");
8
return 0;
9
}
10
int fd = atoi( argv[1] ) - 0x1234;
11
int len = 0;
12
len = read(fd, buf, 32);
13
if(!strcmp("LETMEWIN\n", buf)){
14
printf("good job :)\n");
15
system("/bin/cat flag");
16
exit(0);
17
}
18
printf("learn about Linux file IO\n");
19
return 0;
20
21
}
Copied!

Solution

A little bit of background knowledge: in Linux, the default file descriptors are:
    STDIN (standard input) => 0
    STDOUT (standard output) => 1
    STDERR (standard error) => 2
Back to the source code. To read the flag, we need to store LETMEWIN in the buffer. This can be done by read(0, buf, 32) (from STDIN => directly from user's keyboard). That is, we want fd to be 0, hence we need to pass 4660 (0x1234 in decimal) as argv[1].

Get Flag

Get flag
Last modified 5mo ago