[1] fd
2017. 12. 5. 19:19ㆍSystemHacking/pwnable.kr
파일 디스크립터 ( File Discriptor )
0 : 표준 입력
1 : 표준 출력
2 : 표준 에러
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #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; | cs |
read( int fd , void *buf , size_t len )
fd : open() 시스템 콜로 열린 파일을 가리키는 파일 지정 번호
buf : 파일에서 읽은 데이터를 저장할 메모리 공간
len : 읽을 데이터의 크기
read ( 0 , buf , 32 )
=> 표준입력을 받아서 32길이만큼의 데이터를 buf에 저장
strcmp( str1 , str2 )
str1 과 str2 를 비교해서 같으면 0 , str1 > str2 : 양수 , str1 < str2 : 음수 반환
atoi() 함수
입력받은 문자열을 long 정수형으로 변환한다
* fd = atoi( argv[1] ) - 0x1234
* 0x1234 == 4660
'SystemHacking > pwnable.kr' 카테고리의 다른 글
[3] bof (0) | 2017.12.05 |
---|