随笔BUG记录

Apache Tomcat 服务器禁用非安全的HTTP方法(PU

2024-01-17  本文已影响0人  红与树

渗透测试发现 WebDAV 的远程代码执行漏洞,主要是服务器未禁止除 get 和 post 以外的 HTTP 方法,如 PUT 、DELETE、OPTIONS 方法等。 如下所示:


对于 Tomcat 8 服务器,解决方法是在项目的web.xml中添加安全访问策略。为方便拷贝,代码如下:

    <!-- 禁用非安全方法 加上auth-constraint验证 -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>NoAccess</web-resource-name>
            <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/>
    </security-constraint>

    <!-- GET/POST 不需auth-constraint 此段可去掉 -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>AllowedMethods</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
    </security-constraint>
  
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>

通过security-constraint和login-config配合实现禁用。配置在应用的web.xml中只针对该应用,配置在tomcat下的web.xml应用于所有应用。

tip:在server.xml中,还需要把Connector 的allowTrace属性设为"true" ,来允许支持trace方法再通过上面配置才能关闭 trace 方法,allowTrace的默认值是 false

扩展:HTTP1.0 定义了三种请求方法: GET, POST 和 HEAD 方法。HTTP1.1 新增了六种请求方法:OPTIONS、PUT、PATCH、DELETE、TRACE 和 CONNECT 方法。

上一篇 下一篇

猜你喜欢

热点阅读