Spring Framework URL解析不当漏洞以及绕过
原创 信安路漫漫 信安路漫漫 2024-03-21 07:02
前言
前面出了Spring Framework URL解析不当的一个漏洞CVE-2024-22243,修复以后又出现了一个绕过的漏洞CVE-2024-22257,下面就一起来看看这两个漏洞。
CVE-2024-22243漏洞描述Spring Framework 是一个开源的Java应用程序框架,UriComponentsBuilder是Spring Web中用于构建和操作URI的工具类。受影响版本中,由于 UriComponentsBuilder 处理URL时未正确过滤用户信息中的方括号 [
,攻击者可构造包含方括号的恶意URL绕过主机名验证。如果应用程序依赖UriComponentsBuilder.fromUriString()等方法对URL进行解析和校验,则可能导致验证绕过,出现开放重定向或SSRF漏洞。影响范围org.springframework:spring-web@[6.1.0, 6.1.4)org.springframework:spring-web@[6.0.0, 6.0.17)org.springframework:spring-web@(-∞, 5.3.32)libspring-java@影响所有版本POChttp://www.xxx.com[@www.evil.com漏洞复现pom文件 org.springframework.boot spring-boot-starter-parent 2.7.18 4.0.0 spring-uricomponentsbuilder 8 8 org.springframework.boot spring-boot-starter-web org.springframework spring-web 5.3.31 OauthController.javaimport org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.util.UriComponents;import org.springframework.web.util.UriComponentsBuilder;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.util.Arrays;import java.util.HashSet;import java.util.Set;@Controller@RequestMapping(“/oauth”)public class OAuthController { private static final Set whiteDomains = new HashSet<>(Arrays.asList(new String[]{ “.fuckpdd.com” })); /* * 一般绕过oauth的host校验,可以开放重定向到恶意站点劫持code * 访问:http://127.0.0.1:8080/oauth?redirect_uri=http%3A%2F%2Fwww.fuckpdd.com%5B%40www.evil.com%2Ftou * * * @param redirectUri http://www.fuckpdd.com[@www.evil.com/tou * @return / @GetMapping public String oauth(@RequestParam(name = “redirect_uri”) String redirectUri, HttpServletResponse response) throws IOException { UriComponents uriComponents = UriComponentsBuilder.fromUriString(redirectUri).build(); String schema = uriComponents.getScheme(); String host = uriComponents.getHost(); String path = uriComponents.getPath(); System.out.printf(“schema:%s\n”, schema); System.out.printf(“host:%s\n”, host); System.out.printf(“path:%s\n”, path); boolean pass = false; for (String whiteDomain : whiteDomains) { if (host.endsWith(whiteDomain)) { pass = true; break; } } if (!pass) return “error”; return “redirect:” + redirectUri; }}从上面的代码中可以看到对host头设置了白名单,如果不在白名单内则返回error。在白名单内则跳转到redirectUri。不在白名单内时:在白名单内时:利用漏洞:可以看到利用[可以成功绕过这个限制。在新的版本修复了上面的漏洞,但是没有修复彻底,还可以绕过,下面就一起来看看绕过。Spring Web UriComponentsBuilder URL解析不当漏洞(CVE-2024-22243绕过)Spring Framework 是一个开源的Java应用程序框架,UriComponentsBuilder是Spring Web中用于构建和操作URI的工具类。由于对CVE-2024-22243的修复不充分,攻击者可构造一下两类 url 绕过主机名验证,导致开放重定向或SSRF漏洞:1、包含以 http 开头的 scheme 但不包含 host;2、url 中的 host 以 [
开头但不以 ]
结尾。影响范围org.springframework:spring-web@[6.1.0, 6.1.5)org.springframework:spring-web@[6.0.0, 6.0.18)org.springframework:spring-web@(-∞, 5.3.33)复现新版本中改成了5.3.32此时,用上面的poc运行,发现报错可以通过下面的方式绕过修复方案将 org.springframework:spring-web 升级至 6.1.5 及以上版本将 org.springframework:spring-web 升级至 6.0.18 及以上版本将 org.springframework:spring-web 升级至 5.3.33 及以上版本