漏洞描述
CVE-2025-22228 是一个存在于 Spring Security 的 spring-security-crypto 包中的身份验证绕过漏洞。该漏洞允许攻击者通过使用超过 72 个字符的密码来绕过身份验证机制,只要前 72 个字符与实际密码匹配即可。
漏洞影响:
漏洞类型:身份验证绕过
攻击者可以利用该漏洞绕过身份验证,从而访问受保护的资源。
影响版本:
-
- <=5.6.12
- > =5.7.0 <5.7.16
- > =5.8.0 <5.8.18
- > =6.0.0 <=6.0.16
- > =6.1.0 <6.1.14
- > =6.2.0 <6.2.10
- > =6.3.0 <6.3.8
- > =6.4.0 <6.4.4
本地复现过程
复现结果,能看见不同的密码加密后的值是相同的,容易造成身份验证绕过
复现代码
import org.springframework.security.crypto.bcrypt.BCrypt;import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;publicclassMain {publicstaticvoidmain(String[] args) {// 原始密码大72位Stringpassword1="999999999999999999999999999999999999999999999999999999999999999999999999";Stringpassword2="999999999999999999999999999999999999999999999999999999999999999999999999aaaaaaaa";// 生成盐值Stringsalt= BCrypt.gensalt();// 使用推荐的方法进行哈希处理StringhashedPassword1= BCrypt.hashpw(password1, salt);StringhashedPassword2= BCrypt.hashpw(password2, salt);// 输出哈希后的密码 System.out.println("Hashed Password: " + hashedPassword1); System.out.println("Hashed Password: " + hashedPassword2); }}
pom
<dependencies><!-- Spring Security Crypto --><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-crypto</artifactId><version>5.8.11</version></dependency></dependencies>
具体漏洞位于密码比对的地方位于org.springframework.security.crypto.bcrypt下的String hashpw(byte[] passwordb, String salt, boolean for_check)方法
修复建议
升级到修复版本:尽快将受影响的应用程序升级到已修复该漏洞的 Spring Security 版本
使用商业支持:如果您使用的是不再受社区支持的 Spring Security 版本,可以考虑使用商业支持服务,如 HeroDevs,以获得额外的安全支持
密码长度限制:作为临时解决方案,可以在应用程序代码中实现密码长度验证,确保传递给 BCryptPasswordEncoder.matches 方法的密码不超过 72 个字符
PS:现实中真的没见过密码设置超过72个字符的人,估计都记不住,所以这个漏洞现实意义不大
原文始发于微信公众号(Z0安全):【CVE-2025-22228】Spring Security 漏洞分析复现
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论