Bandit Level 9 → Level 10

Minchae Kim·2023년 5월 15일
0

📌 Level 9 → Level 10


https://overthewire.org/wargames/bandit/bandit10.html

🚩 Level Goal

The password for the next level is stored in the file data.txt in one of the few human-readable strings, preceded by several ‘=’ characters.

🚩 Problem Solving

Level goal에 제시된 것과 같이, = 기호를 포함하는 라인을 찾아야 한다. 이전 level에서 다루었던 grep 명령어와, |를 이용하여 출력해보았다.

bandit9@bandit:~$ cat data.txt | grep "="
grep: (standard input): binary file matches

출력된 내용을 보면, binary file이기 때문에 grep 명령어를 사용할 수 없다고 한다.

🔹 Process

이러한 상황에서 grep 명령어를 원활하게 사용하려면, binary file을 text file처럼 처리하는 -a option을 사용해야 한다. 물론, 해당 option을 사용해도 여전히 파일 형태를 육안으로 확인하기 어려움으로 다른 방법을 사용해야 한다.

file에 포함된 문자열을 출력하는 strings 명령을 활용하면, 파일 안에 포함된 문자열을 뽑아낼 수 있다. 이렇게 뽑아낸 문자열을 |을 통해 grep에게 넘겨준다면, human-readable 텍스트를 출력해낼 수 있다.

strings data.txt | grep "="
→ (생략) ========== G7w8LIi6J3kTb8A7j9LgrywtEUlyyp6s

생략한 부분에는 = 기호가 포함된 라인들이 모두 출력됨으로, password가 있는 라인만 확인하면 된다.

🔹 Password

Bandit10 Password : G7w8LIi6J3kTb8A7j9LgrywtEUlyyp6s

📌 Linux Commands


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

🚩 grep (Binary file matches)

앞서 언급했듯이, 특정 파일 내용을 출력하려고 하면 Binary file matches라는 메세지와 함께 명령을 수행하지 못하는 일이 발생한다. 해당 파일이 대부분 문자열로 인코딩 된 파일이지만, 특정 라인 때문에 data file로 인식될 수 있고, 이 경우 grep은 이를 'binary' 파일로 간주하게 된다.

  • 다시 한 번 더 강조하지만, binary file일 경우 option 없이 grep 할 수 없다.

🔹 option

이를 해결하기 위해서는, 모든 파일을 text file로 인식하여 명령어를 수행하도록 도와주는 grep 명령어의 option 중 하나인 -a를 사용해야 한다. 즉 -a 옵션을 사용하면 binary file을 text file로 인식해 내용을 검색할 수 있게 도와준다는 뜻이다.

cat data.txt | grep -a "===="

물론 해당 level에서는 원활하게 text file로 처리되었으나, 여전히 육안으로 확인하기에 어려움이 있어 파일에 포함된 문자열을 출력할 수 있는 strings 명령어를 사용해야 한다.

🚩 strings

strings 명령어는 실행 파일인 ASCII 문자를 찾아 화면에 출력한다. Binary file 또는 Object file에 있는 모든 인쇄 가능한 문자열을 추출하여 출력하기에 유용한 명령어이다.

strings [file name][option]

예시로, data.txt file에는 ASCII 코드가 아닌 코드들이 섞여 있어 제대로 읽을 수 없다. 그렇기에 strings 명령어로 data.txt file를 실행하면 읽을 수 있는 문자열만 출력하게 된다.

profile
Security Researcher 시켜줘 !

0개의 댓글