Spring Cloud Config Server 任意文件读取漏洞安全通告

发布时间 2019-04-18

漏洞编号和级别


CVE编号:CVE-2019-3799,危险级别:高危,CVSS分值:官方未评定


影响版本


Spring Cloud Config 2.1.0 to 2.1.1

Spring Cloud Config 2.0.0 to 2.0.3

Spring Cloud Config 1.4.0 to 1.4.5

其他不受支持的老版本 (如Spring Cloud Config1.3及其以下版本)

值得注意的是通过maven自动构建的应用,如果不指定spring-cloud-config-server的版本,默认安装的还是spring-cloud-config-server 1.3.0不安全版本


漏洞概述


Spring Cloud Config一套开源分布式系统配置服务,为分布式环境提供外部配置服务支持。Spring Cloud Config Server 路径穿越与任意文件读取漏洞,可通过构造的恶意请求直接读取服务器任意文件,风险较大。


漏洞验证


环境搭建: https://github.com/spring-cloud/spring-cloud-config#quick-start

GET /foo/default/master/..%252F..%252F..%252F..%252Fetc%252fpasswd HTTP/1.1

Host: localhost:8888




Spring Cloud Config项目是一个解决分布式系统的配置管理方案。它包含了ClientServer两个部分,server提供配置文件的存储、以接口的形式将配置文件的内容提供出去,client通过接口获取数据、并依据此数据初始化自己的应用。Spring cloud使用gitsvn存放配置文件,默认情况下使用git


环境搭建:


Pom.xml 配置依赖



Application.yml 设置配置文件存放的远程仓库地址



启动文件



org/springframework/cloud/config/sever/resource/ResourceController.java中可以查看http请求格式为@RequestMapping("/{name}/{profile}/{label}/**")

name为应仓库名称

profile为应配置文件环境

label 为git分支名

** 为具体文件名

实际测试中只需要label为存在的分支名即可,一般git仓库都存在master分支

所以通用poc地址为:

/test/dev/master/..%252F..%252F..%252F..%252F..%252F..%252F..%252Fetc%252Fpasswd



传入参数后 会调用this.resourceRepository.findOne(name, profile, label, path)并根据配置文件中的仓库地址去组装新的地址并获取文件内容。我们跟入到org.springframework.cloud.config.server.resourcefindOne方法中。


findOne 中location为远程git地址下载到本地的tmp目录地址,然后和我们传入的path拼装为file:/var/folders/2t/2pcjgph96ms9jltyfnm5brr40000gn/T/config-repo-1763575875528585941/..%2F..%2F..%2F..%2F..%2F..%2F.-dev.%2Fetc%2Fpasswd


this.resourceLoader.getResource(path)方法为 spring.core中封装的获取资源文件方法,默认会还原URLdecode的地址并通过 ../../将前面的tmp路径地址吃掉,最终达到穿越到任意路径,读取任意文件的效果。


修复建议


Spring Cloud Config 2.1.x 升级至 to 2.1.2Spring Cloud Config 2.0.x u升级至 2.0.4Spring Cloud Config 1.4.x 升级至 1.4.6老版本升级到指定的安全版本spring-cloud-config-server应部署在内网中并使用Spring Security进行用户身份鉴定。


Spring Security配置支官方文档Securing Spring Cloud Config Server

https://github.com/spring-cloud/spring-cloud-config/commit/3632fc6f64e567286c42c5a2f1b8142bfde505c2


参考链接


https://pivotal.io/security/cve-2019-3799