Level 4 -> Level 6
Level 4 -> Level 5
<Level Goal>
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 "reset" command
Approach
inhere 디렉토리의 사람만 읽을 수 파일에 password가 있다고 한다.
예상대로 파일 이름들이 정상적이지는 않다. -로 시작하니 리디렉션으로 해석될 확률이 커보인다.
bandit4@bandit:~/inhere$ ls
-file00 -file01 -file02 -file03 -file04 -file05 -file06 -file07 -file08 -file09
그래서 파일명으로 해석하는 more 명령어를 써봤다. 하지만 error 메시지가 났고, 내용을 보니 리디렉션이나 옵션으로 해석된 것이 문제인 듯 하다.
bandit4@bandit:~/inhere$ more -file00
more: invalid option -- 'i'
Try 'more --help' for more information.
그래서 리디렉션 기호 <를 사용해서 파일 내용을 표준 입력으로 전달해봤다. -file00이 명령어 옵션이 아니라 파일 이름이라는 것을 조금 더 명확히 하기 위해서이다. 그랬더니 뭔가 이상한 문자열이 출력되었다.
bandit4@bandit:~/inhere$ more < -file00
�p��&�y�,�(jo�.at�:uf�^���@
그래서 모든 파일의 내용을 읽어보기로 했다. 와일드카드를 사용해 모든 파일을 읽으려 했으나 명확하지 않은 리디렉션이라는 에러가 났다.
bandit4@bandit:~/inhere$ more < -file*
-bash: -file*: ambiguous redirect
그래서 그냥 파일 하나하나 모두 읽어보기로 했다. 그 전에 출력된 이상한 문자열을 아스키코드 변환, 16진수 변환해서 의미있는 문자열을 찾아내고자 했다(file*의 모든 문장을 합쳐야 답이 나올 것이라고 생각해서). 하지만 유의미한 결과값이 나오지 않아, Level Goal에 있던 human readable file에 대해 검색해봤다. 그리고 find 명령어를 사용해 읽을 수 있는 파일을 찾아보라는 힌트를 얻었다.
Solve
file 명령어는, 지정된 파일의 종류(타입)을 확인하는 명령어이다. 현재 파일 이름이 -로 시작하기 때문에 잘못 해석될 여지가 있다. 그래서 ./로 현재 디렉토리의 파일이라는 것을 명시하고 와일드 카드를 사용해 inhere 디렉토리의 모든 파일들의 종류를 확인했다.
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
-file07이 아스키 텍스트로 적혀있다는 것을 알게 되었고, 해당 파일을 열어보니 password가 있었다. level 4도 클리어다!
-> 인간이 읽을 수 있는 파일은 ASCII text로 적힌 파일인가보다.
bandit4@bandit:~/inhere$ more < -file07
4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw
Level 5 -> Level 6
<Level Goal>
The password for the next level is stored in a file somewhere under the inhere directory and has all of the following properties: human-readable, 1033 bytes in size, not executable
Approach
복잡해보이지만 생각보다 간단하다. inhere 디렉토리 아래에 정말 많은 하위 디렉토리가 존재하는데, 이 하위 디렉토리 안에 또 파일들이 들어있다. inhere 디렉도리 하위에 존재하는 모든 파일들 중 human-readable(ASCII text) + 1033 bytes + 실행 가능하지 않은? 이 조건을 만족하는 곳에 password가 존재한다고 한다.
아래와 같은 구조로 되어있으며, maybehere[0*] 디렉토리를 모두 검색해보면 답이 나올 것 같긴 하다.
bandit5@bandit:~/inhere$ ls
maybehere00 maybehere03 maybehere06 maybehere09 maybehere12 maybehere15 maybehere18
maybehere01 maybehere04 maybehere07 maybehere10 maybehere13 maybehere16 maybehere19
maybehere02 maybehere05 maybehere08 maybehere11 maybehere14 maybehere17
bandit5@bandit:~/inhere$ cd maybehere00
bandit5@bandit:~/inhere/maybehere00$ ls
-file1 -file2 -file3 spaces file1 spaces file2 spaces file3
bandit5@bandit:~/inhere/maybehere00$ file ./*
./-file1: ASCII text, with very long lines (1038)
./-file2: ASCII text, with very long lines (9387)
./-file3: OpenPGP Secret Key
./spaces file1: ASCII text, with very long lines (6117)
./spaces file2: ASCII text, with very long lines (6849)
./spaces file3: data
하지만 ls 명령어 옵션 -R(위치한 디렉토리 하부 디렉토리의 파일까지 모두 출력)이 떠올랐고, file 명령어 또는 find 명령어에도 이런 옵션이 있을 것 같다는 생각이 들었다. 이런 옵션이 존재한다면 inhere 하위의 모든 디렉토리와 파일이 출력되므로 하나하나 명령어를 입력하지 않아도 된다.
->파일 타입과 파일 사이즈가 주어졌으니 이것을 이용해서 필터링 하면 되지 않을까?
Solve
일단 find 명령어를 이용해 size가 1033 bytes인 파일을 찾는것은 성공했다. find 경로를 inhere 디렉토리 하위의 maybehere* 하위의 파일과 디렉토리로 설정했다. 그리고 1033 뒤의 c는 byte 단위인 것을 명시해주는 것이다.
그런데 .file2? 숨겨진 파일이다.
bandit5@bandit:~/inhere$ find ./maybehere* -size 1033c
./maybehere07/.file2
그래서 maybehere07 디렉토리의 모든 파일, 디렉토리를 출력해봤다. 와 숨겨진 파일이 있다.
andit5@bandit:~/inhere/maybehere07$ ls -a
. -file1 -file2 -file3 spaces file1 spaces file3
.. .file1 .file2 .file3 spaces file2
file 명령어에서는 숨겨진 파일에 대한 정보는 출력되지 않는다. 진짜 하나하나 찾았다면 답을 못 찾았을 것 같다.
bandit5@bandit:~/inhere/maybehere07$ file ./*
./-file1: ASCII text, with very long lines (3662)
./-file2: ASCII text, with very long lines (2487)
./-file3: data
./spaces file1: ASCII text, with very long lines (4129)
./spaces file2: ASCII text, with very long lines (9063)
./spaces file3: data
숨겨진 파일인 .file2를 cat 명령어로 읽어보면 password가 나온다. level 5 클리어다!
bandit5@bandit:~/inhere/maybehere07$ cat .file2
HWasnPhtq9AVKe0dmk45nxy20cvUa6EG
More
01. not execytable?
password가 들어있는 파일의 조건 중 'not executable' 이런게 있었다. 이건 무슨 의미인지 알아봤다.
ls -l 명령어는 숨겨진 파일에 대한 정보는 출력하지 않으니 ls -al 명령어를 통해 파일들을 살펴보았다. .file2를 살펴보면 읽기 권한 r과 쓰기 권한 w만 있는 상태이다. 'not executable'은 x 권한이 없는 것을 의미하지 않았나...? 싶다.
bandit5@bandit:~/inhere/maybehere07$ ls -al
total 56
drwxr-x--- 2 root bandit5 4096 Sep 19 07:08 .
drwxr-x--- 22 root bandit5 4096 Sep 19 07:08 ..
-rwxr-x--- 1 root bandit5 3663 Sep 19 07:08 -file1
-rwxr-x--- 1 root bandit5 3065 Sep 19 07:08 .file1
-rw-r----- 1 root bandit5 2488 Sep 19 07:08 -file2
-rw-r----- 1 root bandit5 1033 Sep 19 07:08 .file2
-rwxr-x--- 1 root bandit5 3362 Sep 19 07:08 -file3
-rwxr-x--- 1 root bandit5 1997 Sep 19 07:08 .file3
-rwxr-x--- 1 root bandit5 4130 Sep 19 07:08 spaces file1
-rw-r----- 1 root bandit5 9064 Sep 19 07:08 spaces file2
-rwxr-x--- 1 root bandit5 1022 Sep 19 07:08 spaces file3
02. find의 지정된 경로 범위
(find 명령어 정리된 사이트: https://coding-factory.tistory.com/804)
<find 명령어의 동작 원리>
1) ./maybehere*로 지정된 경로가 디렉토리이면, 그 디렉토리의 모든 하위 파일과 하위 디렉토리까지 포함하여 탐색한다.
2) ./maybehere*로 지정된 경로가 파일이면, 해당 파일만 확인한다.
위와 같은 이유로 ./maybehere*과 ./의 출력 결과가 동일하다. 지정된 경로의 모든 하위 디렉토리와 하위 파일을 포함하여 검색하기 때문이다.
andit5@bandit:~/inhere$ find ./maybehere* -size 1033c
./maybehere07/.file2
bandit5@bandit:~/inhere$ find ./ -size 1033c
./maybehere07/.file2