当前位置:开发者网络 >> 技术教程 >> ASP教程 >> 数据库相关 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
关于SQL注入防御函数
作者:未知
日期:2004-08-10
人气:
投稿:xiaxia(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
刚刚在最爱白菜那里看到了一个SQL注入防御的函数,突然想起以前看到这些文章时的一直有个问题想不通的,我对于SQL注入的防御很简单,就以下两个函数:

'####
'##
'## SQL注入攻击预防装置[字符型]
'##
'## @ data ->处理的数据
'## @ length ->长度限制
'##
'## 例: strSql("SQL字符型数据",50)
'##
function strSql(data,length)
'########################################################################
if length<>0 then data=left(data,length)
strSql="'"&replace(data,"'","''")&"'"
end function

'####
'##
'## SQL注入攻击预防装置[数字型]
'##
'## @ numeric ->数字
'##
'## 例: intSql(50)
'##
'## 2004/03/04,改良版,原因:IsNumeric检测MSSQL数据类型时会误判。
'##
function intSql(Numeric)
'########################################################################
dim MM_intTemp
On Error Resume Next
if Numeric="" then Numeric=0
MM_intTemp=csng(Numeric)
if err=0 then
intSql=Numeric
else
intSql=0
end if
end function

strSQL的length不在防御SQL注入的范围中,是我为了防止插入字符超过字段长度而出错作的一个小小的防御。
我在网上看到各式各样的SQL注入防御函数,所以很好奇,这样的函数不能防御注入吗?谁知道这两个函数的漏洞请告诉我。

相关文章: