Bandit

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

waterclean101 2023. 8. 24. 09:32

Level Goal

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 bandit6
  • 33 bytes in size

Commands you may need to solve this level

ls , cd , cat , file , du , find , grep

→ 다음 단계의 비밀번호는 서버 어딘가에 있다. 파일의 조건도 명시되어있다.

 

풀이

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로 문제 풀기.

bandit6@bandit:~$ find / -size 33c 2>/dev/null

var/lib/dpkg/info/libnss-nis:i386.shlibs
/var/lib/dpkg/info/libmagic1:amd64.shlibs
/var/lib/dpkg/info/libtasn1-6:amd64.shlibs
/var/lib/dpkg/info/libefiboot1:amd64.shlibs
/var/lib/dpkg/info/networkd-dispatcher.conffiles
/var/lib/dpkg/info/bandit7.password
/var/lib/dpkg/info/login.conffiles
/var/lib/dpkg/info/libpython3.10-minimal:amd64.conffiles
/var/lib/dpkg/info/install-info.triggers
/opt/radare2/shlr/www/m/css/networkerr.css
/opt/radare2/libr/arch/p/arm/v35/arch-armv7/.git/refs/remotes/origin/HEAD
/opt/radare2/libr/arch/p/arm/v35/arch-arm64/.git/refs/remotes/origin/HEAD
/home/bandit3/inhere/.hidden
/home/bandit18/readme
/home/bandit2/spaces in this filename
/home/bandit1/-
/home/drifter0/chroot/drifter0.password
/home/bandit4/inhere/-file03
/home/bandit4/inhere/-file06
/home/bandit4/inhere/-file08
/home/bandit4/inhere/-file07
/home/bandit4/inhere/-file04
/home/bandit4/inhere/-file00
/home/bandit4/inhere/-file01
/home/bandit4/inhere/-file02
/home/bandit4/inhere/-file09
/home/bandit4/inhere/-file05
/home/bandit21/.prevpass
/home/bandit17/.bandit16.password
/home/bandit0/readme
/home/bandit16/.bandit15.password
/home/bandit15/.bandit14.password
/home/bandit25/.bandit24.password
  • 사이즈만으로 파일을 찾으니 엄청나게 많은 파일들이 정렬되었다. 그렇다면 주어진 조건 user와 group을 모두 포함해서 찾아야 한다.

 

3. find 옵션 -user, -group

bandit6@bandit:~$ find / -size 33c -user bandit7 -group bandit6 2>/dev/null

/var/lib/dpkg/info/bandit7.password
  • 모든 조건을 포함하니 하나의 파일만이 남았다.

 

4. cat으로 파일읽기

bandit6@bandit:~$ cat /var/lib/dpkg/info/bandit7.password
  • 이제 bandit7에 로그인하자.

 

5. bandit7 계정에 로그인

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

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

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

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

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

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

Welcome to OverTheWire!

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