Bandit

Bandit 워게임으로 리눅스 공부하기 - Bandit Level 5 → Level 6

waterclean101 2023. 8. 24. 09:31

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

→ 다음 단계의 비밀번호는 inhere 디렉토리의 어딘가에 있다. 파일의 조건도 명시해주었다.

 

풀이

1. find의 -size 옵션 알아보기

  • 파일의 조건 중 1033 bytes라는 파일의 사이즈가 우선 file의 -size 옵션을 알아보자.
    1. 정확한 크기 검색:
      • c: 바이트로 크기를 나타낸다. size 1033c는 크기가 정확히 1033 바이트인 파일을 찾는다.
    2. 블록 크기로 검색:
      • 기본적으로 size 옵션은 512바이트 블록 단위로 크기를 나타낸다. 즉, size 2는 크기가 1024바이트 (2 x 512) 인 파일을 찾는다.
    3. 상대적 크기 검색:
      • +: 주어진 크기보다 큰 파일을 검색. size +2k는 크기가 2 킬로바이트보다 큰 파일을 찾는다.
      • ``: 주어진 크기보다 작은 파일을 검색. size -2k는 크기가 2 킬로바이트보다 작은 파일을 찾는다.
    4. 다른 단위로 검색:
      • k: 킬로바이트
      • M: 메가바이트
      • G: 기가바이트
    • size 옵션은 파일의 실제 크기와 파일 시스템에서 차지하는 공간 사이에 차이가 있을 수 있기 때문에, 사용시 주의가 필요하다. 예로 파일이 300 바이트지만 파일 시스템에서 512바이트 블록을 사용하는 경우, 그 파일은 1 블록 크기로 계산된다.
  • size 옵션은 Linux의 find 명령어에서 파일 또는 디렉토리의 크기를 기반으로 검색을 수행할 때 사용하는 옵션이다.

 

2. find로 문제 풀기.

bandit5@bandit:~$ cd inhere

bandit5@bandit:~/inhere$ find ./ -type f -size 1033c # 1
./maybehere07/.file2

bandit5@bandit:~/inhere$ find ./ -type f -size 1033c ! -executable -print # 2
./maybehere07/.file2

bandit5@bandit:~/inhere$ find ./ -type f -size 1033c ! -executable -print | xargs file | grep text # 3
./maybehere07/.file2: ASCII text, with very long lines (1000)
  • cd로 inhere 디렉토리에 접근한 후 다양한 명령으로 파일을 찾았다.
    1. size 만으로 .file2에 비밀번호가 있음을 알아내었다.
    2. 조건에서 executable 하지 않다고 하였음으로 추가하여 검색해보았다. **! -executable**는 실행 가능한 파일을 제외한다는 의미이다.
    3. 모든 조건을 포함하여 find 명령어와 file 명령어를 조합하는 명령어를 만들었다.
    • xargs file: **find**로 찾은 각 파일에 대해 file 명령어를 실행한다.
    • grep text: file 명령어의 출력에서 'text'가 포함된 줄을 검색하여 human-readable한 파일을 확인한다.

 

3. cat으로 읽기

bandit5@bandit:~/inhere$ cat ./maybehere07/.file2
  • 이제 bandit6에 로그인하자.

 

4. bandit6 계정에 로그인

다른 username으로 접속하기 위해 먼저 기존 원격접속을 해제하고 재접속한다.

bandit5@bandit:~$ exit
logout
Connection to bandit.labs.overthewire.org closed.
                                                                                                                                                                                                                                           
┌──(root㉿kali)-[/home/kali]
└─# ssh bandit6@bandit.labs.overthewire.org -p 2220

                         _                     _ _ _   
                        | |__   __ _ _ __   __| (_) |_ 
                        | '_ \\ / _` | '_ \\ / _` | | __|
                        | |_) | (_| | | | | (_| | | |_ 
                        |_.__/ \\__,_|_| |_|\\__,_|_|\\__|
                                                       

                      This is an OverTheWire game server. 
            More information on <http://www.overthewire.org/wargames>

bandit6@bandit.labs.overthewire.org's password: 

      ,----..            ,----,          .---.
     /   /   \\         ,/   .`|         /. ./|
    /   .     :      ,`   .'  :     .--'.  ' ;
   .   /   ;.  \\   ;    ;     /    /__./ \\ : |
  .   ;   /  ` ; .'___,/    ,' .--'.  '   \\' .
  ;   |  ; \\ ; | |    :     | /___/ \\ |    ' '
  |   :  | ; | ' ;    |.';  ; ;   \\  \\;      :
  .   |  ' ' ' : `----'  |  |  \\   ;  `      |
  '   ;  \\; /  |     '   :  ;   .   \\    .\\  ;
   \\   \\  ',  /      |   |  '    \\   \\   ' \\ |
    ;   :    /       '   :  |     :   '  |--"
     \\   \\ .'        ;   |.'       \\   \\ ;
  www. `---` ver     '---' he       '---" ire.org

Welcome to OverTheWire!

패스워드까지 입력하면 접속 성공