ssh bandit25@bandit.labs.overthewire.org -p 2220
#p7TaowMYrmu23Ol8hiZh9UvD0O9hpx8d
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.
밴디트 25에서 밴디트 26에 로그인하는 것은 꽤 쉬울 것입니다. 사용자 밴디트 26의 셸은 /bin/bash가 아니라 다른 것이다. 그것이 무엇인지, 그것이 어떻게 작동하는지, 그리고 그것을 탈출하는 방법을 알아보세요.
먼져 홈에있는 sshkey를 통해 접속해보자
bandit25@bandit:~$ ssh bandit26@localhost -i bandit26.sshkey -p 2220
_ _ _ _ ___ __
| | | (_) | |__ \ / /
| |__ __ _ _ __ __| |_| |_ ) / /_
| '_ \ / _` | '_ \ / _` | | __| / / '_ \
| |_) | (_| | | | | (_| | | |_ / /| (_) |
|_.__/ \__,_|_| |_|\__,_|_|\__|____\___/
Connection to localhost closed.
바로 끊긴다. 쉘문제라고 알려줬으니 /etc/passwd를 확인하자
bandit25@bandit:~$ cat /etc/passwd | grep bandit26
bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext
설명
| 내용 | 설명 |
|---|---|
| bandit26: | 서버로 로그인하는 아이디 |
| x: | 비밀번호(진짜는 /etc/shadow에있음) |
| 11026: | 2개있는데 유저번호,그룹번호임 |
| bandit level 26: | 사용자의 이름 |
| /home/bandit26: | 사용자가 로그인하면 위치하는 디렉토리 |
| /usr/bin/showtext | 사용자가 처음 로그인했을때 실행되는 프로그램 |
이때, 마지막 로그인했을때 실행되는 프로그램이, 나머지는 bin/bash인데 얘만 /usr/bin/showtext이다
따라서 이를 열어보자
bandit25@bandit:~$ cat /usr/bin/showtext
#!/bin/sh
export TERM=linux
exec more ~/text.txt
exit 0
test.txt에 more 실행하고 종료하는 명령어이다
따라서 more 명령이 끝나지 않기 위해 창을 줄여버리면, 대기상태가 된다
여기서 shell을 설정해주면, 끝나지 않은 채로 접속이 가능하다 (현재 bandit26)
#창을 줄인채로
bandit25@bandit:~$ ssh bandit26@localhost -i bandit26.sshkey -p 2220
#v를 눌러 vim으로 진행
:set shell=/bin/bash #쉘세팅
:sh # 쉘실행
bandit26@bandit:~$
bandit26@bandit:~$ cat /etc/bandit_pass/bandit26
#c7GvcKlw9mC7aUQaPx7nwFstuAIBw1o1
또다른방법
vim 에디터에서 :r 로 파일의 내용을 읽어서 쓸수도 있다.
비번은 알 수 있는다 접속을 못한다 ㅠㅠ