Spring框架爆RCE 0day漏洞的临时解决方案

3月29日,Spring框架曝出RCE 0day漏洞。已经证实由于 SerializationUtils#deserialize 基于 Java 的序列化机制,可导致远程代码执行(RCE),使用JDK9及以上版本皆有可能受到影响。

漏洞描述:
作为目前全球最受欢迎的Java轻量级开源框架,Spring允许开发人员专注于业务逻辑,简化Java企业级应用的开发周期。

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

目前已知,触发该漏洞需要满足两个基本条件:

  • 使用JDK9及以上版本的Spring MVC框架
  • Spring 框架以及衍生的框架spring-beans-*.jar 文件或者存在CachedIntrospectionResults.class

临时解决方案:

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

springRCE.java

package org.jeecg.modules.nanxin;

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;

/**
 * @author: myqxin
 * @Desc:
 * @create: 2022-03-30 16:09
 **/
@ControllerAdvice
@Order(10000)
public class SpringRCE {
    
    
    @InitBinder
    public void setAllowedFields(WebDataBinder dataBinder) {
    
    
        String[] abd = new String[]{
    
    "class.*", "Class.*", "*.class.*", "*.Class.*"};
        dataBinder.setDisallowedFields(abd);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_45752401/article/details/123849309