剛剛在最愛白菜那裡看到了一個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注入防禦函數,所以很好奇,這樣的函數不能防禦注入嗎?誰知道這兩個函數的漏洞請告訴我。