web漏洞-远端WWW服务支持TRACE请求

漏洞描述

          远端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,
在文件末尾(</web-app>之前)添加如下代码:

<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>

注:在tomcat的在server.xml中先允许TRACE请求,再在web.xml中禁用TRACE,以此禁用TRACE请求.

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" allowTrace="true"
               redirectPort="8443" />

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中增加配置:

1 <security-constraint>
2     <web-resource-collection>
3         <web-resource-name>NoTrace</web-resource-name>
4         <url-pattern>/*</url-pattern>
5         <http-method>TRACE</http-method>
6     </web-resource-collection>
7     <auth-constraint></auth-constraint>
8 </security-constraint>

5.对于Springboot内嵌式Jetty:

由于这种情况没有实际操作过,代码参考其他博主。采用拦截器来过滤所有的trace请求->启动类增加配置来实现,或者和内嵌式tomcat一样直接添加Jetty配置类来实现也可以。

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lzylbp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值