防ASP注入終極防范
更新時(shí)間:2011年11月03日 00:20:22 作者:
其實(shí)SQL注入漏洞并不可怕,知道原理 + 耐心仔細(xì),就可以徹底防范
下面給出4個(gè)函數(shù),足夠你抵擋一切SQL注入漏洞!讀懂代碼,你就能融會(huì)貫通。
注意要對(duì)所有的request對(duì)象進(jìn)行過(guò)濾:包括 request.cookie, request.ServerVariables 等等容易被忽視的對(duì)象:
程序代碼
function killn(byval s1) '過(guò)濾數(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) 過(guò)濾貨幣型參數(shù)
if not isnumeric(s1) then
killc=0
else
killc=formatnumber(s1,2,-1,0,0)
end if
end function
function killw(byval s1) '過(guò)濾字符型參數(shù)
if len(s1)=0 then
killw=""
else
killw=trim(replace(s1,"'",""))
end if
end function
function killbad(byval s1) 過(guò)濾所有危險(xiǎn)字符,包括跨站腳本
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
注意要對(duì)所有的request對(duì)象進(jìn)行過(guò)濾:包括 request.cookie, request.ServerVariables 等等容易被忽視的對(duì)象:
程序代碼
復(fù)制代碼 代碼如下:
function killn(byval s1) '過(guò)濾數(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) 過(guò)濾貨幣型參數(shù)
if not isnumeric(s1) then
killc=0
else
killc=formatnumber(s1,2,-1,0,0)
end if
end function
function killw(byval s1) '過(guò)濾字符型參數(shù)
if len(s1)=0 then
killw=""
else
killw=trim(replace(s1,"'",""))
end if
end function
function killbad(byval s1) 過(guò)濾所有危險(xiǎn)字符,包括跨站腳本
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)文章
ASP 支持中文的len(),left(),right()的函數(shù)代碼
在用ASP處理文字時(shí)。系統(tǒng)自帶的字符串長(zhǎng)度檢測(cè)函數(shù)有時(shí)候也不是很好用。2010-05-05ASP:ActiveX不能創(chuàng)建Scripting.FileSystemObject對(duì)象解決辦法
關(guān)于ActiveX不能創(chuàng)建Scripting.FileSystemObject對(duì)象的類(lèi)似問(wèn)題,大體上解決辦法都是類(lèi)似的,主要是思想要清晰:首先考慮組件注冊(cè)問(wèn)題,其次是組件權(quán)限問(wèn)題,如果服務(wù)器配置沒(méi)有問(wèn)題的話(huà),那就仔細(xì)檢查一下你的程序源碼吧2011-11-11ASP中實(shí)現(xiàn)限制IP的函數(shù)詳解
ASP中實(shí)現(xiàn)限制IP的函數(shù)詳解...2007-04-04asp 驗(yàn)證輸入網(wǎng)址是否有效并可以訪問(wèn) 與正則驗(yàn)證輸入網(wǎng)址
這篇文章主要是驗(yàn)證用戶(hù)輸入的字符是否是網(wǎng)址的方法,需要的朋友可以參考一下2007-08-08從一個(gè)網(wǎng)站扒下的asp生成靜態(tài)頁(yè)面的代碼 腳本之家特供版
雖然腳本之家以前發(fā)布過(guò)相關(guān)的代碼,但一些特別的網(wǎng)站不是很完美,最近幫客戶(hù)修改系統(tǒng)發(fā)現(xiàn)了這段代碼,發(fā)現(xiàn)還不錯(cuò),特提取出來(lái),方便大家使用。2011-07-07