spring Framework 特定条件下目录遍历漏洞(CVE-2024-38816)修复
漏洞描述
CVE-2024-38816: Path traversal vulnerability in functional web frameworks
通过功能性 Web 框架 WebMvc.fn 或 WebFlux.fn 提供静态资源的应用程序容易受到路径遍历攻击。攻击者可以编写恶意 HTTP 请求并获取文件系统上任何可由 Spring 应用程序正在运行的进程访问的文件。
具体来说,当以下两个条件都成立时,应用程序就容易受到攻击:
- Web 应用程序用于
RouterFunctions
提供静态资源 - 资源处理明确配置了
FileSystemResource
位置
但是,当以下任何一项满足时,恶意请求都会被阻止和拒绝:
- Spring Security HTTP 防火墙正在使用中
- 应用程序在 Tomcat 或 Jetty 上运行
受影响的 Spring 产品和版本
Spring 框架
- 5.3.0 - 5.3.39
- 6.0.0 - 6.0.23
- 6.1.0 - 6.1.12
- 较旧的、不受支持的版本也受到影响
分析:
通常我们会把sprintboot项目打包war部署tomcat,
或者直接本地springboot 运行(内置tomcat)
上述两种方式都阻止漏洞,因为tomcat会拦截,返回错误如下:
<!doctype html>
<html lang="en">
<head>
<title>HTTP Status 400 – Bad Request</title>
<style type="text/css">
body {
font-family: Tahoma, Arial, sans-serif;
}
h1,
h2,
h3,
b {
color: white;
background-color: #525D76;
}
h1 {
font-size: 22px;
}
h2 {
font-size: 16px;
}
h3 {
font-size: 14px;
}
p {
font-size: 12px;
}
a {
color: black;
}
.line {
height: 1px;
background-color: #525D76;
border: none;
}
</style>
</head>
<body>
<h1>HTTP Status 400 – Bad Request</h1>
<hr class="line" />
<p><b>Type</b> Status Report</p>
<p><b>Message</b> Invalid URI</p>
<p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a
client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
</p>
<hr class="line" />
<h3>Apache Tomcat/9.0.46</h3>
</body>
</html>
综上,内置和外置的tomcat都会校验地址,通过后才会进入spring webmvc解析才可能触发漏洞。
因此要重现漏洞需用不知名web服务器。 webflux默认采用netty也无需处理。
漏洞原因:spring地址解析URL地址代码考虑欠缺,需要依赖前置的web服务器(比如tomcat)拦截
修复参考: