C# 检查字符串,防SQL注入攻击
来源:互联网 发布:pc客户端软件开发 编辑:程序博客网 时间:2024/06/07 18:54
这些天,CSDN上讨论SQL注入攻击似乎是如火如荼啊...我也来参合一下..如下,CheckParams函数,接收参数任意,如参数中有字符串,则对字符串进行检查,如参数中有集合(如Array之类,总之是实现了ICollection的),则对集合中的字符串元素进行检查.大家可根据具体情况来定要过滤的字符,我这个例子里暂定为=号和'号,实际上我个人认为,过滤了这两个,似乎要进行SQL注入就已经比较困难了,当然,我对SQL是菜鸟,欢迎高手指正,谢谢.我的邮箱(MSN): Appledotnet@hotmail.com
bool CheckParams(params object[] args)
{ string[] Lawlesses={"=","'"};
if(Lawlesses==null||Lawlesses.Length<=0)return true; //构造正则表达式,
例:Lawlesses是=号和'号,则正则表达式为 .*[=}'].* (正则表达式相关内容请见MSDN) 另外,由于我是想做通用而且容易修改的函数,所以多了一步由字符数组到正则表达式,实际使用中,直接写正则表达式亦可;
string str_Regex=".*[";
for(int i=0;i< Lawlesses.Length-1;i++)
str_Regex+=Lawlesses[i]+"|";
str_Regex+=Lawlesses[Lawlesses.Length-1]+"].*";
// foreach(object arg in args)
{ if(arg is string)//如果是字符串,直接检查
{ if(Regex.Matches(arg.ToString(),str_Regex).Count>0)
return false; }
else if(arg is ICollection)//如果是一个集合,则检查集合内元素是否字符串,是字符串,就进行检查 { foreach(object obj in (ICollection)arg)
{ if(obj is string)
{ if(Regex.Matches(obj.ToString(),str_Regex).Count>0)
return false;
}
}
}
}
return true;}
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C#检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- C# 检查字符串,防SQL注入攻击
- 防SQL注入攻击
- JSP防SQL注入攻击
- SQL 防注入式攻击
- 防SQL注入式攻击
- 天晨设计整站SQL注入漏洞
- Linux 内存管理 -- 高端内存的映射方式
- 浅谈sql注入式(SQL injection)攻击与防范
- 用vbs来写sql注入等80端口的攻击脚本
- Linux initrd的分析、创建和使用(转)
- C# 检查字符串,防SQL注入攻击
- 关于对SQL注入80004005 及其它错误消息分析
- SQL注入入侵动网SQL版论坛
- 利用SQL注入2分钟入侵网站全程实录
- 三步堵死SQL注入漏洞
- SQL注入专题
- 候捷谈Java反射机制
- asp汉语拼音函数
- 我的C# asp.net 学习笔记