Appscan安全漏扫问题总结
最近解决Appscan安全漏洞扫描软件上的漏洞,遇到不少问题,趁热打铁写个总结。
下面罗列问题类型,截图,以及解决方案。
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。1.SQL盲注
过滤掉字符:' + = and or
public static boolean checkWebUnSafe2sql(String word){ String str=word.replaceAll("'", "").replaceAll("(?i)or", "").replaceAll("(?i)and", "").replaceAll("=", ""); if (word.length()!=str.length()) { return true; } return false; }
注:(?i)代表忽略大小写,即or是Or、oR、OR、or都可以匹配到。
2.跨站点脚本编制
注入的方法很多,最简单的是 alert(123),还有"+eval("ale"+"rt"+"("162")")+",'+eval('ale'+'rt'+'('162')')+', */eval(/ale/.source+/rt/.source+/(451)/.source)///*等等
要彻底解决需要过滤一些js的关键字。
public static boolean checkWebUnSafe2js(String word){ String str=word.replaceAll("<", "").replaceAll(">", "").replaceAll(";", "").replaceAll("(?i)alert", "").replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("(?i)source","").replaceAll("\"+\"","").replaceAll("'+'","") .replaceAll("(?i)window", "").replaceAll("(?i)eval", "").replaceAll("(?i)function", "").replaceAll("(?i)hasOwnProperty", "").replaceAll("(?i)Infinity", "").replaceAll("(?i)isFinite", "").replaceAll("(?i)isNaN", "").replaceAll("(?i)isPrototypeOf", "") .replaceAll("(?i)blur", "").replaceAll("(?i)button", "").replaceAll("(?i)element", "").replaceAll("(?i)event", "").replaceAll("(?i)focus", "").replaceAll("(?i)frame", "").replaceAll("(?i)link", "") .replaceAll("(?i)parseInt", "").replaceAll("(?i)plugin", "").replaceAll("(?i)screenX", "").replaceAll("(?i)screenY", "").replaceAll("(?i)select", ""); if (word.length()!=str.length()) { return true; } return false; }
3.查询中的密码参数
对参数的敏感关键词进行处理,word改为w即可。
4.使用HTTP动词篡改的认证旁路
有该问题的请求走过滤器,在过滤器中加上对请求method判断,防止此类问题的发生。
String method = request.getMethod(); if(!"GET".equalsIgnoreCase(method)&&!"POST".equalsIgnoreCase(method)&&!"HEAD".equalsIgnoreCase(method)) { response.setContentType("text/html;charset=GBK"); response.setCharacterEncoding("GBK"); ((HttpServletResponse) resp).setStatus(403); response.getWriter().print("<font size=6 color=red>对不起,您的请求非法,系统拒绝响应!</font>"); return; }
5.加密会话(SSL)Cookie中缺少Secure属性
有两个方法:第一个方法是项目使用servlet3.0版本,在web.xml里添加secure属性。
第二个方法,简单粗暴,直接让该页面走过滤器,手动加上secure属性。(缺少HttpOnly同理)
if ( url.indexOf("")!=-1){ //""内写请求名 String jSessionId=request.getSession().getId(); if(jSessionId!=null) response.setHeader("Set-Cookie", "JSESSIONID="+jSessionId+";secure;HttpOnly"); }
另外,如何获取所有请求参数
Enumeration em = request.getParameterNames(); while (em.hasMoreElements()) { String name = (String) em.nextElement(); String value = req.getParameter(name);
}

更多精彩