CVE-2022-22965

https://github.com/vulhub/vulhub/tree/master/spring/CVE-2022-22965

https://paper.seebug.org/1877/

https://sourcegraph.com/github.com/spring-projects/spring-framework/-/commit/002546b3e4b8d791ea6acccb81eb3168f51abb15?visible=1

https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/spring-projects/spring-framework%24%40v5.3.18:%5Ev5.3.17+type:commit&patternType=standard&sm=1&groupBy=author

https://sourcegraph.com/github.com/apache/tomcat/-/commit/8a904f6065080409a1e00606cd7bceec6ad8918c?visible=2

概述

基于JDK 9+的Spring框架RCE数据绑定(assets/CVE-2022-22965)

在JDK 9+上运行的Spring MVC或Spring WebFlux应用程序可能容易通过数据绑定受到远程代码执行(RCE)的攻击。特定的漏洞利用要求应用程序作为WAR部署在Tomcat上运行。如果应用程序部署为Spring Boot可执行jar(即默认情况),则不容易受到攻击。然而,该漏洞的性质更为普遍,可能还有其他方法可以利用它。

影响版本:

Spring ≤ 5.17

Tomcat ≤ 9.0.61

jdk ≥ 9

分析

class.module.classLoader.resources.context.parent.pipeline.first.pattern

%{c2}i if("j".equals(request.getParameter("pwd"))){ java.io.InputStream in = %{c1}i.getRuntime().exec(request.getParameter("cmd")).getInputStream(); int a = -1; byte[] b = new byte[2048]; while((a=in.read(b))!=-1){ out.println(new String(b)); } } %{suffix}i

原理分析

Java Bean PropertyDescriptor 用于获取符合 Java Bean规范的对象属性和 set/get 方法。

Spring BeanWrapperImpl 是 对 BeanWrapper 的默认实现,BeanWrapper接口是对Bean 的包装,BeanWrapperImpl对与 Bean 的属性访问和设置是调用的PropertyDescriptor。

class.module.classLoader.resources.context.parent.pipeline.first.pattern 再自动转换赋值执行流程可能如下

bean.getCLass().getModule().getClassLoader().getResources().getContext().getParent().getPipeline().getFirst().setPattern()

往上流传的 POC,是结合Tomcat 的日志去触发的,上面获取对象最后去设置的就是日志的格式,再结合设置日志文件后缀和存储位置等,可以实现jsp shell 。

修复分析

当 beanClass 是 Class.class 时,如果不是以 pd 的名字不是 name 并且也不是以 Name 结尾的,就跳过。

同时一会检测 PropertyType 是不是 classLoader 或者 ProtectionDomain,如果是的话也跳过。

Tomcat直接将 Resources 的路堵上了