hackmyvm: hopper
信息收集到获取第一个shell
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
全端口扫描,先访问一下web服务。  利用gobuster扫描目录找到目录advanced-search ,这里存在ssrf。   虚拟机有三个用户可以bash登录,root ,edward ,henry 。
经过简单测试,不能进行远程文件包含,估计是调用的curl_exec ,关于php的ssrf利用一般情况下可以参看SSRF in PHP [1]进行利用。但是这里有点特别,没有redis,没有mysql,于是对主机端口进行了探测。
#!/usr/bin/python3
import requests
for port in range(1,65535):
res = requests.get('http://192.168.143.191/advanced-search/path.php?path=http://127.0.0.1:%d' % port)
if len(res.text) == 0:
continue
else:
print('-----------------------')
print('port %d\n' % port)
print(res.text)
print('-----------------------')
扫描得到新的端口为2222 。  紧接着是目录发现,爆破目录,发现存在目录backup 。  发现是一个passpharse的sshkey,于是使用john进行解密,参看JTR(John The Ripper)的ssh密钥破解记录 [2],得到passpharse为barcelona 。  利用id_rsa登录ssh成功登录用户edward 获取用户flag。 
切换用户
往/var/www/html 目录中写入一个反弹shell的php木马,成功获取用户www-data 。  查看该用户具有sudo权限。  参考GTFOBins [3],切换至用户henry (需要注意的运行程序前需要先设置环境变量export TERM=xterm )。 
提权至root
查看用户henry的sudo权限。  这个就比较简单了,改/etc/passwd 。
将passwd复制到tmp目录中,将root用户中的x 替换为已知加密密码。  然后使用命令henry@hopper:/tmp$ sudo /usr/bin/ascii-xfr -rv /etc/passwd < passwd 将修改后的passwd写入/etc/passwd。使用su,成功切换至root获取flag。 
参考
[1] https://blog.csdn.net/bylfsj/article/details/105083164 [2] https://blog.csdn.net/qq_40490088/article/details/97812715 [3] https://gtfobins.github.io/
|