Post

Bandit Level 25 → Level 26

문제

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

목표

다음 레벨의 패스워드를 찾는다.

bandit26의 쉘은 /bin/bash가 아니다.

풀이

홈 디렉토리를 확인해보니 SSH 키가 있다.

1
2
bandit25@bandit:~$ ls
bandit26.sshkey


SSH 키로 bandit26에 접속해보니 바로 연결이 끊긴다.

1
2
3
4
5
6
7
8
9
10
11
12
bandit25@bandit:~$ ssh bandit26@localhost -i bandit26.sshkey
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)? yes
  _                     _ _ _   ___   __
 | |                   | (_) | |__ \ / /
 | |__   __ _ _ __   __| |_| |_   ) / /_
 | '_ \ / _` | '_ \ / _` | | __| / / '_ \
 | |_) | (_| | | | | (_| | | |_ / /| (_) |
 |_.__/ \__,_|_| |_|\__,_|_|\__|____\___/
Connection to localhost closed.


1
2
bandit25@bandit:~$ cat /etc/passwd | grep bandit26
bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext

사용자의 정보가 있는 /etc/passwd 에서 bandit26을 찾아보니 /usr/bin/showtext 파일이 있다.


1
2
3
4
5
6
7
bandit25@bandit:/home/bandit26$ cat /usr/bin/showtext
#!/bin/sh

export TERM=linux

more ~/text.txt
exit 0

/usr/bin/showtext 파일을 보니 more 명령어로 ~/text.txt 파일을 읽는 것을 알 수 있다.

more 명령어는 cat 명령어와 비슷하지만 화면 단위로 끊어 출력한다는 특징이 있다.

이 점을 이용해 화면의 크기를 줄여 출력이 끝나지 않게 하면 된다.


1
2
3
4
5
6
7
  _                     _ _ _   ___
  __
 | |                   | (_) | |__ \
 / /
 | |__   __ _ _ __   __| |_| |_   )
/ /_
--More--(50%)

이 상태에서 V키를 누르면 vi 에디터를 실행할 수 있다.


그리고 :e 커맨드로 /etc/bandit_pass/bandit26 파일을 읽으면 된다.

1
2
3
4
5
6
7
8
9
10
11
  _                     _ _ _   ___   __
 | |                   | (_) | |__ \ / /
 | |__   __ _ _ __   __| |_| |_   ) / /_
 | '_ \ / _` | '_ \ / _` | | __| / / '_ \
 | |_) | (_| | | | | (_| | | |_ / /| (_) |
 |_.__/ \__,_|_| |_|\__,_|_|\__|____\___/
 ~
 ~
 ~
 ~
 :e /etc/bandit_pass/bandit26
1
2
3
4
5
6
c7GvcKlw9mC7aUQaPx7nwFstuAIBw1o1
~
~
~
~
Connection to localhost closed.adonly] 1L, 33B             1,1           All


Password : c7GvcKlw9mC7aUQaPx7nwFstuAIBw1o1

배운 것

  • more 명령어는 화면 단위로 끊어 출력한다.
This post is licensed under CC BY 4.0 by the author.