본문 바로가기
IT 및 정보보호 관련 소식&정보

Linux study_OverTheWire[03: linux strings, tr, xxd, nc]

by 건행오 2020. 4. 21.
반응형

안녕하세요. 은남입니다. :)

 

리눅스 공부차 포스팅합니다.

Over The Wire

Over The Wire :Bandit

 

OverTheWire: Bandit

We're hackers, and we are good-looking. We are the 1%. Bandit The Bandit wargame is aimed at absolute beginners. It will teach the basics needed to be able to play other wargames. If you notice something essential is missing or have ideas for new levels, p

overthewire.org


Bandit Level 10 → Level 11

Level Goal

The password for the next level is stored in the file data.txt, which contains base64 encoded data

 

패스워드가 data.txt에 있는데 base64로 인코딩 되어 있다네요. 

data파일을 그냥 열어보니 그렇네요

base64 디코딩

구글링하여 base64 decode 하는 명령어를 찾았습니다.

strings data.txt | base64 --decode

인코딩하는 것은 base4 만 넣으면 됩니다.

example


Bandit Level 11 → Level 12

Level Goal

The password for the next level is stored in the file data.txt, where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions

 

이번에도 data.txt파일입니다. 소문자, 대문자는 13개의 포지션으로 바뀌었다는데... 뭔 말인지 한참 찾아보게 되었네요,.

그래서 이번엔 문제 아래에 있는 문구를 따라 위키디피아를 뒤져봤습니다.

Helpful Reading Material

보니...

ROT13 ( " 13 자리 씩 회전 ", 때로는 하이픈이 붙은 ROT-13 )은 알파벳에서 그 뒤에 13 번째 문자로 문자를 대체하는 간단한 문자 대체 암호라고

ROT13

즉... 

ABCDEFGHIJKLM        ▷  NOPQRSTUVWXYZ

NOPQRSTUVWXYZ      ▷  ABCDEFGHIJKLM

 

abcdefghijklm      ▷  nopqrstuvwxyz

nopqrstuvwxyz    abcdefghijklm  

이라는 의미입니다..

 

그래서 이번엔 리눅스 명령어 중 tr을 사용하였습니다.

우선 그냥 열어보았을 땐 특이사항 없어 보여요

암호화 되어 있음

tr을 통하여 변환하면 다음과 같습니다.

cat data.txt |tr "[a-zA-Z]" "[n-za-mN-ZA-M]"

tr "[a-zA-Z]" "[n-za-mN-ZA-M]" < data.txt

Linux tr 옵션에 대해서 간략히 설명드리면 다음과 같아요

tr +옵션 + 문자열 1 + 문자열 2

-d, --delete : 문자열 1에서 지정한 문자를 삭제

-s, --squeeze-repeats : 문자열 2에서 반복되는 문자를 삭제

-t, --truncate-set1 : 문자열 1을 문자열 2의 길이로 줄이기

처음 써보다 보니 이런저런 테스트를 해봤습니다.

실제로 해당 파일내용에 수정을 가하지는 않고 출력 시에 만 변경되어 나옵니다.

소문자를 대문자로
숫자 제거
중복값 제거


Bandit Level 12 → Level 13

Level Goal

The password for the next level is stored in the file data.txt, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work using mkdir. For example: mkdir /tmp/myname123. Then copy the datafile using cp, and rename it using mv (read the manpages!)

 

이번엔 hexdump 라네요.... 16진수로 나열되어 있겠군요. 역시 이러합니다.

hex dump

우선 문제에서 하라는 데로 해보았습니다.

문제대로 해보기

다음을 진행하려고 찾아보니 xxd라는 명령어를 사용해야 한다고 합니다.

xxd --help를 하니 다양한 옵션이 나오는데, 그중 xxd -r이 convert hexdump into binary 기능이어서 이를 이용합니다.

xxd -r password.txt > password.bin

reverse

그래서 해당 파일 정보를 봤더니 gzip으로 압축되어있다고 합니다. 그래서 이를 풀어봅니다.

file gzip
gzip

