从别的地方看到的一个防注入函数
2007-03-17 13:09
309 查看
这个函数还是比较全面的,先判断字符串,再过滤特殊字符
不过我认为防御最好的办法就是用数字传入再转换类型
function sqlcheck(Str)
if Instr(LCase(Str),"select ") > 0 or Instr(LCase(Str),"insert ") > 0 or Instr(LCase(Str),"delete ") > 0 or Instr(LCase(Str),"delete from ") > 0 or Instr(LCase(Str),"count(") > 0 or Instr(LCase(Str),"drop table") > 0 or Instr(LCase(Str),"update ") > 0 or Instr(LCase(Str),"truncate ") > 0 or Instr(LCase(Str),"asc(") > 0 or Instr(LCase(Str),"mid(") > 0 or Instr(LCase(Str),"char(") > 0 or Instr(LCase(Str),"xp_cmdshell") > 0 or Instr(LCase(Str),"exec master") > 0 or Instr(LCase(Str),"net localgroup administrators") > 0 or Instr(LCase(Str),"and ") > 0 or Instr(LCase(Str),"net user") > 0 or Instr(LCase(Str),"or ") > 0 then
Call Qcdn.Err_List("请不要在参数中包含非法字符尝试注入!",1)
Response.End
exit function
end if
Str=Replace(Str,"_","") '过滤SQL注入_
Str=Replace(Str,"*","") '过滤SQL注入*
Str=Replace(Str," ","") '过滤SQL注入空格
Str=Replace(Str,chr(34),"") '过滤SQL注入"
Str=Replace(Str,chr(39),"")'过滤SQL注入'
Str=Replace(Str,chr(91),"")'过滤SQL注入[
Str=Replace(Str,chr(93),"")'过滤SQL注入]
Str=Replace(Str,chr(37),"")'过滤SQL注入%
Str=Replace(Str,chr(58),"")'过滤SQL注入:
Str=Replace(Str,chr(59),"")'过滤SQL注入;
Str=Replace(Str,chr(43),"")'过滤SQL注入+
Str=Replace(Str,"{","")'过滤SQL注入{
Str=Replace(Str,"}","")'过滤SQL注入}
sqlcheck=Str'返回经过上面字符替换后的Str
end function
不过我认为防御最好的办法就是用数字传入再转换类型
function sqlcheck(Str)
if Instr(LCase(Str),"select ") > 0 or Instr(LCase(Str),"insert ") > 0 or Instr(LCase(Str),"delete ") > 0 or Instr(LCase(Str),"delete from ") > 0 or Instr(LCase(Str),"count(") > 0 or Instr(LCase(Str),"drop table") > 0 or Instr(LCase(Str),"update ") > 0 or Instr(LCase(Str),"truncate ") > 0 or Instr(LCase(Str),"asc(") > 0 or Instr(LCase(Str),"mid(") > 0 or Instr(LCase(Str),"char(") > 0 or Instr(LCase(Str),"xp_cmdshell") > 0 or Instr(LCase(Str),"exec master") > 0 or Instr(LCase(Str),"net localgroup administrators") > 0 or Instr(LCase(Str),"and ") > 0 or Instr(LCase(Str),"net user") > 0 or Instr(LCase(Str),"or ") > 0 then
Call Qcdn.Err_List("请不要在参数中包含非法字符尝试注入!",1)
Response.End
exit function
end if
Str=Replace(Str,"_","") '过滤SQL注入_
Str=Replace(Str,"*","") '过滤SQL注入*
Str=Replace(Str," ","") '过滤SQL注入空格
Str=Replace(Str,chr(34),"") '过滤SQL注入"
Str=Replace(Str,chr(39),"")'过滤SQL注入'
Str=Replace(Str,chr(91),"")'过滤SQL注入[
Str=Replace(Str,chr(93),"")'过滤SQL注入]
Str=Replace(Str,chr(37),"")'过滤SQL注入%
Str=Replace(Str,chr(58),"")'过滤SQL注入:
Str=Replace(Str,chr(59),"")'过滤SQL注入;
Str=Replace(Str,chr(43),"")'过滤SQL注入+
Str=Replace(Str,"{","")'过滤SQL注入{
Str=Replace(Str,"}","")'过滤SQL注入}
sqlcheck=Str'返回经过上面字符替换后的Str
end function
相关文章推荐
- 一个自己实现的strstr 字符串查找函数,大家看看有什么错误和改进的地方
- 刚刚在看52单片机和GPS通信程序的时候,看到了一个函数,absacc.h,貌似从来没有遇到过,百度了一下,结合自己的理解,整理如下: http://blog.sina.com.cn/s/blog_4
- jquery 多个地方引用一个函数(id只能唯一 class可以重复)
- 网上看到一个提供WebService的地方,如果作webService测试,不妨试试
- AngularJS权威教程 笔记(AngularJS是一个很有意思的库,基于函数形参的依赖注入?酷!还有奇怪的$scope和指令)
- 一个完整的DLL远程注入函数
- 一个完整的DLL远程注入函数
- 这是我在逛一个微波论坛的时候看到的一些帖子里面对HFSS仿真的一些问题的解决方法,不一定正确,有不对的地方希望指出,我改正!
- 一个完整的DLL远程注入函数
- 一个asp放注入函数
- 写正确函数需要注意的地方:给定一个十进制整数N,计算从1开始到N的所有整数出现的“1”的个数
- 智能指针变量做函数参数的一个值得注意的地方
- CreateIpForwardEntry函数在VIsta/win2008下需要注意的一个地方
- 在网上看到了一个面试题感觉很有意思 写一个函数,实现字符串反转
- 一道看到的面试题 [写一个函数,比较2个整数大小,但不是用任何比较操作符]
- 智能指针变量做函数参数的一个值得注意的地方
- struts2+spring中注入的一个要注意的地方
- 当函数发现字符串中如果有一个地方由一个或多个连续的空格组成,就把它们改成单个空格字符。
- AngularJS权威教程 笔记(AngularJS是一个很有意思的库,基于函数形参的依赖注入?酷!还有奇怪的$scope和指令)
- 写一个函数应注意的地方