.NET防止用户恶意输入
2011-12-06 11:18
162 查看
/// <summary>
/// 该方法用来检测用户输入是否带有恶意
/// </summary>
/// <param name="text">用户输入的文字</param>
/// <param name="maxlength">最大的长度</param>
/// <returns>返回验证后的文字</returns>
public static string InputText(string text, int maxlength)
{
text = text.ToLower().Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxlength)
text = text.Substring(0, maxlength);
text = Regex.Replace(text, "[\\s]{2,{", " ");
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 = Regex.Replace(text,"=", "");
text = Regex.Replace(text, "%", "");
text = Regex.Replace(text, "'", "");
text = Regex.Replace(text, "select", "");
text = Regex.Replace(text, "insert", "");
text = Regex.Replace(text, "delete", "");
text = Regex.Replace(text, "or", "");
text = Regex.Replace(text, "exec", "");
text = Regex.Replace(text, "--", "");
text = Regex.Replace(text, "and", "");
text = Regex.Replace(text, "where", "");
text = Regex.Replace(text, "update", "");
text = Regex.Replace(text, "script", "");
text = Regex.Replace(text, "iframe", "");
text = Regex.Replace(text, "master", "");
text = Regex.Replace(text, "exec", "");
text = Regex.Replace(text, "<", "");
text = Regex.Replace(text, ">", "");
text = Regex.Replace(text, "\r\n", "");
return text;
}
来源于:www.hackbadboy.com B.B.S.T 信息安全团队 BadBoy网络安全小组
/// 该方法用来检测用户输入是否带有恶意
/// </summary>
/// <param name="text">用户输入的文字</param>
/// <param name="maxlength">最大的长度</param>
/// <returns>返回验证后的文字</returns>
public static string InputText(string text, int maxlength)
{
text = text.ToLower().Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxlength)
text = text.Substring(0, maxlength);
text = Regex.Replace(text, "[\\s]{2,{", " ");
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 = Regex.Replace(text,"=", "");
text = Regex.Replace(text, "%", "");
text = Regex.Replace(text, "'", "");
text = Regex.Replace(text, "select", "");
text = Regex.Replace(text, "insert", "");
text = Regex.Replace(text, "delete", "");
text = Regex.Replace(text, "or", "");
text = Regex.Replace(text, "exec", "");
text = Regex.Replace(text, "--", "");
text = Regex.Replace(text, "and", "");
text = Regex.Replace(text, "where", "");
text = Regex.Replace(text, "update", "");
text = Regex.Replace(text, "script", "");
text = Regex.Replace(text, "iframe", "");
text = Regex.Replace(text, "master", "");
text = Regex.Replace(text, "exec", "");
text = Regex.Replace(text, "<", "");
text = Regex.Replace(text, ">", "");
text = Regex.Replace(text, "\r\n", "");
return text;
}
来源于:www.hackbadboy.com B.B.S.T 信息安全团队 BadBoy网络安全小组
相关文章推荐
- .NET防止用户恶意输入
- 防止用户恶意输入信息
- 防止用户恶意输入信息
- 防止用户恶意输入信息
- 防止用户恶意刷新过滤器
- 防止用户直接输入地址访问jsp文件
- 心得3--表单提交时防止用户不小心提交多次及有人恶意提交案例分析
- 设置GRUB密码以防止单用户模式下root密码被恶意更改
- 心得3--表单提交时防止用户不小心提交多次及有人恶意提交案例分析
- 如何防止用户输入 ComboBox 控件数据源列表中不存在的值
- 心得3--表单提交时防止用户不小心提交多次及有人恶意提交案例分析
- 防止用户不登陆直接输入网址访问页面
- 防止用户提交的表单内容里可能会写入一些恶意的代码
- 防止用户恶意刷新过滤器
- 防止恶意字符输入
- .net防止同一用户登陆
- 防止浏览器默认记录用户输入值
- 用户的访问权限过滤器,防止用户直接输入URL直接访问资源。
- 登陆模块防止恶意用户SQL注入攻击
- 拒绝远程修改win8注册表键值防止恶意用户攻击win8