Spring Cloud Gateway表达式注入


漏洞复现

环境搭建

直接使用vulhub(https://github.com/vulhub/vulhub/tree/master/spring/CVE-2022-22947) 中的项目,为演示方便将项目从docker中的spring-cloud-gateway-0.0.1-SNAPSHOT.jar文件下载至Windows环境下并使用java开启

rce:

发送payload创建恶意路由

img

刷新路由执行SpEL表达式

img

漏洞分析

在org.springframework.cloud.gateway.support#ShortcutConfigurable.getValue()中使用了SpEL表达式

img

在这个方法下的normalize调用了getvalue()方法

img

可以在org.springframework.cloud.gateway.filter.factory#GatewayFilterFactory中观察到GatewayFilterFactory继承了ShortcutConfigurable

img

其中某条getvalue的调用链如下

img

定位到convertToRoute()方法

img

convertToRoute()方法在加载录用时被调用,传入的RouteDefinition属性如下

img

查看官方列出的路由接口定义

img

img

可通过/gateway/routes/{id_route_to_create}创建路由

然后通过/actuator/gateway/refresh刷新路由,重新加载配置使得路由生效。

因此攻击者可以添加带有filter的恶意路由,当重新加载路由时,会触发对参数的归一化逻辑,从而导致filter参数value中的SPEL表达式被解析。

参考链接

https://wya.pl/2022/02/26/cve-2022-22947-spel-casting-and-evil-beans/

https://github.com/vulhub/vulhub/blob/master/spring/CVE-2022-22947/README.zh-cn.md

https://blog.csdn.net/murphysec/article/details/123262978

https://mp.weixin.qq.com/s/lKKOUvWqU1Qpexus5u_3Uw


文章作者: jokerscar
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 jokerscar !
  目录