본문 바로가기
Linux/bandit

[Bandit] Bandit 6 -> 8 풀이

by 끊임없는정진 2022. 11. 5.

▶Bandit 6 -> 7

The password for the next level is stored somewhere on the server and has all of the following properties : owned by user bandit7, owned by group bandit 6, 33 bytes in size 라고 조건을 제시해주고 있다. 조건에 맞는 파일을 찾아야 하는데, 핵심은 "Somewhere on the server" . 즉, 더 이상 홈디렉토리에 국한되어서 찾는 문제가 아님을 알 수가 있다. 전 단계와 같이 find를 쓰는데 조건에 / (슬래쉬) 를 넣는다. 즉, 전체 디렉토리를 다 뒤져보는 것이다. 다음과 같이 명령어를 내리면 되지만, 권한이 없는 파일이 대다수라 standard error(2)에 해당하는 정보가 많이 나오는 관계로 이 정보들은 걸러서 볼 필요가 있다. 이는 리눅스 기초에서 보았던 리다이렉션(> or >>) 기능을 활용하면 된다. 에러정보만 /dev/null 경로로 보내서 걸러서 보려면 2> 로 리다이렉션 해주면 된다. 리다이렉션 없이, 그리고 리다이렉션과 함께 쓰는 명령어는 다음과 같다. 

1
2
3
4
bandit6@bandit:~$ find / -user bandit7 -group bandit6 -size 33c
...
bandit6@bandit:~$ find / -user bandit7 -group bandit6 -size 33c 2> /dev/null
/var/lib/dpkg/info/bandit7.password
cs

 

▶Bandit 7 -> 8

data.txt 에서 millionth 단어 바로 다음에 password가 있다고 한다. 이를 해결하는 방법은 3가지로 나눠서 볼 수 있겠다. 

(1) vi 모드 활용 : vi data.txt 로 파일을 연 다음, 명령모드에서 /millionth 를 입력하면 해당 문자를 찾아준다. 

1
2
bandit7@bandit:~$ vi data.txt
이후 명령모드에서 /millionth 입력
cs

 

(2) cat 명령어에서 pipe(|) 를 쓰는 방법

1
2
bandit7@bandit:~$ cat data.txt | grep millionth
millionth       TESKZC0XvTetK0S9xNwm25STk5iWrBvP
cs

 

(3) 순수 grep 명령어만 쓰는 방법

1
2
bandit7@bandit:~$ grep millionth ./data.txt
millionth       TESKZC0XvTetK0S9xNwm25STk5iWrBvP
cs

 

 

 

출처 : https://man7.org/linux/man-pages/

https://overthewire.org/wargames/bandit

https://academy.segfaulthub.com/

'Linux > bandit' 카테고리의 다른 글

[Bandit] Bandit 0 -> 6 풀이  (1) 2022.11.02

댓글