Computer Security

#15 Wargame bandit 12 (Level24 ~ Level26), 브루트포스공격,more명령어 본문

Wargame:Bandit

#15 Wargame bandit 12 (Level24 ~ Level26), 브루트포스공격,more명령어

쿠리 Kuri 2022. 7. 22. 18:30

Level24 -> Level25

Level24

데몬은 포트 30002에서 수신 대기 중이며 bandit24에 대한 암호와 비밀 숫자 4자리 핀코드가 제공된 경우 bandit25에 대한 암호를 제공합니다.
무차별 대입(brute-forcing)이라고 하는 10000가지 조합을 모두 통과하는 것 외에는 암호를 검색할 방법이 없습니다.

brute force 문제이다.


brute force 란?

  • 암호학에서, 무차별 대입 공격(brute-force attack)은 특정한 암호를 풀기 위해 가능한 모든 값을 대입하는 것을 의미한다.
  • 대부분의 암호화 방식은 이론적으로 무차별 대입 공격에 대해 안전하지 못하며, 충분한 시간이 존재한다면 암호화된 정보를 해독할 수 있다.
  • 하지만 대부분의 경우 모든 계산을 마치려면 실용적이지 못한 비용이나 시간을 소요하게 되어, 공격을 방지하게 한다.
  • 암호의 '취약점'이라는 의미에는 무차별 대입 공격보다 더 빠른 공격 방법이 존재한다는 것을 의미한다.

1.  30002 포트에 0~9999까지의 비밀번호를 보내면 그중에서 맞는 비밀번호가 나오면 bandit25의 비밀번호를 내보낸다 한다.

 

 

2. mkdir 명령어를 이용해 /tmp/pw25 디렉토리를 생성 해주고, cd로 접근 해주자.

bandit24@bandit:~$ mkdir /tmp/pw25
bandit24@bandit:~$ cd /tmp/pw25

 

 

3.vim brute.sh 를 이용해 , 아래와 같이 만들어 passwd24 + 0000부터 9999까지의 숫자를 pass.txt에 저장하자.

bandit24@bandit:/tmp/pw25$ vim brute.sh

vim brute.sh

 

 

4. ./brute.sh 를 하니, Permission denied 가 뜬다. chmod 777 를 통해 관리자 권한을 부여 해주고 다시 해보자.

bandit24@bandit:/tmp/pw25$ ./brute.sh
-bash: ./brute.sh: Permission denied
bandit24@bandit:/tmp/pw25$ chmod 777 brute.sh
bandit24@bandit:/tmp/pw25$ ./brute.sh

 

 

 

5. ls 를 이용해 pass.txt 라는 파일이 잘 만들어 진 것을 알 수 있다.

bandit24@bandit:/tmp/pw25$ ls
brute.sh  pass.txt

 

 

6. cat pass.txt | nc localhost 30002 를 이용해 30002 포트에 pass.txt데이터를 보내주자.

bandit24@bandit:/tmp/pw25$ cat pass.txt | nc localhost 30002


Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Wrong! Please enter the correct pincode. Try again.
Correct!
The password of user bandit25 is uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG

 

 

 

