Post

Bandit Level 12 → Level 13

문제

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

목표

여러 번 압축된 hexdump인 data.txt 파일에 저장되어 있는 패스워드를 찾는다.

이 레벨에서는 /tmp에 mkdir 명령어를 사용해 디렉토리를 만드는 것이 유용하다.

풀이

목표에 있는 설명대로 디렉토리를 만든다.

1
bandit12@bandit:~$ mkdir /tmp/new_dir


파일을 새로 만든 디렉토리로 복사해준다.

1
bandit12@bandit:~$ cp data.txt /tmp/new_dir


new_dir로 이동한다.

1
bandit12@bandit:~$ cd /tmp/new_dir


data.txt 파일을 확인해보니 hexdump인 것을 알 수 있다.

1
2
3
4
5
6
7
8
9
10
bandit12@bandit:/tmp/new_dir$ cat data.txt
00000000: 1f8b 0808 6855 1e65 0203 6461 7461 322e  ....hU.e..data2.
00000010: 6269 6e00 013d 02c2 fd42 5a68 3931 4159  bin..=...BZh91AY
00000020: 2653 5948 1b32 0200 0019 ffff faee cff7  &SYH.2..........
.
.
.
00000230: 003c a584 d4c1 61ef eb02 3f65 3a54 a3a2  .<....a...?e:T..
00000240: a565 c154 34c2 b162 d206 1ff8 bb92 29c2  .e.T4..b......).
00000250: 8482 40d9 9010 b3a9 e478 3d02 0000       ..@......x=...


xxd data.txt > data 명령으로 새 파일에 바이너리 파일로 저장한다.

1
bandit12@bandit:/tmp/new_dir$ xxd -r data.txt > data

xxd -r data.txt > dataxxd -r data.txt의 출력을 data 파일에 저장한다는 의미이다.


data 파일의 형식을 확인한다.

1
2
bandit12@bandit:/tmp/new_dir$ file data
data: gzip compressed data, was "data2.bin", last modified: Thu Oct  5 06:19:20 2023, max compression, from Unix, original size modulo 2^32 573

gzip으로 압축된 파일인 것을 알 수 있다.


압축을 풀려면 파일에 맞는 확장자로 변경해줘야 한다.

파일의 이름은 mv 명령어를 사용해 변경할 수 있다.

1
bandit12@bandit:/tmp/new_dir$ mv data data.gz


gzip 파일의 압축을 풀려면 gzip 명령어의 -d 옵션을 사용해야 한다.

1
bandit12@bandit:/tmp/new_dir$ gzip -d data.gz


다시 파일을 확인해보니 bzip2로 압축된 파일인 것을 알 수 있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data
data: bzip2 compressed data, block size = 900k


data 파일의 확장자를 bzip2 파일의 확장자인 bz로 변경해야 한다.

1
bandit12@bandit:/tmp/new_dir$ mv data data.bz


bzip2 파일의 압축을 풀려면 bzip2 명령어의 -d 옵션을 사용해야 한다.

1
bandit12@bandit:/tmp/new_dir$ bzip2 -d data.bz


다시 file data 명령으로 파일을 확인해보니 gzip으로 압축된 파일인 것을 알 수 있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data
data: gzip compressed data, was "data4.bin", last modified: Thu Oct  5 06:19:20 2023, max compression, from Unix, original size modulo 2^32 20480


확장자를 변경하고 압축을 푼다.

1
2
bandit12@bandit:/tmp/new_dir$ mv data data.gz
bandit12@bandit:/tmp/new_dir$ gzip -d data.gz

다시 파일을 확인해보니 tar로 압축된 파일인 것을 알 수 있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data
data: POSIX tar archive (GNU)


tar 파일의 압축을 풀려면 tar 명령어의 -xvf 옵션을 사용해야 한다.

1
2
bandit12@bandit:/tmp/new_dir$ tar -xvf data
data5.bin


data5.bin 파일을 확인해보니 tar로 압축되어있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data5.bin
data5.bin: POSIX tar archive (GNU)


확장자를 변경하고 압축을 푼다.

1
2
3
bandit12@bandit:/tmp/new_dir$ mv data5.bin data5.bin.tar
bandit12@bandit:/tmp/new_dir$ tar -xvf data5.bin.tar
data6.bin


data6.bin 파일을 확인해보니 bzip2로 압축되어 있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data6.bin
data6.bin: bzip2 compressed data, block size = 900k


확장자를 변경하고 압축을 푼다.

1
2
bandit12@bandit:/tmp/new_dir$ mv data6.bin data6.bin.bz
bandit12@bandit:/tmp/new_dir$ bzip2 -d data6.bin.bz  

data6.bin 파일을 확인해보니 tar로 압축되어 있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data6.bin
data6.bin: POSIX tar archive (GNU)


확장자를 변경하고 압축을 푼다.

1
2
3
bandit12@bandit:/tmp/new_dir$ mv data6.bin data6.bin.tar
bandit12@bandit:/tmp/new_dir$ tar -xvf data6.bin.tar
data8.bin


data8.bin 파일을 확인해보니 gzip으로 압축되어 있다.

1
2
bandit12@bandit:/tmp/new_dir$ file data8.bin
data8.bin: gzip compressed data, was "data9.bin", last modified: Thu Oct  5 06:19:20 2023, max compression, from Unix, original size modulo 2^32 49


확장자를 변경하고 압축을 푼다.

1
2
bandit12@bandit:/tmp/new_dir$ mv data8.bin data8.bin.gz
bandit12@bandit:/tmp/new_dir$ gzip -d data8.bin.gz


data8.bin 파일을 확인해보니 ASCII 코드로 작성된 텍스트 파일이다.

1
2
bandit12@bandit:/tmp/new_dir$ file data8.bin
data8.bin: ASCII text


data8.bin 파일의 내용을 확인한다.

1
2
bandit12@bandit:/tmp/new_dir$ cat data8.bin
The password is wbWdlBxEir4CaE8LaPhauuOo6pwRmrDw


Password : wbWdlBxEir4CaE8LaPhauuOo6pwRmrDw

배운 것

  • xxd 명령어의 -r 옵션으로 hexdump를 바이너리 데이터로 변환할 수 있다.
  • >으로 출력을 파일에 저장할 수 있다.
  • file 명령어로 파일의 형식을 출력할 수 있다.
  • gzip 파일은 gzip 명령어의 -d 옵션,
    bzip2 파일은 bzip2 명령어의 -d 옵션,
    tar 파일은 tar 명령어의 -xvf 옵션으로 압축을 풀 수 있다.
This post is licensed under CC BY 4.0 by the author.