Mom? how can i pass my input to a computer program?
엄마? 소프트웨어에 값을 어떻게 입력해야 하나요?
<input.c>
<myinput.c>
It is difficult to solve with script language alone, so I maked with C language.
스크립트 언어만으로 해결하기에는 어려움이 있어서, C언어로 구현했다.
<Stage 1>
Put the given value in the array And put a NULL value at the end of the array because it is a string type,
해당 배열의 위치에 지정된 값을 넣으면 된다. 문자열 형태이므로 배열 끝에 NULL 값을 넣는다.
<Stage 2>
You must enter given value in the reserved file descriptors 0(=stdin), 2(=stderr). Since it is currently in operation, you can't input it with wirte(0, ~, ~) function, you can create a pipeline instead and pass the value.
예약된 파일디스크립터인 0(=stdin), 2(=stderr)에 특정 데이터를 입력해야 한다. 현재 동작 중이기 때문에 wirte(0, ~, ~)와 같이 입력하면 안되고, 파이프라인을 생성하여 데이터를 넘기면 된다.
Use the dup2 function to connect 0(=stdin) and 2(=stderr) to the read portion of the pipeline. If you then input the given value to the write function, you can read the value from the 0 and 2.
dup2 함수를 이용하여 0(=stdin)과 2(=stderr)를 파이프라인의 read 부분과 연결한다. 이후 write 함수로 주어진 데이터를 입력하면 0과 2에서 해당 데이터를 읽을 수 있다.
<State 3>
Input given environment value.
주어진 환경 변수를 입력한다.
<Stage 4>
After opening the file with the given file name, enter the given value.
주어진 파일 이름으로 파일을 오픈 한 뒤에 주어진 데이터를 입력한다.
<Stage 5>
The input program opens a server with the argv['C'] port, Therefore, specify the port value.
input 프로그램은 서버를 argv['C'] 포트로 오픈 한다. 그러므로 포트 값을 지정한다.
Now finally, you can pass the argv and the envp to the arguments of the execve function.
이제 마지막으로, argv와 envp를 execve 함수의 아규먼트로 넘겨주면 된다.
□ Move the myinput.c to the pwnable.kr server
□ 지금까지 작성한 myinput.c를 pwnable.kr 서버로 옮긴다
→ pscp.exe -P 2222 [PATH]\myinput.c input2@pwnable.kr:/tmp/yon
□ Compile the myinput.c
□ myinput.c를 컴파일 한다
→ gcc /tmp/yon/myinput.c -o /tmp/yon/myinput
□ Create a soft link of the flag file to execute the command "/bin/cat flag". And modify the environment variable(=PATH).
□ "/bin/cat flag" 명령을 실행하기 위해서 flag 파일의 소프트 링크를 생성하고, 환경변수(=PATH)를 변경한다
→ ln -s /home/input2/flag /tmp/yon/flag
→ export PATH="$PATH:/tmp/yon"
□ Execute myinput program. Stage 1 to Stage 4 are cleared., and Stage 5 can be cleared as shown below.
□ myinput 프로그램을 실행한다. Stage 1부터 Stage 4까지 claer 되는데, Stage 5는 아래와 같이 클리어 할 수 있다.
□ Leave the current window as is, log in to pwnable.kr again with a new window, and connect to the port(=3490) with sending the given value.
□ 기존 창은 그대로 둔 채로 pwnable.kr에 새롭게 로그인 한 후, 지정한 포트(3490)로 접속하면서 주어진 데이터를 보낸다.
→ perl -e 'print "\xde\xad\xbe\xef"' | nc localhost 3490