나나는 내게 버퍼 오버플로우에 대하여 말해주었다. 그것은 일반적인 소프트웨어 취약점 중 하나라고 했다. 정말일까?
After downloading the bof.c and bof files, I opened the file bof.c. It is a program that executes /bin/sh if key == 0xcafebabe is satisfied. It seems to require a buffer overflow attack in order to execute Bourne shell.
bof.c와 bof 파일을 다운로드후에 bof.c 파일을 열어보았다. key==0xcafebabe를 만족하면 /bin/sh를 실행하는 프로그램이다. 본쉘을 실행할 수 있도록 버퍼 오버플로우 공격을 하라는 것 같다.
After running gdb, change to the intel syntax with the command "set disassembly-flavor intel".
gdb를 실행한 뒤, "set disassembly-flavor intel" 명령으로 intel 문법으로 변경해준다.
The main function is func, so disassemble it as shown above. Because there is an "overflow me:" string in the memory 0x78c(x/s 0x78c), Below, <func + 25> is assumed to be a printf function, and <func + 36> is assumed to be a gets function.
주요 함수는 func 이므로 디스어셈블 해보면 위 그림과 같다. 0x78c 메모리 부분에 "overflow me : " 문자열이 있으므로(x/s 0x78c), 그 아래 <func+25>는 printf 함수로 추정되며, <func+36>은 gets 함수로 추정된다.
The "cmp" command means the if statement. You must type 0xcafebabe in [ebp + 0x8] to run the shell. Since the gets function stores the value entered by the user in [ebp-0x2c], fill the [ebp-0x2c]~[ebp+0x7] memory with meaningless values and fill the [ebp+0x8] memory with 4 bytes value 0xcafebabe It has the same effect as putting a value in the key variable.
"cmp" 명령어는 if 문을 의미한다. [ebp+0x8]에 0xcafebabe를 입력해야 쉘이 실행될 것이다. gets 함수가 [ebp-0x2c]에 사용자가 입력한 값을 저장하므로 [ebp-0x2c]~[ebp+0x7] 메모리는 의미 없는 값으로 채우고, [ebp+0x8] 메모리에는 4바이트 값 0xcafebabe를 채우면 key 변수에 값을 넣는 것과 동일한 효과가 있다.
Insert 52 dummy values and 0xcafebabe in a little-endian way, and connect the server using pipeline to pass the data(Without the "; cat", the program does not work as I thought, and I do not know why).
더미 값 52 개와 0xcafebabe를 리틀 엔디안 방식으로 입력하고, 파이프라인으로 데이터를 넘겨주며 서버에 접속하면 된다(;cat을 누락하면 프로그램이 생각처럼 동작하지 않는데, 이유는 모르겠다.).
You can check the authentication key by reading the flag file.
flag 파일을 열람하면 인증 키를 확인할 수 있다.