워게임/CyKor 자체 과제

overthewire-bandit level0->level27

overthewire


📒 level 0 -> level 1

바로 있다 !!
level1 pw : boJ9jbbUNNfktd78OOpsqOltutMc3MY1


📒 level1 -> level2

Level Goal

The password for the next level is stored in a file called - located in the home directory

 

home directory의 -에 저장되어있다고 한다.

하지만 그냥 cat - 명령을 하게 되면 그냥 옵션으로 인식하게 된다.

그러니 cat ./- 를 하게되면, 현재 폴더 내의 -라는 파일로 인식하게 된다.

level2 pw : CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9


📒 level2 -> level3

Level Goal

The password for the next level is stored in a file called spaces in this filename located in the home directory

파일 이름에 스페이스가 존재한다. 이럴 때는 어떻게 해야할까?

그럴 때는 그냥 따옴표로 묶어주자.

level3 pw : UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK


📒 level3 -> level4

Level Goal

The password for the next level is stored in a hidden file in the inhere directory.

inhere directory를 봐야할 것 같다.

ls명령을 통해서는 아무것도 보이지 않아 ls -al을 해주었더니 .hidden이 보인다.

level4 pw : pIwrPrtPN36QITSp3EQaw936yaFoFgAB


📒 level4 -> level5

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 the “reset” command.

 

또 inhere directory를 봐보자.

무지성으로 file 명령어를 남발해보았고, ASCII text가 있음을 확인했다.

 

level5 pw : koReBOKuIDDepwhWk7jZC0RTdopnAYKh


📒 level5 -> level6

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

이전 문제에서 byte가 1033이며 실행불가능한 파일을 찾아봐야 할 것 같다.

find 명령을 이용해 찾으면 될 듯 하다.

https://recipes4dev.tistory.com/156 find 명령에 관한 설명이 나와있는 글이다.

우선 -size 옵션을 1033c로 줘보자.

 

level6 pw : DXjZPULLxYr17uwoI01bNLQbtFemEgo7


📒 level6 -> level7

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

size는 33byte이므로 이전 문제처럼 옵션을 주면 될 것 같다.

하지만 uid, gid (userid, groupid) 설정을 좀 해주어야 할 것 같다. ( 기억이 가물가물 )

그리고 또 다른 중요한 건, 서버 어딘가에 저장되어 있으니 그것 또한 찾아야 한다.

해커스쿨 ftz에서 find 문제와 약간 유사하다.

-user bandit7 -group bandit6 2> /dev/null

옵션을 주면 문제를 해결할 수 있다. (뒤에 2> /dev/null은 permission denied 에러 메시지를

출력하지 않을 수 있다.)

 

level7 pw : HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs


📒 level7 -> level8

Level Goal

The password for the next level is stored in the file data.txt next to the word millionth

 

?? data.txt 파일 내에서 millionth라는 단어 옆에 저장되어있다고 한다.

이럴 때 grep 명령을 통해 문자열을 찾을 수 있는데,

grep -r '찾을 문자열' 대상파일
이런 형식으로 넘겨주면된다.

level8 pw : cvX2JJa4CFALtqS87jk27qwqGhBM9plV


📒 level8 -> level9

Level Goal

The password for the next level is stored in the file data.txt and is the only line of text that occurs only once

 

음.... sort/uniq 명령을 사용해야 할 것 같다.

https://websecurity.tistory.com/80

나도 처음 사용하는 명령이므로 블로그 글을 확인해봤다.

그냥 uniq 명령만 사용하게 되면 중복된 행이 떨어져 있을 경우 인식이 되지 않는 문제가 있었다.

그래서 sort data.txt | uniq -u 이렇게 해주면 된다. 파이프라인으로 넘겨주는 것이다.

 level9 pw : UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR


📒 level9 -> level10

Level Goal

The password for the next level is stored in the file data.txt in one of the few human-readable strings, preceded by several ‘=’ characters.

 

 

data.txt에 저장되어 있고, '=' 문자를 봐야 한다. grep으로 찾아보자

Binary File이라 grep이 먹히지 않는 것 같다.

