
事情布景
Spring Cloud Config为分布式体系的外部装备供给客户端的服务端的支撑。运用了它,开发人员就能够在一个中心库房办理应用程序在所有环境中的外部装备。2020-02-26 Spring 收到缝隙陈述, Spring Cloud Config Server 存在目录穿越缝隙。
时间线
2020-02-26 Spring 收到缝隙陈述, Spring Cloud Config Server 存在目录穿越缝隙
2020-03-03 Spring Cloud Config Server 更新 2.1.7 版别
2020-03-04 Spring Cloud Config Server 更新 2.2.2 版别
2020-03-06 斗象应急呼应团队分分出缝隙POC
缝隙发掘
依据描绘该缝隙为目录穿越 2.2.0-2.2.1,2.1.0-2.1.6 都受必定的影响, 所以这儿直接下载2.2.1和2.2.2的源码包进行比照
https://github.com/spring-cloud/spring-cloud-config/releases
解压后直接运用idea Ctrl+D 进行比照
许多开源项目都会在test文件中写入本次更新触及的缝隙点
比方这次 spring-cloud-config-2.2.2.RELEASE/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/environment/EnvironmentTests.java
清楚明了的这个缝隙是用 (_) 来替代 / 进行目录穿越
建立环境
这儿发动 2.2.1环境, 运用idea 翻开 (maven项目)
spring-cloud-config-2.2.1.RELEASEspring-cloud-config-server
这儿假如速度慢能够修改成阿里源,发动成功后拜访
http://127.0.0.1:8888/foo/default/master/test.json
补丁比照
依据上一个目录穿越缝隙
Spring Cloud Config Server 途径穿越与恣意文件读取缝隙剖析 – 【CVE-2019-3799】 – 先知社区
https://xz.aliyun.com/t/4844
这儿能够结构一个途径进行测验(看看报错)
/foo/default/master/..(_)..(_)..(_)..(_)etc(_)passwd
作用欠安,从文中可知恳求格局如下
GET /{name}/{profile}/{label}/{path}
持续看对应完成源码
org/springframework/cloud/config/server/resource/ResourceController.java
这儿能够知道恳求的格局,这儿决议了POC的根本结构
持续比照能够能够精确的看出, (_) 会在 [name/label] 时被处理成 /
再依据新增的测验文件
spring-cloud-config-2.2.2.RELEASE/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java
根本能够结构出来如下格局
由于label中能够解析(_)
依据提示 “Cannot clone or checkout repository” 以及 代码中的
this.nativeRepository.setSearchLocations("file:./src/test/resources/test/local");
这儿考虑可能是得选用本地装备文件方法
玩转Spring Cloud之装备中心(config server &config client) – 梦在旅途 – 博客园
https://eptable to specify a period as the first character of a name. For example, ".temp".
所以在Windows中,咱们我们能够运用文件名加点.的方法来进行无后缀文件读取
缝隙发生根本原因
org.springframework.cloud.config.server.environment.NativeEnvironmentRepository#getLocations
这儿发生了直接拼接{label}的行为
所以这儿两层url编码/为%252f仍是能够用,由于最终拼接成的途径是URL类,支撑%2f
运用 %252f 恳求
Spring修正方法
修正点在
spring-cloud-config-2.2.2.RELEASE/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/GenericResourceRepository.java
org.springframework.cloud.config.server.resource.GenericResourceRepository#findOne函数加入了对途径的判别
org.springframework.cloud.config.server.resource.GenericResourceRepository#isInvalidEncodedLocation 会先对途径进行url解码
org.springframework.cloud.config.server.resource.GenericResourceRepository#isInvalidLocation 然后检测是否包括 ..
检测的新方法
Windows 能够检测 C:/Windows/win.ini
Linux 能够检测 /etc/resolv.conf
(这儿测验Windows上file协议无法拜访其他盘,假如Spring Cloud Config Server 查找途径指定在 classpath,能够测验读取meta-INF/下面的文件,这儿是个检测难点)
作者:斗象才能中心 TCC – 小胖虎



