远端WWW服务支持TRACE请求。RFC 2616介绍了TRACE请求,该请求典型地用于测试HTTP协议实现。
攻击者利用TRACE请求,结合其它浏览器端漏洞,有可能进行跨站脚本攻击,获取敏感信息,比如cookie中的认证信息,这些敏感信息将被用于其它类型的攻击。
如果目标存在服务端支持TRACE请求,验证方法如下
1.通过抓包软件burpsuite,重发数据
将请求方法修改为TRACE,相应包中返回 如图所示,则存在改漏洞
2.模拟trace请求,假设报漏洞的端口是8081:
curl -v -X TRACE -I localhost:8081
如果回显为,如下所示,则该端口服务支持trace请求,漏洞存在。
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: message/http
Content-Type: message/http
如果回显为,如下所示,则该漏洞不存在。
< HTTP/1.1 403 Forbidden
< Content-Type: text/html; charset=iso-8859-1
或者回显为
< HTTP/1.1 405 Method Not Allowed
< Content-Type: text/html; charset=iso-8859-1
1.对于apache:
对于2.0.55以上版本的apache服务器,
在httpd.conf尾部添加如下指令后重启apache即可:
TraceEnable off
其它版本的Apache服务器可编辑httpd.conf文件:
激活rewrite模块(去掉符号 # ):
LoadModule rewrite_module modules/mod_rewrite.so
在各虚拟主机的配置文件里添加如下语句:
# 启用 Rewrite 引擎
RewriteEngine On
# 对Request中的Method字段进行匹配:^TRACE 即以TRACE字符串开头
RewriteCond %{REQUEST_METHOD} ^TRACE
# 定义规则:对于所有格式的来源请求,均返回[F]-Forbidden响应
RewriteRule .* - [F]
注:可以在httpd.conf里搜索VirtualHost确定虚拟主机的配置文件。
2.对于非内嵌tomcat:
直接修改tomcat根目录conf目录下的web.xml,
在文件末尾(之前)添加如下代码:
/* PUT DELETE HEAD OPTIONS TRACE BASIC
注:在tomcat
的在server.xml
中先允许TRACE
请求,再在web.xml中
禁用TRACE
,以此禁用TRACE请求.
3.对于spring boot内嵌tomcat:
配置TomcatConfig.java
1 import org.apache.catalina.Context; 2 import org.apache.tomcat.util.descriptor.web.SecurityCollection; 3 import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 4 import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; 5 import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer; 6 import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; 7 import org.springframework.context.annotation.Bean; 8 import org.springframework.context.annotation.Configuration; 9 10 @Configuration 11 public class TomcatConfig { 12 13 @Bean 14 public EmbeddedServletContainerFactory servletContainer() { 15 TomcatEmbeddedServletContainerFactory tomcatServletContainerFactory = new TomcatEmbeddedServletContainerFactory(); 16 tomcatServletContainerFactory.addContextCustomizers(new TomcatContextCustomizer(){ 17 @Override 18 public void customize(Context context) { 19 SecurityConstraint securityConstraint = new SecurityConstraint(); 20 securityConstraint.setUserConstraint("CONFIDENTIAL"); 21 SecurityCollection collection = new SecurityCollection(); 22 23 collection.addPattern("/*"); 24 collection.addMethod("HEAD"); 25 collection.addMethod("PUT"); 26 collection.addMethod("DELETE"); 27 collection.addMethod("OPTIONS"); 28 collection.addMethod("TRACE"); 29 collection.addMethod("COPY"); 30 collection.addMethod("SEARCH"); 31 collection.addMethod("PROPFIND"); 32 securityConstraint .addCollection(collection); 33 context.addConstraint(securityConstraint ); 34 } 35 }); 36 37 //禁用TRACE请求 38 tomcatServletContainerFactory.addConnectorCustomizers(connector -> { 39 connector.setAllowTrace(true); 40 }); 41 return tomcatServletContainerFactory; 42 } 43 }
4.对于非内嵌式Jetty:
在jetty.xml中增加配置:
12 3 7NoTrace 4/* 5TRACE 68
5.对于Springboot内嵌式Jetty:
由于这种情况没有实际操作过,代码参考其他博主。采用拦截器来过滤所有的trace请求->启动类增加配置来实现,或者和内嵌式tomcat一样直接添加Jetty配置类来实现也可以。