strings data.txt를 하면

보기쉽게 확인된다.

하지만 =으로 시작하는 저 부분 확인을 할 수는 없는 것일까.

이런 방법도 있다. strings 명령을 통해 나온 것을 다시 grep으로 돌려주는 것이다.
(이런 경우는 grep -a data.txt를 통해 바이너리 모드로 실행시킬 수도 있다.)

 

level10 pw : truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk

 


📒 level10 -> level11

Level Goal

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

 

대충 base64로 암호화되어있단다.

cat data.txt | base64 -d

쉬우니까 사진은 미첨부.

The password is IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR


📒 level11 -> level12

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

 

시저암호인가?

 

Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh

복호화를 진행해보자.

The password is 5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu

 

쉬우니까 사진 미첨부.


📒 level12 -> level13

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!)

덤프파일이 보인다. xxd -r 옵션을 통해 binary로 바꿀 수 있다.

분석을 좀 해주기 위해 /tmp/samdasoo로 옮겨주자.

그리고 xxd -r 명령을 통해 bandit12라는 파일에 써주면 이렇게 바이너리가 확인이 된다.

문제에서 여러번 압축(compress) 했다 하니 압축을 풀어주면 될 것 같다.

gzip으로 압축이 되었음을 확인할 수 있다. 그러기 위해 bandit12에 확장자 .gz를 붙여주자 (나는 cp 이용)

그리고 압축을 해제해주면 이번엔 bzip2으로 압축된 것을 확인할 수 있다.

이걸 노가다 급으로 8번 ~ 9번 정도 반복해주면 된다.

The password is 8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL


📒 level13 -> level14

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

 

다음 패스워드는 /etc/bandit_pass/bandit14에 저장되어 있다고 한다. 현재 나는 bandit13인데 bandit14이어야 읽을 수 있다고 한다. 이번 단계는 비밀번호를 몰라도 넘어갈 수 있는데, SSH key를 얻어야 하는 듯 하다.

내 기억상 이 파일을 가지고 비밀번호 없이 로그인 할 수 있던 걸로 기억한다.

nmap으로 ssh 포트를 찾아주자. => 22

ssh 사용법을 보면 -i 옵션을 통해 private key file을 넘겨줄 수 있을 것 같다.

짜잔 ! (비밀번호는 없음)


📒 level14 -> level15

Level Goal

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

 

실제로 30000번 포트는 ndmps라는 서비스가 돌아가고 있다.

localhost의 30000번 포트에 현재 레벨의 패스워드를 제출함에 따라 다음 비밀번호를 얻을 수 있다는 것 같은데..

난 현재 내 비밀번호를 모른다. (level13을 그렇게 해결했기 때문)

 

level13을 생각해보면 /etc/bandit_pass/bandit14 내에 있다고 했다.

4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e 이게 level14 password이다.

 

이걸 localhost의 포트 30000으로 보내보자.

무야호 ~

pw : BfMYroe26WYalil77FoDi9qh59eK5xNr

 


📒 level15 -> level16

Level Goal

The password for the next level can be retrieved by submitting the password of the current level to port 30001 on localhost using SSL encryption.

Helpful note: Getting “HEARTBEATING” and “Read R BLOCK”? Use -ign_eof and read the “CONNECTED COMMANDS” section in the manpage. Next to ‘R’ and ‘Q’, the ‘B’ command also works in this version of that command…

 

위의 문제와 비슷하게 해결하면 될 것 같다. SSL Encryption을 해줘야 한다?

BfMYroe26WYalil77FoDi9qh59eK5xNr 얘를 어떻게 암호화 해줘야 할까.

힌트에서 CONNECTED COMMANDS를 man에서 찾으라고 하는데 s_client 명령어 man에

해당 힌트가 있다.

-ign_eof 옵션을 잘 봐야할 것 같다. s_client는 openssl과 함께 쓰자.

-connect 옵션과 -ign_eof 옵션을 같이 써주면 될 것 같다.

이러면서 밑에 비밀번호를 알려준다.

pw : cluFn7wTiGryunymYOu4RcffSxQluehd

 


