[关闭]
@websec007 2017-10-12T08:15:01.000000Z 字数 1524 阅读 2534

Tomcat 安全加固

未分类


学习参考

http://www.zhutougg.com/2017/10/11/tomcatzhi-jie-shou-get-postqing-qiu-fang-fa/

一、禁用HTTP请求方法

禁用方式比较简单,只需要在web.xml文件中配置以下内容即可完成,具体配置可参考如下说明。(注:web.xml配置文件有多个,不同的业务目录下可能都存在web.xml,默认配置$Tomcat/conf目录下的web.xml 即可禁用根目录下所有业务的相关请求。如有特殊业务需求可独立配置您实际业务目录下的web.xml文件)

将你需要禁用的HTTP请求方法(PUT/DELETE/HAED...),直接参考如下代码的格式添加好相关禁用方法,然后将整段代码加在<webapp>标签字段之中,即可实现当前业务下路径的HTTP请求方法的禁用。

禁用HTTP 请求方法代码

  1. <security-constraint>
  2. <web-resource-collection>
  3. <url-pattern>/*</url-pattern>
  4. <http-method>PUT</http-method>
  5. <http-method>DELETE</http-method>
  6. <http-method>HEAD</http-method>
  7. <http-method>OPTIONS</http-method>
  8. <http-method>TRACE</http-method>
  9. </web-resource-collection>
  10. <auth-constraint>
  11. </auth-constraint>
  12. </security-constraint>

二、加固实操

例如你需要禁用Tomcat默认conf 目录下的所有业务请求中的PUT、DELETE、HEAD、OPTIONS、TRACE方法(即只开启GET 与 POST方法 )。

2.1 配置步骤

  1. <security-constraint>
  2. <web-resource-collection>
  3. <url-pattern>/*</url-pattern>
  4. <http-method>PUT</http-method>
  5. <http-method>DELETE</http-method>
  6. <http-method>HEAD</http-method>
  7. <http-method>OPTIONS</http-method>
  8. <http-method>TRACE</http-method>
  9. </web-resource-collection>
  10. <auth-constraint>
  11. </auth-constraint>
  12. </security-constraint>

2.2 实际效果验证

我们直接使用curl 命令行工具进行HTTP 请求方法验证,具体操作命令如下。

  1. # curl -I -X OPTIONS http://127.0.0.1:8080/
  2. # curl -I -X OPTIONS http://127.0.0.1:8080/examples/

https://www.linuxquestions.org/questions/programming-9/tomcat-6-0-24-how-do-i-disable-delete-put-options-916212/

http://www.techstacks.com/howto/disable-http-methods-in-tomcat.html

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注