简单看下最近的Spring Secrurity、Spring漏洞(CVE-2024-22234、CVE-2024-22243)
最近的这两个cve我看国内很多情报将其评为高危,所以想着去看看原理,看完发现都比较简单,利用要求的场景也相对有限(特别是第一个),所以就随便看下就行了
Spring Security 用户认证绕过(CVE-2024-22234)
先看下官网的公告(https://spring.io/security/cve-2024-22234)
In Spring Security, versions 6.1.x prior to 6.1.7 and versions 6.2.x prior to 6.2.2, an application is vulnerable to broken access control when it directly uses the
AuthenticationTrustResolver.isFullyAuthenticated(Authentication)method.Specifically, an application is vulnerable if:
- The application uses
AuthenticationTrustResolver.isFullyAuthenticated(Authentication)directly and anullauthentication parameter is passed to it resulting in an erroneoustruereturn value.An application is not vulnerable if any of the following is true:
- The application does not use
AuthenticationTrustResolver.isFullyAuthenticated(Authentication)directly.- The application does not pass
nulltoAuthenticationTrustResolver.isFullyAuthenticated- The application only uses
isFullyAuthenticatedvia Method Security or HTTP Request Security
大概意思是直接调用``AuthenticationTrustResolver.isFullyAuthenticated(Authentication)` ,若Authentication为null,则方法会永远返回真,从而产生一些与预期相反的结果。
AuthenticationTrustResolver 接口中的 isFullyAuthenticated 方法用于检查 Authentication 对象是否完全经过身份验证,即是否不是匿名用户。在 Spring Security 中,可以使用这个方法来确定用户是否已经进行了完整的身份验证。
影响版本为:
- 6.1.0 to 6.1.6
- 6.2.0 to 6.2.1
环境搭建
引入pom,实际调用:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
增加下密码验证和/index的无鉴权的配置(交给应用手动配置)
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/", "/index").permitAll() // 端点/、/index 无需鉴权,交给应用直接控制
.anyRequest().authenticated()
)
.formLogin((form) -> form
.loginPage("/login")
.permitAll()
)
.logout((logout) -> logout.permitAll());
return http.build();
}
@Bean
public UserDetailsService userDetailsService() {
UserDetails user =
User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
}
新增控制器并配置需要用户手动输入密码(isFullyAuthenticated)后才能访问的逻辑:
@GetMapping("/index")
@ResponseBody
public String index(){
// CVE-2024-22234
// 获取当前的认证对象
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
System.out.println(authentication);
// 创建 AuthenticationTrustResolver 实例
AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
// 使用 isFullyAuthenticated 方法检查是否完全经过身份验证
boolean fullyAuthenticated = trustResolver.isFullyAuthenticated(authentication); // 传递null返回即为true
String msg = "";
if (fullyAuthenticated) {
msg = "用户已完全经过身份验证";
} else {
msg = "用户可能是匿名用户或者仅部分经过身份验证";
}
return msg;
}
复现
正常情况下,如果没有经过认证,返回的页面为:

进入登录页面正常登录后

返回的页面为:

如果开发在某些情况,比如手动清除SecurityContextHolder中的Authentication信息或通过异步处理导致在异步线程中没有可用的信息getAuthentication()返回null, 则会导致认证校验的失效,我们这里为了复现就手动置为null,
boolean fullyAuthenticated = trustResolver.isFullyAuthenticated(null);
重启应用,在不登陆的情况下,重新访问/index ,发现isFullyAuthenticated已经直接返回了true 。访问鉴权后的页面

修复
修复方式也比较简单在isFullyAuthenticated 中增加了对authentication对象为空的判断

Spring Framework SSRF or open redirect( CVE-2024-22243)
Applications that use
UriComponentsBuilderto parse an externally provided URL (e.g. through a query parameter) AND perform validation checks on the host of the parsed URL may be vulnerable to a open redirect attack or to a SSRF attack if the URL is used after passing validation checks.
这个看官网描述只知道使用UriComponentsBuilder这个方法来做host校验,会导致重定向和ssrf,粗看下源码不知道是怎么回事,看了下代码更新记录,很简单只是将uri匹配中userinfo匹配的正则表达式去掉[。

pre:
private static final String USERINFO_PATTERN = "([^@\\[/?#]*)";
now:
private static final String USERINFO_PATTERN = "([^@/?#]*)";
环境搭建
这里假设存在一个场景,后端会将用户输入的url交给UriComponentsBuilder进行验证,通过后进行正常的访问,后端有个简单的黑名单host判断(evil.com) :
String url = "http://xxx.com";
UriComponents uriComponents = UriComponents uriComponents = UriComponentsBuilder.fromUriString(url).build();
String host = uriComponents.getHost();
System.out.println("userinfo: " + uriComponents.getUserInfo());
System.out.println("host: " + host);
// 如果host为 evil.com 则会被拦截
if (host != null && host.equals("evil.com")) {
System.out.println("403");
}else {
System.out.println("pass");
}
简单场景,排除使用302、ip、rebind等方式,单纯从UriComponentsBuilder来进行绕过有什么办法?
复现
一般情况下我们知道绕过ssrf会用到@,如果url为http://A.com@B.com ,部分的host校验库会识别这个urlHost为A.com,而浏览器或者http client实际会访问B.com 利用这种差异就能绕过部分黑名单限制,直接访问恶意网站。
试下UriComponentsBuilder 可不可以:

很明显,在这个方法中,直接这么用是不行的,但根据漏洞的修复删除的正则表达式符号来看,我们在userinfo最后增加一个[,测试一下
成功绕过:


不过这样绕过后大部分情况下不能直接使用原url进行访问,因为url中存在[ 会让程序报错:

所以更多利用场景我猜可能是使用UriComponentsBuilder取的host重新进行url拼接来进行访问
总结
Spring Security中这个漏洞可能对于实战利用不大,因为黑盒测未授权都能测试出来不需要什么用户可控的绕过姿势,相对而言Spring Framework这个在实战中对于url可控的地方增加xxx[@yyy.com 可能会有奇效。
简单看下最近的Spring Secrurity、Spring漏洞(CVE-2024-22234、CVE-2024-22243)的更多相关文章
- 【Spring】Spring Session的简单搭建与源码阅读
搭建一个简单的Spring Session例子 引入依赖包 <dependencies> <dependency> <groupId>org.springframe ...
- 【springboot spring mybatis】看我怎么将springboot与spring整合mybatis与druid数据源
目录 概述 1.mybatis 2.druid 壹:spring整合 2.jdbc.properties 3.mybatis-config.xml 二:java代码 1.mapper 2.servic ...
- 看源码,重新审视Spring Security中的角色(roles)是怎么回事
在网上看见不少的博客.技术文章,发现大家对于Spring Security中的角色(roles)存在较大的误解,最大的误解就是没有搞清楚其中角色和权限的差别(好多人在学习Spring Security ...
- Spring Boot -- Spring AOP原理及简单实现
一.AOP基本概念 什么是AOP,AOP英语全名就是Aspect oriented programming,字面意思就是面向切面编程.面向切面的编程是对面向对象编程的补充,面向对象的编程核心模块是类, ...
- Spring Cloud实战 | 最八篇:Spring Cloud +Spring Security OAuth2+ Axios前后端分离模式下无感刷新实现JWT续期
一. 前言 记得上一篇Spring Cloud的文章关于如何使JWT失效进行了理论结合代码实践的说明,想当然的以为那篇会是基于Spring Cloud统一认证架构系列的最终篇.但关于JWT另外还有一个 ...
- IDEA下创建Maven项目,并整合使用Spring、Spring MVC、Mybatis框架
项目创建 本项目使用的是IDEA 2016创建. 首先电脑安装Maven,接着打开IDEA新建一个project,选择Maven,选择图中所选项,下一步. 填写好GroupId和ArtifactId, ...
- MyEclipse2014快速配置Spring & Spring Testing, Spring AOP简单使用
1.新建项目 2.右击项目,如图,利用myeclipse自动导入spring 3.在弹出的对话框中一直next到最后,在最后的页面中勾选Spring Testing,完成. 4.在src下的appli ...
- Maven环境下搭建SSH框架之Spring整合Hibernate
© 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Spring:4.3.8.RELEASE Hibernate:5.1.7.Final MySQL:5.7.17 注意:其他版本在某些特性 ...
- UWP入门(一) -- 先写几个简单控件简单熟悉下(别看这个)
原文:UWP入门(一) -- 先写几个简单控件简单熟悉下(别看这个) 1. MainPage.xmal <Grid Background="{ThemeResource Applica ...
- 深入分析Spring 与 Spring MVC容器
1 Spring MVC WEB配置 Spring Framework本身没有Web功能,Spring MVC使用WebApplicationContext类扩展ApplicationContext, ...
随机推荐
- [转帖]Nginx(2):架构设计与工作流程
https://cloud.tencent.com/developer/article/1886166?areaSource=&traceId= 这些天呐,实在是给我看晕了.起因自然还是对 n ...
- CentOS创建vsftp进行读写操作的简单方法
1. 安装vsftpd yum install epel-release yum install vsftpd 2. 进入系统设置简单进行处理 注意 user_list 是不允许访问的列表. [roo ...
- IBM Z15设备信息
- sed 删除包含某字符的一行 给包含某字符的一行添加 逗号的简单方法
今天处理环境折腾死了 方法: #给包含 configdata 的一行 添加 逗号结尾 find . -name "*.json" |xargs sed -i '/configdat ...
- Loki动态展示linux本地日志
Loki动态展示linux本地日志 背景 产品需要拆分微服务部署,直接使用K8S部署虽然比较规范但是部署时间较长. 本地文件系统部署简洁快速一些, 但是不太好直接复用一些规范的产品. 本次处理方法就是 ...
- Vue3类型判断和ref的两个作用
1.类型判断的四种方法 isRef: 检查一个值是否为一个ref对象 isReactive:检查一个对象是否是由 reactive 创建的响应式代理 isReadonly: 检查一个对象是否是由 re ...
- vs不同版本支持的c++版本和PlatformToolset,及在vs中切换c++版本
找c++资料从网上找确实更快速,但要想深入地理解vc++建议看msdn文档. vs不同版本支持的c++版本 C++17: vs2017基本支持,vs2015部分支持. C++14: vs2017就可以 ...
- 从零开始匹配vim(0)——vimscript 简介
通过之前一系列的文章,相信各位小伙伴应该已经对vim产生了浓厚的兴趣,可能不少小伙伴通过慢慢的使用变的跟我一样,离开vim就不会写代码了.如果你希望继续长时间使用vim,甚至将vim作为主要的代码编辑 ...
- 辣鸡 mac 下 pycharm 中代码拖拽的问题
Editor –> General Enable Drag'n'Drop functionality in Editor
- SpringSecurity使用步骤
一.导入jar包(使用maven构建项目导入其坐标) <dependency> <groupId>org.springframework.security</groupI ...