Bandit Level 7 → Level 8

장일영·2024년 5월 10일

Bandit

목록 보기
8/33

Level

Goal

The password for the next level is stored in the file data.txt next to the word millionth

다음 레벨의 패스워드는 data.txt 파일 내의 millionth 단어 옆에 있다.

Commands you may need to solve this level

man, grep, sort, uniq, strings, base64, tr, tar, gzip, bzip2, xxd

Exploit

bandit7@bandit:~$ ls -al
total 4108
drwxr-xr-x  2 root    root       4096 Oct  5  2023 .
drwxr-xr-x 70 root    root       4096 Oct  5  2023 ..
-rw-r--r--  1 root    root        220 Jan  6  2022 .bash_logout
-rw-r--r--  1 root    root       3771 Jan  6  2022 .bashrc
-rw-r-----  1 bandit8 bandit7 4184396 Oct  5  2023 data.txt
-rw-r--r--  1 root    root        807 Jan  6  2022 .profile

bandit7@bandit:~$ file ./*.txt
./data.txt: Unicode text, UTF-8 text

bandit7@bandit:~$ head 10 ./data.txt
head: cannot open '10' for reading: No such file or directory
==> ./data.txt <==
gallop	hu3ZhCrGRvfaO5jsY6ttvApzVCA2Hjvs
Aurelia's	ikl4F3cK5m6Cl6HAxva6zUAVJhI2Cvc6
stoicism	JiW9ts44udf20bJHe8H5dS1c99Muwz42
embodies	vWheZcAsQHZNnerI3ViW8wqOKIx0kbgR
Plato	dW2U8E5FfuAvNLdGDupP8GAxr922ZV0x
cultivation	A90E75jvWbEKrijFxM4GxqHEw8c8U2Bf
stable	omR4PHolFwbI0IEJsanveA21yWvFy8a7
bedspread	VlBFxuEDi3phEpljbKbahRJvJxfh3k9M
oppressing	hQTiEm5XF3cUQSEiBjh7sekemLOKBrcJ
darnedest	9O2zdCLKVoW5u34P9T7EKTZXcMRE6xh5

ASCII text가 아니라 Unicode text 파일임을 확인할 수 있다. 즉, 해당 파일은 ASCII로는 표현할 수 없는 문자를 포함하고 있다. 또 Key-Value 형태로 작성되어 있다.

파일의 특정 단어 옆에 플래그가 위치하고 있음을 이미 알고 있기 때문에 grep 커맨드를 이용해 해당 라인을 찾을 수 있다.

cat ./data.txt | grep millionth

터미널은 하나의 프로세스다. 명령어를 실행하면 해당 명령어는 기존 터미널(부모 프로세스)의 정보를 기준으로 백그라운드에서 자식 프로세스가 fork 되어 실행한다. 즉, ls라는 명령어를 터미널에 입력하면 자식 프로세스가 fork 되고, 백그라운드에서 부모 프로세스의 정보를 기준으로 stdin으로 정보를 입력 받고, stdout으로 ls 명령어를 호출한 터미널(부모 프로세스)로 정보를 반환하게 된다.

만약 명령어를 파이프로 연결하면 명령어가 실행된 터미널(부모 프로세스)에서 연결된 명령어가 각각의 자식 프로세스로 백그라운드에서 시작하게 된다.

부모 프로세스에서 fork로 시작된 자식 프로세스들은 모두 병렬로 처리되고, 모든 프로세스는 exec 방식으로 호출되기 때문에 동일한 PID를 갖는다. A | B | C가 호출되면 A의 stdout을 B의 stdin으로 읽어 들인다. 마찬가지로 B의 stdout을 C의 stdin이 읽어들인다. 그러므로 A의 stdout이 있기 전까지 B는 wait 상태가 된다.

따라서 ./data.txt 파일을 cat한 stdout은 grep의 stdin으로 처리된다.

0개의 댓글