标签:
示例
<tr> <td><spring:message code="lable.field.user.company" /></td> <td>${username}</td> <td></td> </tr>
private static final char[] QUOTE_ENCODE = """.toCharArray(); private static final char[] AMP_ENCODE = "&".toCharArray(); private static final char[] LT_ENCODE = "<".toCharArray(); public static final String escapeForHtml(String string) { if (string == null) { return null; } char ch; int i = 0; int last = 0; char[] input = string.toCharArray(); int len = input.length; StringBuffer out = new StringBuffer((int) (len * 1.3)); for (; i < len; i++) { ch = input[i]; if (ch > '>') { continue; } else if (ch == '<') { if (i > last) { out.append(input, last, i - last); } last = i + 1; out.append(LT_ENCODE); } else if (ch == '"') { if (i > last) { out.append(input, last, i - last); } last = i + 1; out.append(QUOTE_ENCODE); } } if (last == 0) { return string; } if (i > last) { out.append(input, last, i - last); } return out.toString(); }
用户资料被修改,攻击者以用户身份执行任意操作
CSRF 攻击主要是由攻击者在网页中植入恶意代码或连接,当受害人的浏览器执行恶意代码或者受害人点击连接后,攻击者就可以访问那些被害人身份验证后的网络应用。如果被害人采用多窗口浏览器,攻击者就可以以被害人身份控制浏览器中任何一个窗口中的Web应用。
用户被钓鱼,帐号密码被盗
response.sendRedirect(request.getParameter("done"));
public boolean sendRedirect(String url) { if (!StringUtil.isEmpty(url)) { try { url = url.trim(); if (!WHITE_DOMAIN_PATTERN.matcher(url).matches()) { url = "http://www.dxy.cn/redirect?url=" + URLEncoder.encode(url, "UTF-8"); } res.sendRedirect(url); return true; } catch (Throwable ex) { } } return false; } private static Pattern WHITE_DOMAIN_PATTERN = null; static { StringBuilder buff = new StringBuilder(); for (String domain : new String[] { “abc\\.(cn|com|net)", “aaa\\.cn", “bbb\\.(cn|com)", “ccc\\.cn" }) { if (buff.length() > 0) { buff.append("|"); } buff.append("(^http[s]?://[\\w-]+\\."); buff.append(domain); buff.append("(\\/.*)?$)"); } buff.append("|(^(?!http).+$)"); WHITE_DOMAIN_PATTERN = Pattern.compile(buff.toString(), Pattern.CASE_INSENSITIVE); }
服务器被黑客控制
攻击者通过附件上传漏洞,上传可执行脚本,从而控制服务器。
标签:
原文地址:http://blog.csdn.net/wenniuwuren/article/details/50768900