1.漏洞描述

平安集团银河实验室安全研究人员发现Pivotal公司旗下产品 Spring Cloud Config Server 的安全漏洞(CVE-2019-3799)并第一时间向Pivotal公司进行报告。Pivotal公司发布了关键补丁更新公告 https://pivotal.io/security/cve-2019-3799

Spring Cloud Config是一套开源分布式系统配置服务,为分布式环境提供外部配置服务支持。

Spring Cloud Config Server 路径穿越与任意文件读取漏洞,可通过构造的恶意请求直接读取服务器任意文件,风险较大。

影响范围:

  • 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不安全版本

2.修复措施

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

3.漏洞复现

GET /test/dev/master/..%252F..%252F..%252F..%252F..%252F..%252F..%252Fetc%252Fpasswd HTTP/1.1

Host: 0.0.0.0:8001

4.漏洞分析

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路径地址吃掉,最终达到穿越到任意路径,读取任意文件的效果。

声明:本文来自银河安全实验室,版权归作者所有。文章内容仅代表作者独立观点,不代表安全内参立场,转载目的在于传递更多信息。如有侵权,请联系 anquanneican@163.com。