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项目是一个解决散布式系统的配置治理规划 。它蕴含了Client和Server两个部门,server提供配置文件的存储、以接口的大局将配置文件的内容提供出去,client通过接口获取数据、并凭据此数据初始化自己的利用 。Spring cloud使用git或svn存放配置文件,默认情况下使用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.resource的findOne步骤中 。


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.2,Spring Cloud Config 2.0.x u升级至 2.0.4,Spring 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