asp終極防范SQL注入漏洞
更新時間:2011年03月01日 23:17:53 作者:
其實SQL注入漏洞并不可怕,知道原理 + 耐心仔細,就可以徹底防范!
下面給出4個函數(shù),足夠你抵擋一切SQL注入漏洞!讀懂代碼,你就能融會貫通。
注意要對所有的request對象進行過濾:包括 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對象進行過濾:包括 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
您可能感興趣的文章:
- access數(shù)據(jù)庫的一些少用操作,ASP,創(chuàng)建數(shù)據(jù)庫文件,創(chuàng)建表,創(chuàng)建字段,ADOX
- ASP ACCESS 日期操作語句小結(jié) By Stabx
- asp 獲取access系統(tǒng)表,查詢等操作代碼
- Asp 操作Access數(shù)據(jù)庫時出現(xiàn)死鎖.ldb的解決方法
- asp.net(C#) Access 數(shù)據(jù)操作類
- asp實現(xiàn)的查詢某關(guān)鍵詞在MSSQL數(shù)據(jù)庫位置的代碼
- asp 在線備份與恢復sqlserver數(shù)據(jù)庫的代碼
- asp連接mysql數(shù)據(jù)庫詳細實現(xiàn)代碼
- asp連接access、sql數(shù)據(jù)庫代碼及數(shù)據(jù)庫操作代碼
- asp操作access提示無法從指定的數(shù)據(jù)表中刪除原因分析及解決
- ASP中巧用Split()函數(shù)生成SQL查詢語句的實例
- asp執(zhí)行帶參數(shù)的sql語句實例
- ASP 連接 SQL SERVER 2008的方法
- ASP通過ODBC連接SQL Server 2008數(shù)據(jù)庫的方法
- ASP語言實現(xiàn)對SQL SERVER數(shù)據(jù)庫的操作
相關(guān)文章
JavaScript在ASP頁面中實現(xiàn)掩碼文本框效果代碼
在網(wǎng)頁中輸日期、時間、IP地址等需要一定的格式限制,否則將會程序?qū)茈y和程序溝通2012-08-08用asp實現(xiàn)把文件打包成Xml文件包,帶解包的ASP工具附下載
用asp實現(xiàn)把文件打包成Xml文件包,帶解包的ASP工具附下載...2007-06-06從一個網(wǎng)站扒下的asp生成靜態(tài)頁面的代碼 腳本之家特供版
雖然腳本之家以前發(fā)布過相關(guān)的代碼,但一些特別的網(wǎng)站不是很完美,最近幫客戶修改系統(tǒng)發(fā)現(xiàn)了這段代碼,發(fā)現(xiàn)還不錯,特提取出來,方便大家使用。2011-07-07asp實現(xiàn)excel中的數(shù)據(jù)導入數(shù)據(jù)庫
本文給大家匯總介紹了使用asp實現(xiàn)將Excel中數(shù)據(jù)導入到數(shù)據(jù)庫中的方法,需要的朋友可以參考一下2015-09-09Asp Conn.execute的參數(shù)與返回值總結(jié)
這篇文章主要介紹了Asp Conn.execute的參數(shù)與返回值總結(jié),數(shù)據(jù)庫對象的execute方法參數(shù)與返回值總結(jié),需要的朋友可以參考下2014-07-07asp下用replace非正則實現(xiàn)代碼運行功能的代碼
asp下用replace非正則實現(xiàn)代碼運行功能的代碼...2007-09-09