Linux Exploitation/Wargame

[Pwnable.kr] fd

Rosieblue 2023. 6. 3. 21:25
728x90

문제 코드

#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는 문자열을 정수로 변환하는 애라고 한다.
https://www.ibm.com/docs/ko/i/7.3?topic=functions-atoi-convert-character-string-integer 

atoi() — 문자 스트링을 정수로 변환

형식 #include int atoi(const char *string); 로케일 감지 이 함수의 작동은 현재 로케일의 LC_CTYPE 범주에 영향을 받을 수 있습니다. 자세한 정보는 CCSID 및 로케일 이해의 내용을 참조하십시오. 설명 atoi()

www.ibm.com

 
stdin에서 인자를 받기 위해 argv[1]을 0x1234(10진수로4660)로 맞춰준다

끝.