본문 바로가기

OverTheWire/Bandit

OverTheWire Bandit Level 17 → 18 ~ 20 → 21

connect : ssh bandit17@bandit.labs.overthewire.org -p 2220

password : xLYVMN9WE5zQ5vHacb0sZEVqbrp7nBTn

 Level 17 → 18


이미지 클릭 시 문제로 이동

문제 : 홈 디렉토리에는 passwords.old 및 passwords.new의 두 파일이 있습니다. 다음 레벨의 비밀번호는 passwords.new에 있으며 passwords.old와 passwords.new 사이에서 변경된 유일한 행입니다. 참고 :이 레벨을 해결하고 bandit18에 로그인 할 때 'Byebye!'가 표시되면 다음 레벨 인 bandit19와 관련이 있습니다.

 

new와 old의 차이점을 찾으면 되는 문제다.

  bandit17@bandit:~$ ls
  passwords.new  passwords.old
  bandit17@bandit:~$ diff passwords.new passwords.old
  42c42
  < kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd
  ---
  > w0Yfolrc5bwjS4qw5mq1nnQi6mF03bii

diff 명령어를 통해 다른 행을 찾아준다. 새로운 new의 값이 password일 것이다.

 

Level 18 → 19


  ssh bandit18@bandit.labs.overthewire.org -p 2220 
  This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

  bandit18@bandit.labs.overthewire.org's password: 
  Linux bandit.otw.local 5.4.8 x86_64 GNU/Linux

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


  Welcome to OverTheWire!
  < 생략 > 

  Enjoy your stay!

  Byebye !
  Connection to bandit.labs.overthewire.org closed.

해당 레벨에 접속하면 바이바이 하면서 나가진다..

 참고 :이 레벨을 해결하고 bandit18에 로그인 할 때 'Byebye!'가 표시되면 다음 레벨 bandit19와 관련이 있다.

level 17에서 이렇게 말했었다.

문제를 보면,

 

다음 레벨의 비밀번호는 홈 디렉토리의 readme 파일에 저장됩니다. 안타깝게도 누군가 SSH로 로그인 할 때 로그 아웃하도록 .bashrc를 수정했다.

  bandit17@bandit:~$ cd /home
  bandit17@bandit:/home$ ls
  bandit0   bandit13  bandit18  bandit22  bandit27      bandit29-git  bandit31-git  bandit6
  bandit1   bandit14  bandit19  bandit23  bandit27-git  bandit3       bandit32      bandit7
  bandit10  bandit15  bandit2   bandit24  bandit28      bandit30      bandit33      bandit8
  bandit11  bandit16  bandit20  bandit25  bandit28-git  bandit30-git  bandit4       bandit9
  bandit12  bandit17  bandit21  bandit26  bandit29      bandit31      bandit5
  bandit17@bandit:/home$ cd bandit18
  bandit17@bandit:/home/bandit18$ ls
  readme
  bandit17@bandit:/home/bandit18$ cat readme
  cat: readme: Permission denied

홈 디렉토리에 가보면 bandit 파일들이 있다. 이동해보면 readme 파일이 없지만 권한이 없다. 저 곳에 bandit19가 비밀번호가 있고 현재 bandit18의 비밀번호를 알기 때문에 접속할 때 ""로 실행할 명령어를 함께 보내주어 결과를 얻을 것이다.

  ssh bandit18@bandit.labs.overthewire.org -p 2220 "cat readme"
  This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

  bandit18@bandit.labs.overthewire.org's password: 
  IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x

바로 readme 파일을 읽게하고 얻은 비밀번호( kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd ) 를 넣어주면 다음 레벨의 비밀번호가 출력된다.

 

방법 2

-t : pseudo-tty 할당을 강제한다.

  bandit17@bandit:/home/bandit18$ ssh -t bandit18@localhost cat readme
  The authenticity of host 'localhost (127.0.0.1)' can't be established.
  ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
  Are you sure you want to continue connecting (yes/no)? yes
  Failed to add the host to the list of known hosts (/home/bandit17/.ssh/known_hosts).
  This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  Permissions 0640 for '/home/bandit17/.ssh/id_rsa' are too open.
  It is required that your private key files are NOT accessible by others.
  This private key will be ignored.
  Load key "/home/bandit17/.ssh/id_rsa": bad permissions
  bandit18@localhost's password: 
  IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x
  Connection to localhost closed.

-t 옵션을 사용하는 방법도 있다.

 

Level 19 → 20


문제 : 다음 레벨에 액세스하려면 홈 디렉토리에있는 setuid 바이너리를 사용해야합니다. 사용 방법을 찾으려면 인수없이 실행하십시오. 이 수준의 암호는 setuid 바이너리를 사용한 후 일반적인 위치 (/ etc / bandit_pass)에서 찾을 수 있습니다.

 

  ssh bandit19@bandit.labs.overthewire.org -p 2220             
  This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

  bandit19@bandit.labs.overthewire.org's password:IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x

접속해준다.

  bandit19@bandit:~$ ls
  bandit20-do
  bandit19@bandit:~$ ./bandit20-do
  Run a command as another user.
    Example: ./bandit20-do id

다른 유저를 통해 실행하란다... 예시를 보니 bandit20일 듯 싶다. 문제에서 /etc/bandit_pass에서 찾을 수 있을 것이라고 했다.

  bandit19@bandit:~$ ./bandit20-do cat /etc/bandit_pass/bandit20
  GbKksEFF4yrVs6il55v6gwY5aVje5f0j

해당 파일을 이용해서 실행을 해준다.

 

Level 20 → 21


문제 : 다음을 수행하는 setuid 바이너리가 홈 디렉토리에 있습니다. 명령 줄 인수로 지정한 포트에서 localhost에 연결합니다. 그런 다음 연결에서 텍스트 한 줄을 읽고 이전 수준 (bandit20)의 암호와 비교합니다. 비밀번호가 정확하면 다음 단계 (bandit21)의 비밀번호를 전송합니다. 참고 : 자신의 네트워크 데몬에 연결하여 생각대로 작동하는지 확인하십시오.

 

nc [옵션]

  • -l : listen 상태로 둔다. -p와 함께 사용되며 nc를 서버로 사용할 때 쓴다.
  • -p : 포트를 지정한다. ex) -p 1024 
  <terminal 1>
  bandit20@bandit:~$ nc -l -p 1025

우선 server로 동작할 터미널에서 대기 상태로 해준다.

  <terminal 2>
  bandit20@bandit:~$ ./suconnect 1025

지정한 포트로 연결해준다.

  <terminal 1>
  bandit20@bandit:~$ nc -l -p 1025
  GbKksEFF4yrVs6il55v6gwY5aVje5f0j

그리고 그 전 레벨에서 얻었던 현재 password를 넣어준다.

  <terminal 2>
  bandit:~$ ./suconnect 1025
  Read: GbKksEFF4yrVs6il55v6gwY5aVje5f0j
  Password matches, sending next password

  <terminal 1>
  bandit20@bandit:~$ nc -l -p 1025
  GbKksEFF4yrVs6il55v6gwY5aVje5f0j
  gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr

2에서 비밀번호를 비교하고 맞으면 1로 다음 레벨의 비밀번호를 전송한다.


- 끝 -