7. 얻은 bandit25비밀번호 : uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG 로 bandit25에 접속하면 성공!

 For your convenience we have installed a few usefull tools which you can find
 in the following locations:

    * gef (https://github.com/hugsy/gef) in /usr/local/gef/
    * pwndbg (https://github.com/pwndbg/pwndbg) in /usr/local/pwndbg/
    * peda (https://github.com/longld/peda.git) in /usr/local/peda/
    * gdbinit (https://github.com/gdbinit/Gdbinit) in /usr/local/gdbinit/
    * pwntools (https://github.com/Gallopsled/pwntools)
    * radare2 (http://www.radare.org/)
    * checksec.sh (http://www.trapkit.de/tools/checksec.html) in /usr/local/bin/checksec.sh

--[ More information ]--

  For more information regarding individual wargames, visit
  http://www.overthewire.org/wargames/

  For support, questions or comments, contact us through IRC on
  irc.overthewire.org #wargames.

  Enjoy your stay!

bandit25@bandit:~$

Level25 -> Level26

Level25

bandit25에서 bandit26으로 로그인하는 것은 상당히 쉬울 것입니다.
bandit26 사용자의 쉘은 /bin/bash가 아니라 다른 것입니다. 
그것이 무엇인지, 어떻게 작동하며 어떻게 빠져나갈 수 있는지 알아보십시오.

more 명령어란?

 

more 명령어는 파일의 내용을 페이지 단위로 끊어서 볼 수 있는 명령어다.

cat 명령어 등은 파일의 명령어를 모두 출력해 보여주지만 출력할 내용이 많은 경우에 한번에 내용이 출력돼 버리면 내용을 보기가 힘들어진다.
이때 more 명령어를 이용하면 페이지 단위로 나누어 넘기면서 볼 수 있다.
옵션
-p
페이지를 이동할 때 화면을 아래로 이어서 출력하지 않고 새로고침 하면서 출력한다.
-숫자
한 페이지를 몇 줄로 설정할 것인지 정한다.
-s
여러 줄의 공백이 있는 경우 한 줄의 공백으로 줄여 표시한다.
-d
한 페이지가 끝나면 --More-- 문구 옆에 [Press space to continue, q to quit] 문구를 표시한다.
 
more 실행 중 명령어
Space
다음 페이지로 이동
숫자 + z
숫자줄 만큼 다음으로 이동
q 또는Q
more 명령어 종료
f
다음 페이지로 이동
b
이전 페이지로 이동
=
현재 줄 번호 표시
v
vi 에디터로 실행

 

more 실행 중 문자열 검색
/표현식
표현식에 해당하는 문자열을 찾는다.
n
다음으로 발견되는 문자열을 찾는다.
'
이전 발견되는 문자열을 찾는다.
 

 

1.일단 접속해서 ls 로 확인해보니 bandit26.sshkey가 존재한다.

bandit25@bandit:~$ ls
bandit26.sshkey

 

 

2.ssh -i ./bandit26.sshkey bandit26@localhost 에 접속해보자.

bandit25@bandit:~$ ssh -i ./bandit26.sshkey bandit26@localhost
Could not create directory '/home/bandit25/.ssh'.
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)? y
Please type 'yes' or 'no': yes
Failed to add the host to the list of known hosts (/home/bandit25/.ssh/known_hos     ts).
This is a OverTheWire game server. More information on http://www.overthewire.or     g/wargames

Linux bandit.otw.local 5.4.8 x86_64 GNU/Linux

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


Welcome to OverTheWire!

If you find any problems, please report them to Steven or morla on
irc.overthewire.org.

--[ Playing the games ]--

  This machine might hold several wargames.
  If you are playing "somegame", then:

    * USERNAMES are somegame0, somegame1, ...
    * Most LEVELS are stored in /somegame/.
    * PASSWORDS for each level are stored in /etc/somegame_pass/.

  Write-access to homedirectories is disabled. It is advised to create a
  working directory with a hard-to-guess name in /tmp/.  You can use the
  command "mktemp -d" in order to generate a random and hard to guess
  directory in /tmp/.  Read-access to both /tmp/ and /proc/ is disabled
  so that users can not snoop on eachother. Files and directories with
  easily guessable or short names will be periodically deleted!

  Please play nice:

    * don't leave orphan processes running
    * don't leave exploit-files laying around
    * don't annoy other players
    * don't post passwords or spoilers
    * again, DONT POST SPOILERS!
      This includes writeups of your solution on your blog or website!

--[ Tips ]--

  This machine has a 64bit processor and many security-features enabled
  by default, although ASLR has been switched off.  The following
  compiler flags might be interesting:

    -m32                    compile for 32bit
    -fno-stack-protector    disable ProPolice
    -Wl,-z,norelro          disable relro

  In addition, the execstack tool can be used to flag the stack as
  executable on ELF binaries.

  Finally, network-access is limited for most levels by a local
  firewall.

--[ Tools ]--

 For your convenience we have installed a few usefull tools which you can find
 in the following locations:

    * gef (https://github.com/hugsy/gef) in /usr/local/gef/
    * pwndbg (https://github.com/pwndbg/pwndbg) in /usr/local/pwndbg/
    * peda (https://github.com/longld/peda.git) in /usr/local/peda/
    * gdbinit (https://github.com/gdbinit/Gdbinit) in /usr/local/gdbinit/
    * pwntools (https://github.com/Gallopsled/pwntools)
    * radare2 (http://www.radare.org/)
    * checksec.sh (http://www.trapkit.de/tools/checksec.html) in /usr/local/bin/     checksec.sh

--[ More information ]--

  For more information regarding individual wargames, visit
  http://www.overthewire.org/wargames/

  For support, questions or comments, contact us through IRC on
  irc.overthewire.org #wargames.

  Enjoy your stay!

  _                     _ _ _   ___   __
 | |                   | (_) | |__ \ / /
 | |__   __ _ _ __   __| |_| |_   ) / /_
 | '_ \ / _` | '_ \ / _` | | __| / / '_ \
 | |_) | (_| | | | | (_| | | |_ / /| (_) |
 |_.__/ \__,_|_| |_|\__,_|_|\__|____\___/
Connection to localhost closed.

접속하다가 연결이 끊긴다.

 

 

 

 

3.cat /etc/passwd 를이용해  살펴보니 bandit26만 쪼끔 이상하다.

bandit25@bandit:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologi     n
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/bin/false
messagebus:x:101:104::/var/run/dbus:/bin/false
sshd:x:102:65534::/run/sshd:/usr/sbin/nologin
identd:x:103:65534::/var/run/identd:/bin/false
ntp:x:104:107::/home/ntp:/bin/false
bandit0:x:11000:11000:bandit level 0:/home/bandit0:/bin/bash
bandit1:x:11001:11001:bandit level 1:/home/bandit1:/bin/bash
bandit10:x:11010:11010:bandit level 10:/home/bandit10:/bin/bash
bandit11:x:11011:11011:bandit level 11:/home/bandit11:/bin/bash
bandit12:x:11012:11012:bandit level 12:/home/bandit12:/bin/bash
bandit13:x:11013:11013:bandit level 13:/home/bandit13:/bin/bash
bandit14:x:11014:11014:bandit level 14:/home/bandit14:/bin/bash
bandit15:x:11015:11015:bandit level 15:/home/bandit15:/bin/bash
bandit16:x:11016:11016:bandit level 16:/home/bandit16:/bin/bash
bandit17:x:11017:11017:bandit level 17:/home/bandit17:/bin/bash
bandit18:x:11018:11018:bandit level 18:/home/bandit18:/bin/bash
bandit19:x:11019:11019:bandit level 19:/home/bandit19:/bin/bash
bandit2:x:11002:11002:bandit level 2:/home/bandit2:/bin/bash
bandit20:x:11020:11020:bandit level 20:/home/bandit20:/bin/bash
bandit21:x:11021:11021:bandit level 21:/home/bandit21:/bin/bash
bandit22:x:11022:11022:bandit level 22:/home/bandit22:/bin/bash
bandit23:x:11023:11023:bandit level 23:/home/bandit23:/bin/bash
bandit24:x:11024:11024:bandit level 24:/home/bandit24:/bin/bash
bandit25:x:11025:11025:bandit level 25:/home/bandit25:/bin/bash
bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext
bandit27:x:11027:11027:bandit level 27:/home/bandit27:/bin/bash
bandit28:x:11028:11028:bandit level 28:/home/bandit28:/bin/bash
bandit29:x:11029:11029:bandit level 29:/home/bandit29:/bin/bash
bandit3:x:11003:11003:bandit level 3:/home/bandit3:/bin/bash
bandit30:x:11030:11030:bandit level 30:/home/bandit30:/bin/bash
bandit31:x:11031:11031:bandit level 31:/home/bandit31:/bin/bash
bandit32:x:11032:11032:bandit level 32:/home/bandit32:/home/bandit32/uppershell
bandit33:x:11033:11033:bandit level 33:/home/bandit33:/bin/bash
bandit4:x:11004:11004:bandit level 4:/home/bandit4:/bin/bash
bandit5:x:11005:11005:bandit level 5:/home/bandit5:/bin/bash
bandit6:x:11006:11006:bandit level 6:/home/bandit6:/bin/bash
bandit7:x:11007:11007:bandit level 7:/home/bandit7:/bin/bash
bandit8:x:11008:11008:bandit level 8:/home/bandit8:/bin/bash
bandit9:x:11009:11009:bandit level 9:/home/bandit9:/bin/bash
bandit27-git:x:11527:11527::/home/bandit27-git:/usr/bin/git-shell
bandit28-git:x:11528:11528::/home/bandit28-git:/usr/bin/git-shell
bandit29-git:x:11529:11529::/home/bandit29-git:/usr/bin/git-shell
bandit30-git:x:11530:11530::/home/bandit30-git:/usr/bin/git-shell
bandit31-git:x:11531:11531::/home/bandit31-git:/usr/bin/git-shell

 

 

 

4.cat /usr/bin/showtext 를 읽어보니 more 명령어로 작동 하는 것 같다.

bandit25@bandit:~$ cat /usr/bin/showtext
#!/bin/sh

export TERM=linux

more ~/text.txt
exit 0

 

5.ssh로 접속할때, 패스워드를 읽어서 확인해보자. (창을 작게 하고 해야한다.)

more명령어로 불러오기때문에, more명령어로 접속이 끊기기전에 /etc/bandit_pass/bandit26 에서 패스워드를 읽어야겠다.

ssh

 

 

6. more 명령어가 실행중일때, v 를 입력해서 vi 상태로 간다. 그리고 r 명령어를 이용해 다른 파일의 내용을 삽입한다.  r/etc/bandit_pass/bandit26

r/etc/bandit_pass/bandit26

 

 

 

7. 뭐 읽기전용파일인데 왜 삽입하냐 어쩌구 저쩌구 문구가 나오지만 창을 키워 보면 비밀번호가 나온다!

ATTENTION
bandit26

 

 

8.위에서 얻은 bandit26 비밀번호: 5czgV9L3Xx8JPOyRbXh6lQbmIOWvPT6Z 로 bandit26에 접속하면 성공! 이였지만, 저 비밀번호를 입력하면 바로 꺼진다.

 

9.해결 방법은 아까 봤던 ssh 상태에서 v 로 vi편집기로 들어간뒤에, 

:set shell=/bin/bash
:sh

위에 것을 입력하면 바로 bandit26으로 접속 가능하다! 

bandit26

 

Comments