其他
Spring 官方证实!框架爆漏洞,JDK 9 及以上版本均受影响
大家好,我是磊哥。
Spring 框架出现的 RCE 0day 漏洞影响的范围为 JDK 版本号在 9 及以上的、使用了 Spring 框架或衍生框架。
别慌,虽然现在 Java 已经到了 Java 18 版本,但是很多企业仍然停留在 Java 8 版本及以下。
Spring 零日漏洞真的存在
JDK 9 或更高版本
Apache Tomcat 作为 Servlet 容器
打包为传统的 WAR(与 Spring Boot 可执行 jar 相比)
spring-webmvc 或 spring-webflux 依赖
Spring Framework 版本 5.3.0 到 5.3.17、5.2.0 到 5.2.19 以及更早的版本
@ControllerAdvice
@Order(Ordered.LOWEST_PRECEDENCE)
public class BinderControllerAdvice {
@InitBinder
public void setAllowedFields(WebDataBinder dataBinder) {
String[] denylist = new String[]{"class.*", "Class.*", "*.class.*", "*.Class.*"};
dataBinder.setDisallowedFields(denylist);
}
}
package car.app;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.ServletRequestDataBinder;import org.springframework.web.context.request.NativeWebRequest;import org.springframework.web.method.annotation.InitBinderDataBinderFactory;import org.springframework.web.method.support.InvocableHandlerMethod;import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;import org.springframework.web.servlet.mvc.method.annotation.ServletRequestDataBinderFactory;@SpringBootApplicationpublic class MyApp { public static void main(String[] args) { SpringApplication.run(CarApp.class, args); }@ Bean public WebMvcRegistrations mvcRegistrations() { return new WebMvcRegistrations() {@ Override public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() { return new ExtendedRequestMappingHandlerAdapter(); } }; } private static class ExtendedRequestMappingHandlerAdapter extends RequestMappingHandlerAdapter {@ Override protected InitBinderDataBinderFactory createDataBinderFactory(List < InvocableHandlerMethod > methods) { return new ServletRequestDataBinderFactory(methods, getWebBindingInitializer()) {@ Override protected ServletRequestDataBinder createBinderInstance(Object target, String name, NativeWebRequest request) throws Exception { ServletRequestDataBinder binder = super.createBinderInstance(target, name, request); String[] fields = binder.getDisallowedFields(); List < String > fieldList = new ArrayList < > (fields != null ? Arrays.asList(fields) : Collections.emptyList()); fieldList.addAll(Arrays.asList("class.*", "Class.*", "*.class.*", "*.Class.*")); binder.setDisallowedFields(fieldList.toArray(new String[] {})); return binder; } }; } }}
整理 | 苏宓
出品 | CSDN(ID:CSDNnews)