Wargames与bash知识17
关卡提示
从bandit25登录到bandit26应该相当容易…用户bandit26的shell不是/bin/bash,而是其他东西。找出它是什么,它是如何工作的,以及如何摆脱它。
推荐命令
ssh, cat, more, vi, ls, id, pwd
这个关卡多次尝试没有一点点思路,最后百度了一下。然后发现more和vim还一下“骚操作”。
在家目录发现一个私钥,尝试登录。
bandit25@bandit:~$ ssh -i bandit26.sshkey -p 2220 -l bandit26 bandit.labs.overthewire.org
kex_exchange_identification: read: Connection reset by peer
Connection reset by 127.0.0.1 port 2220
bandit25@bandit:~$ ssh -i bandit26.sshkey -p 2220 -l bandit26 localhost
The authenticity of host '[localhost]:2220 ([127.0.0.1]:2220)' can't be established.
ED25519 key fingerprint is SHA256:C2ihUBV7ihnV1wUXRb4RrEcLfXC5CXlhmAAM/urerLY.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Could not create directory '/home/bandit25/.ssh' (Permission denied).
Failed to add the host to the list of known hosts (/home/bandit25/.ssh/known_hosts).
_ _ _ _
| |__ __ _ _ __ __| (_) |_
| '_ \ / _` | '_ \ / _` | | __|
| |_) | (_| | | | | (_| | | |_
|_.__/ \__,_|_| |_|\__,_|_|\__|
This is an OverTheWire game server.
More information on http://www.overthewire.org/wargames
!!! You are trying to log into this SSH server with a password on port 2220 from localhost.
!!! Connecting from localhost is blocked to conserve resources.
!!! Please log out and log in again.
……
For support, questions or comments, contact us on discord or IRC.
Enjoy your stay!
_ _ _ _ ___ __
| | | (_) | |__ \ / /
| |__ __ _ _ __ __| |_| |_ ) / /_
| '_ \ / _` | '_ \ / _` | | __| / / '_ \
| |_) | (_| | | | | (_| | | |_ / /| (_) |
|_.__/ \__,_|_| |_|\__,_|_|\__|____\___/
Connection to localhost closed.
登录后出现一个bandit26的ASCII图,然后就退出了。
没办法,一点一点找线索吧。
/etc/passwd文件保存着用户登录默认的shell
bandit25@bandit:~$ cat /etc/passwd |grep bandit26
bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext
用户默认shell竟然是/usr/bin/showtext,查看一下:
bandit25@bandit:~$ cat /usr/bin/showtext
#!/bin/sh
export TERM=linux
exec more ~/text.txt
exit 0
/usr/bin/showtext脚本内容是more bandit26用户家目录的text.txt文件,然后exit 0退出了。
bandit25@bandit:~$ ls -al
total 32
drwxr-xr-x 2 root root 4096 Oct 5 06:19 .
drwxr-xr-x 70 root root 4096 Oct 5 06:20 ..
-rw-r----- 1 bandit25 bandit25 33 Oct 5 06:19 .bandit24.password
-r-------- 1 bandit25 bandit25 1679 Oct 5 06:19 bandit26.sshkey
-rw-r--r-- 1 root root 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root root 3771 Jan 6 2022 .bashrc
-rw-r----- 1 bandit25 bandit25 4 Oct 5 06:19 .pin
-rw-r--r-- 1 root root 807 Jan 6 2022 .profile
bandit25@bandit:~$ cat .pin;echo
9015
查找线索过程,发现上一个关卡的pincode码是: 9015.
下面开始尝试:
先将私钥文件下载,修改权限。
gyj@guyanjun:~$ chmod 400 bandit26.sshkey
尝试使用chsh -s bash 修改默认shell
发送命令提示:Pseudo-terminal will not be allocated because stdin is not a terminal.。
翻译过来意思:不会分配伪终端,因为stdin不是终端。
尝试发送命令失败,于是看看几个相关文件的权限
bandit25@bandit:~$ ls -l /etc/passwd
-rw-r--r-- 1 root root 6247 Oct 5 06:20 /etc/passwd
bandit25@bandit:~$ ls -l /usr/bin/showtext
-rwxr-xr-x 1 root root 58 Oct 5 06:19 /usr/bin/showtext
bandit25@bandit:~$
从权限看,试图修改相关文件的方法是不行的。
没有办法只能求助百度了
缩小终端画面让more不退出,就是显示文件百分比 然后用v调用vim
全屏图感受一下,终端比例
这是可以放大终端了
按ESC键 输入 冒号 :set shell 查看一下vim的默认shell
:!bash
终于进入了。
查看家目录,有看见熟悉的操作,拿下bandit27密码
bandit26@bandit:~$ ls
bandit27-do text.txt
bandit26@bandit:~$ ./bandit27-do
Run a command as another user.
Example: ./bandit27-do id
bandit26@bandit:~$ ./bandit27-do cat /etc/bandit_pass/bandit27
YnQpBuifNMas1hcUFk70ZmqkhUU2EuaS
bandit26@bandit:~$