asp.net core2 mvc 基础教程-- XSS & CSRF
2021-01-20 21:15
标签:substr bcd agent == null color ase red name 首先新建一个Xss处理的帮助类 asp.net core2 mvc 基础教程-- XSS & CSRF 标签:substr bcd agent == null color ase red name 原文地址:https://www.cnblogs.com/cqqinjie/p/13303046.html public static class XSSHelper
{
///
///
//:a&_#X6Cert('XSS')>
string chars = "abcdefghijklmnopqrstuvwxyz"+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"+
"!@#$%^&*()~`;:?+/={}[]-_|‘\"\\";
for (int i = 0; i )
{
ret =
System.Text.RegularExpressions.Regex.Replace(ret,
string.Concat("([x|X]0{0,}",
Convert.ToString((int)chars[i], 16).ToLower(),
";?)"),
chars[i].ToString(),
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
//过滤\t, \n, \r构建的恶意代码
string[] keywords = {"javascript", "vbscript", "expression",
"applet", "meta", "xml", "blink", "link", "style",
"script", "embed", "object", "iframe", "frame",
"frameset", "ilayer", "layer", "bgsound", "title",
"base" ,"onabort", "onactivate", "onafterprint",
"onafterupdate", "onbeforeactivate", "onbeforecopy",
"onbeforecut", "onbeforedeactivate", "onbeforeeditfocus",
"onbeforepaste", "onbeforeprint", "onbeforeunload",
"onbeforeupdate", "onblur", "onbounce", "oncellchange",
"onchange", "onclick", "oncontextmenu", "oncontrolselect",
"oncopy", "oncut", "ondataavailable", "ondatasetchanged",
"ondatasetcomplete", "ondblclick", "ondeactivate",
"ondrag", "ondragend", "ondragenter", "ondragleave",
"ondragover", "ondragstart", "ondrop", "onerror",
"onerrorupdate", "onfilterchange", "onfinish",
"onfocus", "onfocusin", "onfocusout", "onhelp",
"onkeydown", "onkeypress", "onkeyup", "onlayoutcomplete",
"onload", "onlosecapture", "onmousedown", "onmouseenter",
"onmouseleave", "onmousemove", "onmouseout", "onmouseover",
"onmouseup", "onmousewheel", "onmove", "onmoveend",
"onmovestart", "onpaste", "onpropertychange",
"onreadystatechange", "onreset", "onresize",
"onresizeend", "onresizestart", "onrowenter",
"onrowexit", "onrowsdelete", "onrowsinserted",
"onscroll", "onselect", "onselectionchange",
"onselectstart", "onstart", "onstop", "onsubmit",
"onunload"};
bool found = true;
while (found)
{
string retBefore = ret;
for (int i = 0; i )
{
string pattern = "/";
for (int j = 0; j )
{
if (j > 0)
pattern = string.Concat(pattern,
‘(‘, "([x|X]0{0,8}([9][a][b]);?)?",
"|({0,8}([9][10][13]);?)?",
")?");
pattern = string.Concat(pattern, keywords[i][j]);
}
string replacement =
string.Concat(keywords[i].Substring(0, 2),
"<x>", keywords[i].Substring(2));
ret =
System.Text.RegularExpressions.Regex.Replace(ret,
pattern, replacement,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (ret == retBefore)
found = false;
}
}
return ret;
}
文章标题:asp.net core2 mvc 基础教程-- XSS & CSRF
文章链接:http://soscw.com/index.php/essay/44714.html