INTERLUDE/System Hacking

[Pwnable.kr] fd

sohexz 2024. 1. 16. 17:36

https://pwnable.kr/play.php

 

https://pwnable.kr/play.php

 

pwnable.kr

 

flag 파일 cat 했을 때 permission denied 떠서

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;

}

 

atoi 함수: 문자 스트링을 정수로 변환해주는 함수

 

정수로 바꿔주면 4660

 

fd에 4660 argument로 넣어주고 LETMEWIN 입력