任务:
禁用 WebDAV,或者禁止不需要的 HTTP 方法。
解决方案:
如何禁止DELETE、PUT、OPTIONS、TRACE、HEAD等协议访问应用程序应用程序呢?
解决方法
第一步:修改应用程序的web.xml文件的协议
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
第二步:在应用程序的web.xml中添加如下的代码即可
<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中conf下的web.xml,步骤同上。
任务:
Slow HTTP Denial of Service Attack漏洞是利用HTTPPOST的时候,指定一个非常大的content-length,然后以很低的速度发包,比如10-100s发一个字节,让这个连接不断开。这样当客户端连接多了后,占用了服务器的所有可用连接,从而导致DOS,属于一种拒绝服务攻击。
解决方案:
打开tomcat的server.xml找到
<Connector port="8080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
将其中的connectionTimeout="20000"改为connectionTimeout="8000",其单位是毫秒。
任务:
javascript等脚本语言能够通过http操纵cookie,对服务器发起XSS攻击。
解决方案:
在应用程序的web.xml文件里,进行以下设置:
<!-- 设置session相关属性 -->
<session-config>
<session-timeout>过期时长(单位为分钟)</session-timeout>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
</session-config>
任务:
在操作时可以输入危险字符。如”<,>,’,%2E”,以达到修改或者查看数据库内容。
解决方案:
加入过滤器,拦截器等,将危险字符替换。
步骤:1,在web.xml中配置拦截器(过滤器)
2,在,框架的配置文件(如struts.xml)中配置过滤器。
3,书写拦截器(过滤器),使用替换或者正则等方式,过滤掉危险字符。
任务:
解决方案:
在拦截器(过滤器)中,加入
//HTTP 头设置 Referer过滤
Stringreferer = request.getHeader("Referer"); //REFRESH
if(referer!=null&& referer.indexOf(GlobalConstant.SYS_ROOT)<0){
request.getRequestDispatcher(request.getRequestURI()).forward(request,response);
}
任务:
介入统一异常处理页面,防止报错信息中包含有价值的信息被泄漏。
解决方案:
在web.xml中加入异常处理的页面配置。
<!-- 默认的错误处理页面-->
<error-page>
<error-code>403</error-code>
<location>/jsp/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/jsp/error.jsp</location>
</error-page>
<!-- 仅仅在调试的时候注视掉,在正式部署的时候不能注释 -->
<!-- 这样配置也是可以的,表示发生500错误的时候,转到500.jsp页面处理。 -->
<error-page>
<error-code>500</error-code>
<location>/jsp/error.jsp</location>
</error-page>
<!-- 这样的配置表示如果jsp页面或者servlet发生java.lang.Exception类型(当然包含子类)的异常就会转到500.jsp页面处理。 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/jsp/error.jsp</location>
</error-page>
任务:
不要接受外部创建的会话标识。
解决方案:
在控制层加入:
if(request.getSession() != null){
System.out.println("清空session s");
request.getSession().invalidate();//清空session
}
Cookie cookie =request.getCookies()[0];//获取cookie
cookie.setMaxAge(0);//让cookie过期;
因篇幅问题不能全部显示,请点此查看更多更全内容