springboot使用undertow服务器禁用TRACE请求
创始人
2025-01-20 00:33:13
0

问题描述:

今日在工作中遇到服务器被扫描出一个漏洞,描述如下:
风险描述:远程 Web 服务器支持 TRACE 和/或 TRACK方法。TRACE和 TRACK 是用于调试 Web 服务器连接的 HTTP 方法。
风险影响:通过一个跨站追踪攻击窃职 cookies 和验证信任

使用框架

springboot + redis +mybatis
web服务使用springboot 内嵌web服务 undertow
配置如下:

                               org.springframework.boot             spring-boot-starter-web                                                      spring-boot-starter-tomcat                      org.springframework.boot                                                                        org.springframework.boot             spring-boot-starter-undertow                      io.undertow         undertow-servlet           

在网上找啊找啊,大多是tomcat的,终于找到一个

@Bean public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {     UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();     factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {          @Override         public void customize(Builder builder) {             builder.addHttpListener(8080, "0.0.0.0");         }      });     return factory; }  

很遗憾不能用,各种类找不到BUG,接续找,终于找到springboot 2.0之后类名字变更,所以修改如下:

package com.ruoyi.medicine.config;  import io.undertow.servlet.api.DeploymentInfo; import io.undertow.servlet.api.SecurityConstraint; import io.undertow.servlet.api.WebResourceCollection; import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer; import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod;  /**  * @author wang'hai'yang  * @Description:  * @date 2024/2/2110:46  */ @Configuration public class EmbeddedServletContainerCustomizerConfig {      @Bean     public WebServerFactoryCustomizer containerCustomizer() {         return new WebServerFactoryCustomizer() {             @Override             public void customize(WebServerFactory factory) {                 if(factory.getClass().isAssignableFrom(UndertowServletWebServerFactory.class)){                     UndertowServletWebServerFactory underTowContainer = (UndertowServletWebServerFactory) factory;                     underTowContainer.addDeploymentInfoCustomizers(new ContextSecurityCustomizer());                 }             }         };     }      private static class ContextSecurityCustomizer implements UndertowDeploymentInfoCustomizer {         @Override         public void customize(DeploymentInfo deploymentInfo) {             SecurityConstraint constraint = new SecurityConstraint();             WebResourceCollection traceWebresource = new WebResourceCollection();             traceWebresource.addUrlPattern("/*");             traceWebresource.addHttpMethod(HttpMethod.TRACE.toString());             constraint.addWebResourceCollection(traceWebresource);             deploymentInfo.addSecurityConstraint(constraint);         }     } }  

测试方式及结果

在这里插入图片描述
如图所示,代表成功,否则 红框所示地方显示 HTTP/1.1 200 OK

相关内容

热门资讯

透视苹果版!pokerworl... 透视苹果版!pokerworld破解版下载,哈糖大菠萝破解器,举措教程(真的有挂)-哔哩哔哩poke...
透视ai代打!poker wo... 透视ai代打!poker world辅助器(透视)好像存在有挂,可靠教程(有挂插件挂)-哔哩哔哩一、...
八分钟揭露!wepoker怎么... 八分钟揭露!wepoker怎么挂飞机(透视)确实真的是有挂,AI教程(有挂实锤)-哔哩哔哩1、八分钟...
透视辅助!如何下载wepoke... 透视辅助!如何下载wepoker安装包,有没有人wepoker,举措教程(确实有挂)-哔哩哔哩如何下...
透视透视!拱趴大菠萝机器人(透... 透视透视!拱趴大菠萝机器人(透视)其实真的有挂,AI教程(有挂技巧)-哔哩哔哩1、拱趴大菠萝机器人透...
第5分钟详细!wepoker私... 第5分钟详细!wepoker私人定制透视(透视)竟然是有挂,必备教程(存在有挂)-哔哩哔哩1、点击下...
透视透视!wpk私人局辅助是真... 透视透视!wpk私人局辅助是真的吗,德普之星私人局辅助免费,方案教程(有人有挂)-哔哩哔哩1、德普之...
透视系统!werplan怎么辅... 透视系统!werplan怎么辅助(透视)切实是真的挂,详细教程(有挂脚本)-哔哩哔哩1、玩家可以在w...
一分钟普及!wepoker轻量... 一分钟普及!wepoker轻量版透视(透视)总是真的有挂,解密教程(真实有挂)-哔哩哔哩;1、游戏颠...
透视挂透视!we poker插... 透视挂透视!we poker插件,aapoker真的假的,策略教程(有挂助手)-哔哩哔哩1、aapo...