Spring RCE 0day高危漏洞预警 以及临时解决代码 (针对jdk9及以上)

Blade 未结 3 1151
yinyuncan
yinyuncan 剑师 2022-03-31 11:44

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

相关监测发现该漏洞可能已被远程攻击者利用,广东省网络安全应急响应中心连夜发布预警通知,考虑到Spring框架的广泛应用,FreeBuf对漏洞评级为:危险。

漏洞描述:

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

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

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

  • 使用JDK9及以上版本的Spring MVC框架

  • Spring 框架以及衍生的框架spring-beans-*.jar 文件或者存在CachedIntrospectionResults.class

漏洞影响范围:

JDK9 <= Spring Cloud Function 执行“java-version”命令可查看JDK版本

解决方案(临时):

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;
/**
 *
 * Spring RCE 0day高危漏洞预警
 * 远程代码执行漏洞临时缓解措施
 * @author yun.can
 * @since : 2022-03-31 09:26
 */
@ControllerAdvice
@Order(10000)
public class GlobalControllerAdvice
{
   /**
    * 每次请求会进来一次
    * @param dataBinder 数据绑定
    */
    @InitBinder
    public void setAllowedFields(WebDataBinder dataBinder)
    {
        String[] classFields = new String[]{"class.*","Class.*","*.class.*","*.Class.*"};
//      参数禁止接收 class 关键字参数, * 为通配符
        dataBinder.setDisallowedFields(classFields);
    }
}


3条回答
提交回复