public static string FilterSpecial(string text)
{
if (text == "")
{
return text;
}
else
{
text = text.Replace("'", "");
text = text.Replace("<", "");
text = text.Replace(">", "");
text = text.Replace("%", "");
text = text.Replace("'delete", "");
text = text.Replace("''", "");
text = text.Replace("\"\"", "");
text = text.Replace(",", "");
text = text.Replace(".", "");
text = text.Replace(">=", "");
text = text.Replace("=<", "");
text = text.Replace("-", "");
text = text.Replace("_", "");
text = text.Replace(";", "");
text = text.Replace("||", "");
text = text.Replace("[", "");
text = text.Replace("]", "");
text = text.Replace("&", "");
text = text.Replace("#", "");
text = text.Replace("/", "");
text = text.Replace("-", "");
text = text.Replace("|", "");
text = text.Replace("?", "");
text = text.Replace(">?", "");
text = text.Replace("?<", "");
text = text.Replace(" ", "");
return text;
}
}
public static string FilterSQLStr(string text)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
text = Regex.Replace(text, "[\\s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br>
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); //
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags
text = text.Replace("'", "''");
text = text.Replace("xp_cmdshell", "");
text = text.Replace("exec master.dbo.xp_cmdshell", "");
text = text.Replace("net localgroup administrators", "");
text = text.Replace("delete from", "");
text = text.Replace("net user", "");
text = text.Replace("/add", "");
text = text.Replace("drop table", "");
text = text.Replace("update", "");
return text;
}
SQL防注入方法
最新推荐文章于 2023-09-05 12:44:54 发布