解讀ASP程序中通用防SQL注入攻擊代碼_ASP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:用紅色顯示ASP查詢數(shù)據(jù)時(shí)得到的記錄關(guān)鍵詞% response.write replace(rs(字段X),searchname,font color=#FF0000 searchname /font) % 說(shuō)明:rs為記錄集對(duì)象,searchname為搜索的關(guān)鍵詞 轉(zhuǎn)載自HTMer[http://www.htmer.com/]
SQL注入一般的http請(qǐng)求不外乎get和post,所以只要我們?cè)谖募羞^(guò)濾所有post或者get請(qǐng)求中的參數(shù)信息中非法字符,就可以防SQL注入攻擊。IIS傳遞給asp.dll的get請(qǐng)求是以字符串的形式,當(dāng)傳遞給Request.QueryString數(shù)據(jù)后,asp解析器會(huì)分析Request.QueryString的信息,然后根據(jù)"&",分出各個(gè)數(shù)組內(nèi)的數(shù)據(jù)。下面分別列出get攔截和post攔截的代碼:
'======get攔截======
dim sql_injdata
SQL_injdata = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
SQL_inj = split(SQL_Injdata,"|")
If Request.QueryString<>"" Then
For Each SQL_Get In Request.QueryString
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then
Response.Write "<Script Language='javascript'>alert('HTMer.com系統(tǒng)提示↓nn請(qǐng)不要在參數(shù)中包含非法字符嘗試注入!nnHTTP://www.htmer.com');history.back(-1)</Script>"
Response.end
end if
next
next
end If
dim sql_injdata
SQL_injdata = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
SQL_inj = split(SQL_Injdata,"|")
If Request.QueryString<>"" Then
For Each SQL_Get In Request.QueryString
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then
Response.Write "<Script Language='javascript'>alert('HTMer.com系統(tǒng)提示↓nn請(qǐng)不要在參數(shù)中包含非法字符嘗試注入!nnHTTP://www.htmer.com');history.back(-1)</Script>"
Response.end
end if
next
next
end If
'======post攔截======
If Request.Form<>"" Then
For Each Sql_Post In Request.Form
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))>0 Then
Response.Write "<Script Language='javascript'>alert('HTMer.com系統(tǒng)提示↓nn請(qǐng)不要在參數(shù)中包含非法字符嘗試注入!nnHTTP://www.htmer.com');history.back(-1)</Script>"
Response.end
end if
next
next
end if
If Request.Form<>"" Then
For Each Sql_Post In Request.Form
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))>0 Then
Response.Write "<Script Language='javascript'>alert('HTMer.com系統(tǒng)提示↓nn請(qǐng)不要在參數(shù)中包含非法字符嘗試注入!nnHTTP://www.htmer.com');history.back(-1)</Script>"
Response.end
end if
next
next
end if
好了,我們已經(jīng)實(shí)現(xiàn)了get和post請(qǐng)求的信息攔截,你只需要在conn.asp之類的打開(kāi)數(shù)據(jù)庫(kù)文件之前引用這個(gè)頁(yè)面即可。
分享:在asp程序中過(guò)濾不文明字符的函數(shù)% Functioncutbadchar(str) badstr=不|文|明|字|符|列|表|格|式’此處填寫(xiě)不文明的詞語(yǔ),用|分開(kāi) badword=split(badstr,|) Fori=0toUbound(badword) Ifinstr(str,badword(i))0then str=Replace(str,badword(i),***) EndIf Next cutbadchar=str EndFunct
相關(guān)ASP教程:
- asp FSO 讀寫(xiě)文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-解讀ASP程序中通用防SQL注入攻擊代碼
。