CVE-2022-22978

本文探讨了CVE-2022-22978漏洞,如何通过在镜像拉取时利用%0a绕过机制,可能导致命令注入或脚本注入,威胁网站安全。

CVE-2022-22978
拉取镜像
在这里插入图片描述此时可成功访问该网站
在这里插入图片描述
正常访问admin页面
在这里插入图片描述
此时我们使用%0a进行绕过
在这里插入图片描述
%0a为什么可以绕过

%0a 表示换行符,如果它被插入到输入中,并且该输入被解释为命令或脚本的一部分,可能导致命令注入或脚本注入漏洞。

### ### 验证 Spring Security 中 RegexRequestMatcher 的认证绕过漏洞 CVE-2022-22978 是否存在或已修复 CVE-2022-22978 是 Spring Security 中由于 `RegexRequestMatcher` 对 URL 路径的正则匹配逻辑不当,导致攻击者可以构造特定路径绕过安全配置中的访问控制规则。该漏洞影响 Spring Security 5.7.0 至 5.7.1、5.6.0 至 5.6.6、5.5.0 至 5.5.8 等版本。修复版本为 Spring Security 5.7.2、5.6.7 和 5.5.9[^1]。 为了验证当前 Spring Security 版本是否受该漏洞影响,可以构造一个绕过正则表达式匹配的请求路径,并观察其是否被错误地允许访问受保护资源。 #### ### 验证代码示例 以下是一个用于测试 `RegexRequestMatcher` 行为的 Spring Boot 应用安全配置示例: ```java import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.RegexRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { RequestMatcher protectedMatcher = new RegexRequestMatcher("/admin/.*", null); http .authorizeRequests() .requestMatchers(protectedMatcher).authenticated() .anyRequest().permitAll() .and() .formLogin(); return http.build(); } } ``` 在该配置中,所有以 `/admin/` 开头的路径都要求用户必须认证。为了验证是否存在 CVE-2022-22978 漏洞,可以构造如下请求路径进行测试: ``` GET /admin%2e%2e%2fsecret HTTP/1.1 Host: localhost ``` 此请求路径在某些版本的 `RegexRequestMatcher` 中可能被解析为 `/admin../secret`,从而绕过 `/admin/.*` 的正则匹配规则,导致未认证用户访问 `/admin/../secret`(即 `/secret`)资源。 #### ### 预期行为 如果 Spring Security 版本存在 CVE-2022-22978 漏洞,则上述请求将被误认为匹配 `/admin/.*`,进而允许未认证用户访问 `/secret` 页面。若版本已修复,则该请求应被正确拒绝,用户必须认证后才能访问。 #### ### 验证修复状态 可以通过检查 Spring Security 的版本并运行测试请求来确认是否已修复: - **受影响版本**:5.7.0、5.7.1、5.6.0 ~ 5.6.6、5.5.0 ~ 5.5.8 - **已修复版本**:5.7.2、5.6.7、5.5.9 及以上版本 在修复版本中,`RegexRequestMatcher` 已更新以防止路径遍历攻击,确保 URL 在匹配前被规范化,从而避免路径绕过问题。 #### ### 模拟攻击场景测试 测试控制器示例: ```java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { @GetMapping("/admin/dashboard") public String adminDashboard() { return "Welcome to admin dashboard"; } @GetMapping("/secret") public String secret() { return "This is a secret page"; } } ``` 使用 curl 或 Postman 发送如下请求: ```bash curl -v http://localhost:8080/admin%2e%2e%2fsecret ``` 若返回 `This is a secret page` 且未要求认证,则说明存在漏洞;若返回 401 或重定向至登录页面,则说明已修复。 #### ### 验证建议 - **升级 Spring Security** 确保使用 5.7.2 或更高版本,以确保修复了 CVE-2022-22978 漏洞[^1]。 - **使用 AntPathRequestMatcher 替代** 在安全配置中优先使用 `AntPathRequestMatcher`,它对路径处理更为稳健,不易受到路径遍历攻击。 - **URL 解码与规范化** 在进行请求匹配前,确保对 URL 进行解码和规范化处理,例如使用 `UrlPathHelper` 的 `removeSemicolonContent` 和 `normalize` 方法。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值