[overthewire] Bandit Level 4 → Level 5

moon_security·2025년 2월 25일

[OverTheWire] Bandit

목록 보기
6/32

문제 목표

The password for the next level is stored in the only human-readable file in the inhere directory. Tip: if your terminal is messed up, try the “reset” command.

비밀번호는 inhere 디렉토리 안에 '사람이 읽을 수 있는 유일한 파일'에 저장된다고 합니다. 무슨 말씀인지 잘 모르겠네요.
일단 inhere 디렉토리로 이동하여 ls-la 명령어를 실행하여 보니 -file00 부터 -file09까지의 파일이 보입니다.

bandit4@bandit:~/inhere$ ls -la
total 48
drwxr-xr-x 2 root    root    4096 Sep 19 07:08 .
drwxr-xr-x 3 root    root    4096 Sep 19 07:08 ..
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file00
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file01
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file02
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file03
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file04
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file05
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file06
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file07
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file08
-rw-r----- 1 bandit5 bandit4   33 Sep 19 07:08 -file09

아무 파일이나 cat 명령어를 사용하여 읽어보니 아래와 같은 화면이 출력됩니다.

bandit4@bandit:~/inhere$ cat -file04
cat: invalid option -- 'f'
Try 'cat --help' for more information.

아마 ls -al에서의 -al처럼 -flile04를 옵션으로 인식하고 파일을 못 읽는 것 같습니다.
경로를 포함하여 모든 파일을 한번에 읽어보도록 하겠습니다.

bandit4@bandit:~/inhere$ cat ./-file00 ./-file01 ./-file02 ./-file03 ./-file04 ./-file05 ./-file06 ./-file07 ./-file08 ./-file09
?p??&?y?,?(jo?.at?:uf?^???@i?R?,?Λ?:Y?????%?A????B??ͩ?3?	?)Ʈ?#Y??-6c??IR-?$????:?????/?
                                                                                      ??????qGi??,?2?Yb?
dۙ?rOx????h0~ey
??c?~?h?n??G1}???ߓ??ߤ??W>??#lk?d?ܮ??yE??6?0]?\?$?1?%???????o@??b/??4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw
?nS?
?<??]?
W??e?˥m?????O??D??2g????????`>5HYA?u???8?g?`0?$`??

알수 없는 문자가 나오네요.

문제 풀이!

-file00 ~ -file09의 데이터 타입을 확인해 봐야 할 듯 합니다.
파일의 형식을 알기 위해서는 file 명령어를 사용하면 됩니다.

bandit4@bandit:~/inhere$ file ./-file00
./-file00: data

-file00의 파일 형식을 알아보니 data라는 군요!

file 명령어를 사용했을 때 사람이 읽을 수 없는 형식을 data로 표현합니다.
1. 바이너리 파일: 사람이 직접 읽을 수 없는 파일로 exe, zip 확장자 등 존재
2. 암호화된 파일
3. 특정한 인코딩이 없는 파일: UTF-8, ASCII, Unicode 같은 문자 인코딩 없음

-file00부터 -file09까지의 파일 형식을 알아보면 '사람이 읽을 수 있는 파일'을 알 수 있겠군요!
현재 폴더에 있는 모든 파일에 대한 파일 형식을 출력했습니다.
-file07이 ASCII text로 확인되네요!

bandit4@bandit:~/inhere$ file ./*
./-file00: data
./-file01: data
./-file02: data
./-file03: data
./-file04: data
./-file05: data
./-file06: data
./-file07: ASCII text
./-file08: data
./-file09: data

해당 파일 읽어보니 비밀번호가 출력됐습니다 :)

bandit4@bandit:~/inhere$ cat ./-file07
4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw
profile
모의해킹 & 보안 공부 기록 블로그

1개의 댓글

comment-user-thumbnail
2025년 2월 27일

오호! 비밀번호 출력!

답글 달기