標籤:
方法1: Replace過濾字元
解決方案:尋找login.asp下的<from找到下邊的類似username=request.Form(”name”)
pass=request.Form(”pass”)
修改為:username=Replace(request.Form(”name”), “’”, “’’”)
pass=Replace(request.Form(”pass”), “’”, “’’”)
文法是屏蔽’和’’字元來達到效果.
方法2:在conn.asp 內引入safe.asp檔案
注意:前提是登陸頁面有引入conn.asp檔案
把以下代碼儲存為safe.asp
程式碼
<%
Dim Query_Badword,Form_Badword,i,Err_Message,Err_Web,name
Err_Message = 3
Err_Web = “safe.htm”
’出錯時轉向的頁面
Query_Badword=”’|and|select|update|chr|delete|%20from|;|insert|mid|master.|set|chr(37)|=”
’在這部份定義get非法參數,使用”|”號間隔
Form_Badword=”’|(|)|;|=”
’在這部份定義post非法參數,使用”|”號間隔
On Error Resume Next
if request.QueryString”" then
Chk_badword=split(Query_Badword,”|”)
FOR EACH Query_Name IN Request.QueryString
for i=0 to ubound(Chk_badword)
If Instr(LCase(request.QueryString(Query_Name)),Chk_badword(i))0 Then
Select Case Err_Message
Case “1″
Response.Write “alert(’傳參錯誤!參數 “&name&” 的值中包含非法字串! 請不要在參數中出現:and update delete ; insert mid master 等非法字元!’);window.close();”
Case “2″
Response.Write “location.href=’”&Err_Web&”’”
Case “3″
Response.Write “alert(’傳參錯誤!參數 “&name&”的值中包含非法字串! 請不要在參數中出現:and update delete ; insert mid master 等非法字元!’);location.href=’”&Err_Web&”’;”
End Select
Response.End
End If
NEXT
NEXT
End if
if request.form”" then
Chk_badword=split(Form_Badword,”|”)
FOR EACH name IN Request.Form
for i=0 to ubound(Chk_badword)
If Instr(LCase(request.form(name)),Chk_badword(i))0 Then
Select Case Err_Message
Case “1″
Response.Write “alert(’出錯了!表單 “&name&” 的值中包含非法字串! 你的非法操作已記錄,請馬上停止非法行為!’);window.close();”
Case “2″
Response.Write “location.href=’”&Err_Web&”’”
Case “3″
Response.Write “alert(’出錯了!參數 “&name&”的值中包含非法字串! 謝謝您光臨!,請停止非法行為!’);location.href=’”&Err_Web&”’;”
End Select
Response.End
End If
NEXT
NEXT
end if
%>
案例:http://www.wooyun.org/bugs/wooyun-2010-024354
大學站防SQL注入代碼(ASP版)