当前位置:   article > 正文

tomcat漏洞修复_tomcat content-security-policy

tomcat content-security-policy

可通过HTTP获取远端WWW服务信息

漏洞详情:

本插件检测远端HTTP Server信息。这可能使得攻击者了解远程系统类型以便进行下一步的攻击。

该漏洞仅是为了信息获取,建议隐藏敏感信息。

解决方法:

隐藏版本号

进入$CATALINA_HOME\lib 目录中,

依次执行如下命令:


<code class="language-plaintext hljs">mkdir -p org/apache/catalina/util //创建文件夹,名称不可更改
cd org/apache/catalina/util //进入目录
vim ServerInfo.properties //创建文件,写入内容
server.info=Apache Tomcat //这里编写自定义的版本信息</code>

目标X-Content-Type-Options等响应头缺失

漏洞详情:

X-Content-Type-Options HTTP 消息头相当于一个提示标志,被服务器用来提示客户端一定要遵循在 Content-Type 首部中对 MIME 类型 的设定,而不能对其进行修改。这就禁用了客户端的 MIME 类型嗅探行为,换句话说,也就是意味着网站管理员确定自己的设置没有问题。

X-Content-Type-Options响应头的缺失使得目标URL更易遭受跨站脚本攻击。

X-XSS-Protection响应头缺失

X-Frame-Options

Strict-Transport-Security

解决方法:

打开tomcat/conf/web.xml,增加如下配置


<code class="language-plaintext hljs">   <filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>hstsEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>hstsMaxAgeSeconds</param-name>
            <param-value>31536000</param-value>
        </init-param>
        <init-param>
            <param-name>antiClickJackingEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>antiClickJackingOption</param-name>
            <param-value>SAMEORIGIN</param-value>
        </init-param>
        <init-param>
            <param-name>blockContentTypeSniffingEnabled</param-name> <!-- X-Content-Type-Options 默认: true(nosniff) -->    
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>xssProtectionEnabled</param-name> <!-- X-XSS-Protection 默认: true(1; mode=block) -->    
            <param-value>true</param-value>
        </init-param>
    </filter>



   <filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
</code>

效果如图

检测到目标X-Download-Options响应头缺失

漏洞详情:

Web 服务器对于 HTTP 请求的响应头中缺少 X-Download-Options,这将导致浏览器提供的安全特性失效。 漏洞危害: Web 服务器对于 HTTP 请求的响应头中缺少 X-Download-Options,这将导致浏览器提供的安全特性失效,更容易遭受 Web 前端黑客攻击的影响。

解决方法:

在Tomcat服务器的web.xml上配置,路径tomcat/conf/web.xml。修改内容如下:


<code class="language-plaintext hljs"><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1">
  <!-- 以上是tomcat中本身存在,下面是新添加内容-->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>http method security</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>PUT</http-method>
            <http-method>DELETE</http-method>
            <http-method>HEAD</http-method>
            <http-method>TRACE</http-method>
        </web-resource-collection>
        <auth-constraint/>
    </security-constraint></code>

重新部署程序,重启tomcat即可完成

如下图:

检测到目标Content-Security-Policy响应头缺失

漏洞详情:

HTTP 响应头Content-Security-Policy允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定服务器的源和脚本结束点。

Content-Security-Policy响应头的缺失使得目标URL更易遭受跨站脚本攻击。

解决办法:

将您的服务器配置为发送“Content-Security-Policy”头。对于 Apache,请参阅:http://httpd.apache.org/docs/2.2/mod/mod_headers.html对于 IIS,请参阅:Add a Custom HTTP Response Header (IIS 7) | Microsoft Learn对于 nginx,请参阅:Module ngx_http_headers_module

tomcat: web.xml 添加如下:


<code class="language-plaintext hljs">    <filter>
        <filter-name>HttpHeaderSecurityFilter</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <init-param>
           <param-name>contentSecurityPolicy</param-name>
           <param-value>default-src 'self'; script-src 'self' xxx.xxx.com.cn:8080 xxx.xxx.com.cn;</param-value>
        </init-param>
    </filter>
 
     <filter-mapping>
        <filter-name>HttpHeaderSecurityFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping></code>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/741258
推荐阅读
相关标签
  

闽ICP备14008679号