📒 level16 -> level17

Level Goal

The credentials for the next level can be retrieved by submitting the password of the current level to a port on localhost in the range 31000 to 32000. First find out which of these ports have a server listening on them. Then find out which of those speak SSL and which don’t. There is only 1 server that will give the next credentials, the others will simply send back to you whatever you send to it.

 

포트 31000부터 32000 사이? => nmap 써보장

아닌가 nc를 반복해야 하나 ??

대충 nc로 때려봤다.

그러던 중 31790 포트에서 RSA key를 출력해주고 값을 기다리고 있는 것이 확인됐다.

그래서 그냥 level16의 비밀번호를 입력했는데 풀렸다. (정확히는 private key를 뱉어냈다.)

문제를 좀 더 해결해주도록 하자. 우선 tmp 폴더 밑에 저 파일을 만들자.

이렇게 만들어주었고, 저 파일을 이용해 로그인하자.

너무 오픈되어 있단다.

permission을 바꿔야 할 것 같은데..

 

permission을 바꿨는데 이번엔 passphrase를 입력하라고 한다.

보니까 앞에 -----BEGI 부분이 없었다. ^~^

pw : xLYVMN9WE5zQ5vHacb0sZEVqbrp7nBTn

 


📒 level17 -> level18

Level Goal

There are 2 files in the homedirectory: passwords.old and passwords.new. The password for the next level is in passwords.new and is the only line that has been changed between passwords.old and passwords.new

NOTE: if you have solved this level and see ‘Byebye!’ when trying to log into bandit18, this is related to the next level, bandit19

 

음 어느 줄이 다른 지 확인을 해야할 것 같다.

찾았당 kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd

로그인이 되지 않는다. 

좀 찾아보니 내 답이 맞는 것 같다. 아마 18번 문제가 연결을 바로 끊는 문제인 것 같다.=

bye bye ~~ (다음 문제에 이어서)

 


📒 level18 -> level19

Level Goal

The password for the next level is stored in a file readme in the homedirectory. Unfortunately, someone has modified .bashrc to log you out when you log in with SSH.

 

그렇다고 한다. ??? ssh를 통해 명령도 같이 넘겨야 하지 않을까 싶다.

근데 그냥 큰 따옴표로 묶어주면 된다.

ls -al 명령을 넘겼을 때. 그럼 그냥 cat readme를 넘겨주자.

PW : IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x

 


📒 level19 -> level20

Level Goal

To gain access to the next level, you should use the setuid binary in the homedirectory. Execute it without arguments to find out how to use it. The password for this level can be found in the usual place (/etc/bandit_pass), after you have used the setuid binary.

 

그냥 setuid 문제이다.

이건 당연히 permission denied가 뜨겠다. (나는 bandit19니까 ~)

pw : GbKksEFF4yrVs6il55v6gwY5aVje5f0j

 


📒 level20 -> level21

Level Goal

There is a setuid binary in the homedirectory that does the following: it makes a connection to localhost on the port you specify as a commandline argument. It then reads a line of text from the connection and compares it to the password in the previous level (bandit20). If the password is correct, it will transmit the password for the next level (bandit21).

NOTE: Try connecting to your own network daemon to see if it works as you think

 

흠 ..

음.. 어떻게 비밀번호를 넘길 수가 있을까

우선 저 프로그램은 연결을 하는 프로그램 같으니, 그걸 들을 수 있는 (이걸 서버라고 생각할 수 있나?) 포트를 열어줘야 할 것 같다. 그런데 문제는 터미널이 한 개 이기에 열어주게 되면 다른 명령을 받을 수가 없게 된다.

 

두 가지 방법으로 해결이 가능할 것 같은데, 첫번재는 서버를 백그라운드에서 돌아가게 하는 것이다.

두 번째는 그냥 overthewire에 두 개의 터미널로 ssh를 접속시키면 된다.

난 후자가 쉽다고 생각되지만 공부하자는 목적에서 첫 번째 방법으로 해보겠다.

 

명령어 뒤에 &을 붙이면 백그라운드 실행이 된다고 한다. 포트는 대충 12345로 열어주자.