압축을 푸실 때 확장자를 gz로 해주셔야 합니다. 풀고 파일 속성을 보니 이번엔... bzip. 그 이후에는 tar까지  리눅스 압축파일이 연속되어 나옵니다. 즉 압축에 압축에 압축.....

bandit12@bandit:/tmp/ennam$ mv pass.out pass.gz

bandit12@bandit:/tmp/ennam$ gzip -d pass.gz

bandit12@bandit:/tmp/ennam$ ls

pass  password.txt

bandit12@bandit:/tmp/ennam$ file pass

pass: POSIX tar archive (GNU)

---------

bandit12@bandit:/tmp/ennam$ file data5.bin

data5.bin: POSIX tar archive (GNU)

bandit12@bandit:/tmp/ennam$ tar -xvf data5.bin

data6.bin

 

계속 이런 식으로 노가다를 했는데, 이런 명령어가 있더라고요.

bzcat // zcat

bzcat : bzip2 파일을 해제 후 원하는 파일명으로 생성

zcat : gzip 파일을 해제 후 원하는 파일명으로 생성

 

bandit12@bandit:/tmp/ennam$ file data6.bin

data6.bin: bzip2 compressed data, block size = 900k

bandit12@bandit:/tmp/ennam$ bzcat data6.bin > data7

 

bandit12@bandit:/tmp/ennam$ file data8.bin

data8.bin: gzip compressed data, was "data9.bin", last modified: Tue Oct 16 12:00:23 2018, max compression, from Unix

bandit12@bandit:/tmp/ennam$ zcat data8.bin > data9

 

이렇게 노가다를 이어가다 보니 끝이 났습니다....

8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL

data9 password


Bandit Level 13 → Level 14

Level Goal

The password for the next level is stored in /etc/bandit_pass/bandit14 and can only be read by user bandit14. For this level, you don’t get the next password, but you get a private SSH key that can be used to log into the next level. Note: localhost is a hostname that refers to the machine you are working on

 

해당 경로에 패스워드가 있으나 사용자가 bandit14여야 된다 합니다. 그래서 ssh key가 있으니 이걸 이용해서 다음으로 가라 합니다.

 

ssh를 이용해야 되지 싶어서 man ssh 하여 이용방법을 봤습니다.

ssh -i (identity file)

: Selects a file from which the identity (private key) for public key authentication is read. 

이걸 사용하면 될듯합니다.

ssh -i sshkey.private bandit14@localhost

ssh


Bandit Level 14 → Level 15

Level Goal

The password for the next level can be retrieved by submitting the password of the current level to port 30000 on localhost.

 

우선 앞 단계의 패스워드 먼저 확인하겠습니다.

bandit14 패스워드가 확인됩니다.

bandit14 passwords

그럼 다음 패스워드는 localhost 상 30000 포트를 이용하여 검색되는 애라고 합니다.

 

그래서 이번엔 nc라는 옵션을 활용하였습니다.

nc 활용

문제 상 hint 내에 openssl, s_client라는 게 있어서 찾아보았는데요.

▶OpenSSL : SSL과 TLS 프로토콜을 구현한 라이브러리 중 하나로 오픈 소스로 구현되어 있습니다. 이를 이용하여 통신 전문을 암호화하거나 문서를 암호화할 수 있습니다.

▶s_client : OpenSSL 명령으로 운영 중인 웹서버의 SSL 인증서 정보를 확인 가능합니다. SSL 및 TLS를 사용하는 원격 호스트에 접속하기 위한 client 구현하는 명령어입니다.

opensl s_client -connect localhost:30001

 

bandit15 접근 패스워드는 BfMYroe26WYalil77FoDi9qh59eK5xNr  요놈이네요.ㅎㅎ

 

2020/04/19 - [법대생이 공부하는 IT&정보보호 컴플라이언스] - Linux study_Over The Wire_bandit[02: find -size, ls -alp, strings]

2020/04/16 - [법대생이 공부하는 IT&정보보호 컴플라이언스] - Linux study_Over The Wire_bandit [01 : ls, cat, find -type ]

 

반응형

댓글