Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1097967
  • 博文数量: 414
  • 博客积分: 10030
  • 博客等级: 上将
  • 技术积分: 4440
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-05 21:42
文章分类

全部博文(414)

文章存档

2011年(1)

2009年(1)

2008年(412)

我的朋友

分类: LINUX

2008-10-10 21:38:54

终极防范SQL注入漏洞

 
   

 
   

终极防范SQL注入漏洞

其实SQL注入漏洞并不可怕,知道原理 + 耐心仔细,就可以彻底防范!

下面给出4个函数,足够你抵挡一切SQL注入漏洞!读懂代码,你就能融会贯通。

注意要对所有的request对象进行过滤:包括 request.cookie, request.ServerVariables 等等容易被忽视的对象:

function killn(byval s1) '过滤数值型参数
if not isnumeric(s1) then
killn=0
else
if s1<0 or s1>2147483647 then
killn=0
else
killn=clng(s1)
end if
end if
end function

function killc(byval s1) 过滤货币型参数
if not isnumeric(s1) then
killc=0
else
killc=formatnumber(s1,2,-1,0,0)
end if
end function

function killw(byval s1) '过滤字符型参数
if len(s1)=0 then
killw=""
else
killw=trim(replace(s1,"'",""))
end if
end function

function killbad(byval s1) 过滤所有危险字符,包括跨站脚本
If len(s1) = 0 then
killbad=""
else
killbad = trim(replace(replace(replace(replace
(replace(replace(replace(replace(s1,Chr(10), "
"),
Chr(34), """), ">", ">"), "<", "<"), "&", "&"),
chr(39),"'"),chr(32)," "),chr(13),""))
end if
end function

阅读(552) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~