나이

 

 


📒 level21 -> level22

Level Goal

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

 

내가 아는 cron은 자동으로 명령어를 계속 실행해주는 것이다.

 

클리어 ~

pw : Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI

 

 


📒 level22 -> level23

Level Goal

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

NOTE: Looking at shell scripts written by other people is a very useful skill. The script for this level is intentionally made easy to read. If you are having problems understanding what it does, try executing it to see the debug information it prints.

 

?? 이전 문제랑 비슷할 것 같다.

myname = bandit22로 설정하고 mytarget에 뭐가 들어갈 지 테스트나 해보자.

pw : jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n

 


 

📒 level23 -> level24

Level Goal

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

NOTE: This level requires you to create your own first shell-script. This is a very big step and you should be proud of yourself when you beat this level!

NOTE 2: Keep in mind that your shell script is removed once executed, so you may want to keep a copy around…

 

음..

쉘 스크립트를 만들어주어야만 풀릴 것 같다. 

근데 반복문 안에 * .*은 무엇일까 ?? 

와일드 카드이니 저 i라는 변수에 디렉토리의 파일명들이 들어가지는 것 같다.

 

i에 파일명이 들어가졌다고 하면, 밑에서 그 명령을 실행하고 지워버린다.(owner는 절대 bandit23이면 안된다.)

그러므로 그냥 /var/spool/bandit24에 쉘 스크립트 하나 만들어주고 permission 설정해주면 되겠다.

2시간 정도 삽질했었는데, 알고보니 /tmp/bandit24_mmo폴더로 cp를 했었다. 오노

 

pw : UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ

 

 


📒 level24 -> level25

Level Goal

A daemon is listening on port 30002 and will give you the password for bandit25 if given the password for bandit24 and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing.

 

?? 브루트 포싱을 하란다. 4자리니까 10000가지 경우수만 대입하면 될 것 같다.

파이썬을 이용해야 하지 않을까 싶다.

그냥 level23에서 이어서 풀어보자. pwntools를 사용하도록 하자.

얼마 안가서 계속 뻗는다...

아직 왜 뻗는 것인 지는 모르겠지만, 문제 해결을 위해서 그냥 쉘 스크립트로 작성했다.

비밀번호 + 코드를 조합해서 message 파일에 저장하고

cat message | nc localhost 30002로 풀었다.

pw : uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG

 

 


📒 level25 -> level26

Level Goal

Logging in to bandit26 from bandit25 should be fairly easy… The shell for user bandit26 is not /bin/bash, but something else. Find out what it is, how it works and how to break out of it.

 

음.... /bin/sh인가 ㅎㅎ

우선 시도를 해보자. 다행히도 bandit26.sshkey 파일이 존재한다.

연결이 끊긴다. bandit26의 쉘을 확인해봐야 하나 ?

/usr/bin/showtext라는 쉘을 사용한다.

more명령이 돌아감을 확인할 수 있다. 뭘 하는 지는 모르겠는데 text.txt를 읽으려고 한다.

접속하면 showtext 쉘은 /home/bandit26/text.txt를 읽으려고 한다고 생각할 수 있다.

우선 showtext를 읽어보았다.

exit 0이 눈에 띈다. 그것보다 더 눈에 띄는 건 more인데, 한 페이지 씩 출력하는 것으로

창 크기를 엄청 줄이면 바로 종료되는 것을 막을 수 있다.

 

이런 식으로 말이다.

more명령은 실행중에 v를 누르면 vi 창이 열리게 된다.

shell을 bash로 바꿔주고 터미널로 빠져나왔다. 

 

pw : 확인하지 않음.

바로 27까지 풀자 !

 

 


📒 level26 -> level27

 

Level Goal

Good job getting a shell! Now hurry and grab the password for bandit27!

 

 

아 예..

그냥 바로 비밀번호 폴더에 접근해보자.

 

pw : 3ba3118a22e93127a4ed485be72ef5ea

 

 


끝 !

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'워게임 > CyKor 자체 과제' 카테고리의 다른 글

CyKor [2주차 과제] HandRay X86  (0) 2022.03.16