防ASP注入終極防范
更新時間:2011年11月03日 00:20:22 作者:
其實(shí)SQL注入漏洞并不可怕,知道原理 + 耐心仔細(xì),就可以徹底防范
下面給出4個函數(shù),足夠你抵擋一切SQL注入漏洞!讀懂代碼,你就能融會貫通。
注意要對所有的request對象進(jìn)行過濾:包括 request.cookie, request.ServerVariables 等等容易被忽視的對象:
程序代碼
function killn(byval s1) '過濾數(shù)值型參數(shù)
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) 過濾貨幣型參數(shù)
if not isnumeric(s1) then
killc=0
else
killc=formatnumber(s1,2,-1,0,0)
end if
end function
function killw(byval s1) '過濾字符型參數(shù)
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), "〈br〉"), Chr(34), """), "〉", ">"), "〈", "<"), "&", "&"),chr(39),"'"),chr(32)," "),chr(13),""))
end if
end function
注意要對所有的request對象進(jìn)行過濾:包括 request.cookie, request.ServerVariables 等等容易被忽視的對象:
程序代碼
復(fù)制代碼 代碼如下:
function killn(byval s1) '過濾數(shù)值型參數(shù)
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) 過濾貨幣型參數(shù)
if not isnumeric(s1) then
killc=0
else
killc=formatnumber(s1,2,-1,0,0)
end if
end function
function killw(byval s1) '過濾字符型參數(shù)
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), "〈br〉"), Chr(34), """), "〉", ">"), "〈", "<"), "&", "&"),chr(39),"'"),chr(32)," "),chr(13),""))
end if
end function
相關(guān)文章
動網(wǎng)論壇的asp 數(shù)據(jù)庫連接代碼
動網(wǎng)論壇的asp程序,在一定程度了,成了asp的頂峰之作。高手2009-02-02
解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯誤頁的問題
這篇文章主要介紹了ASP中http狀態(tài)跳轉(zhuǎn)返回錯誤頁的問題的解決方法,感興趣的小伙伴們可以參考一下2015-10-10
解決用Access數(shù)據(jù)庫建站維護(hù)不便的問題的方法
解決用Access數(shù)據(jù)庫建站維護(hù)不便的問題的方法...2007-05-05

