#include<stdio.h>
#include<stdlib.h>
#include<string.h>charbuf[32];intmain(intargc,char*argv[],char*envp[]){if(argc<2){printf("pass argv[1] a number\n");return0;}intfd=atoi(argv[1])-0x1234;//This is the keyintlen=0;len=read(fd,buf,32);if(!strcmp("LETMEWIN\n",buf)){printf("good job :)\n");setregid(getegid(),getegid());system("/bin/cat flag");exit(0);}printf("learn about Linux file IO\n");return0;}
The key line is:
1
intfd=atoi(argv[1])-0x1234;
0x1234 is 4660 in decimal. If you pass 4660 as the first argument (argv[1]), then:
convert hex 0x1234 to decimal $((1x16^3)+(2x16^2)+(3x{16}^1)+(4x{16}^0))$ =4066
1
fd=4660-4660=0
File descriptor 0 is stdin. The program will then read from your input.