(CVE-2020-5405)Spring Cloud Config Server 目录穿越
一、漏洞简介
二、漏洞影响
Spring Cloud Config Server 2.2.0-2.2.1
Spring Cloud Config Server 2.1.0-2.1.6
三、复现过程
漏洞分析
其实往前看有个替换的操作,很显眼
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
在CVE-2019-3799中,我们使用的配置是常用的spring.cloud.config.server.git.uri
,它会选择使用MultipleJGitEnvironmentRepository.class
的getLocations,然后就会走到checkout,抛出异常了,那么我们怎么去不走checkout逻辑呢。
得知这个配置是让它从本地进行加载,而不是用git,通过在application.properties配置
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=file:/Users/p0desta/Desktop
其实通过补丁我们也可以发现端倪
配置后重新跟进调试
然后就在/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.class@getLocations
中对路径进行了处理,大致就是对路径进行拼接,然后存在ouput数组中,返回一个新的Locations对象
然后后面就是跟CVE-2019-3799一样,直接读文件了。