Spring Cloud Function SPEL表达式注入漏洞
Spring Cloud Function 是基于 Spring Boot 的函数计算框架,它抽象出所有传输细节和基础架构,允许开发人员保留所有熟悉的工具和流程,并专注于业务逻辑。Spring Cloud Function 被爆出了 SPEL 表达式注入漏洞
0x01 漏洞简介
漏洞的代码修复可以通过gihub上提交的commit来查看,通过比较可以分析出漏洞的触发位置
https://github.com/spring-cloud/spring-cloud-function/commit/0e89ee27b2e76138c16bcba6f4bca906c4f3744f
触发漏洞的方式是spel表达式的解析,构造恶意的payload被解析后,可以造成RCE
0x02 漏洞利用
先看一下漏洞触发位置,也就是spel表达式被解析的位置,注入的payload也就是到这里被执行

POC
T(java.lang.Runtime).getRuntime().exec("calc.exe")
最后执行的结果

0x03 漏洞利用链分析
学习了网上的文章,一开始以为触发漏洞只能在application.properties中配置spring.cloud.function.definition=functionRouter,然后发post包触发利用链。
后来在别的文章里看到可以不进行配置直接来触发利用链,这里就直接记录后一种方式,这种方式利用的/functionRouter的path来触发的
学习调试过程如下:
首先构造我们的POC,用POST方式发包

在FunctionWebRequestProcessingHelper.java中findFunction方法会进行判断,传入的是GET请求或者是POST请求都会走doFindFunction,在这里我们可以看到类型是POST的

走下去,看一下返回给doFindFunction的参数,method就是我们请求的方式,这里是POST方式请求
path的路径“/functionRouter”需要关注一下

继续跟进doFindFunction,这里先是对传入的path做一个判断

往下走,这里的functionCatalog.lookup通过name参数给的functionRouter来找到对应位置

顺便进到FunctionCatalog接口中,查看一下lookup方法学习一下,里面的lookup有三种方法(重载)

我们这边看到调用的是第三种lookup方法,这边通过functionDefination参数来找到指定的位置

接下来走下去就到了SimpleFunctionRegistry.java#isRoutingFunction

可以看一下参数中的值,spelPaser=SpelExpressionParser这个参数以及参数值让我们明白离触发点位置近了

走下去就到了payload被接收的位置,在headers参数中,有我们注入的poc

跟进到applay方法中,可以看到给route传入了我们的poc

继续往下走,到RoutingFunction.java#route中,进入else if中获得传入的spring.cloud.function.routing-expression的值

最后就是在functionFromExpression中进行解析调用,至此这条链结束了

0x04 总结
在被twcjw师傅吊了一顿后,才打算写笔记,是跟着网上的文章调的,只不过自己在调这条链的目的并不是在于调通就满足了,也是在不断学习补充开发在写代码的思路,一些设计模式。这是自己第二次进行漏洞调试,第一次是调试spring-cloud-gatway,是跟着t师傅的文章https://www.yuque.com/shenyan-ltajy/ugkir3/glgcs7,希望之后也能继续坚持学习漏洞的研究,产出有价值的文章。
0x05 参考文章
https://forum.butian.net/share/1436
https://mp.weixin.qq.com/s/APiXRwSiEanoIuohjwkoEw