<%
'----------------------------------------------------------------------
'轉寄時請保留此聲明資訊,這段聲明不並會影響你的速度!
'******************* 塵封防SQL注入 V1.0 ********************************
'作者:塵封 QQ:275171
'電子郵件:275171@qq.com
'網站:http://www.1715.cn http://www.77do.com
'QQ群:13683242(ASP愛好者群)
'此程式測試地址:http://www.77do.com/sql/index.asp
'聲明:在做此防SQL之前,我個人都是使用網上那些的防SQL注入,因為那些防SQL有個共同點,就是屏蔽某一SQL語句需要的關鍵字,前些時間我接了一個國外的程式外包,因此程式的使用者都是些國外使用者,如果使用網上那些SQL注入的話,屏蔽:'|select|update|chr|char等等 字元或單詞,給國外使用者帶了非常大的不便,如 I'm等就無法輸入。因此開發了此防SQL注入。可能程式還不夠完善,希望大家多提提意見,一起來完善此程式。
'使用說明:在資料庫連接頁(如:conn.asp)或你要防注入的頁頭內包含此檔案即可。<!--@include file="CF_Sql.asp"-->(將@改為#)
Dim CFSql_i,CFSql_Sqlchr,CFSql_ChrContent
CFSql_Sqlchr = "select*|and'|or'|insertinto|deletefrom|altertable|update|createtable|createview|dropview|createindex|dropindex|createprocedure|dropprocedure|createtrigger|droptrigger|createschema|dropschema|createdomain|alterdomain|dropdomain|);|select@|declare@|print@|char(|select"
CFSql_Sqlchrs = split(CFSql_Sqlchr,"|")
'======================================================
'Post方式處理
'======================================================
If Request.Form<>"" Then
For Each CFSql_ChrContent In Request.Form
For CFSql_i=0 to Ubound(CFSql_Sqlchrs)
Select Case CFSql_Sqlchrs(CFSql_i)
Case "select"'為避免select的多表關聯查詢
If Instr(LCase(replace(Request.Form(CFSql_ChrContent)," ","")),"select")>0 and Instr(LCase(replace(Request.Form(CFSql_ChrContent)," ","")),"from")>0 Then
Call CFSql_PromptTitle()
End IF
Case "update"'update作額外處理,因update..set..
If Instr(LCase(replace(Request.Form(CFSql_ChrContent)," ","")),"update")>0 and Instr(LCase(replace(Request.Form(CFSql_ChrContent)," ","")),"set")>0 Then
Call CFSql_PromptTitle()
End IF
Case Else
If Instr(LCase(replace(Request.Form(CFSql_ChrContent)," ","")),CFSql_Sqlchrs(CFSql_i))>0 Then
Call CFSql_PromptTitle()
End IF
End Select
Next
Next
End IF
'======================================================
'Get方式處理
'======================================================
If Request.QueryString<>"" Then
For Each CFSql_ChrContent In Request.QueryString
For CFSql_i=0 to Ubound(CFSql_Sqlchrs)
Select Case CFSql_Sqlchrs(CFSql_i)
Case "select"'為避免select的多表關聯查詢
If Instr(LCase(replace(Request.QueryString(CFSql_ChrContent)," ","")),"select")>0 and Instr(LCase(replace(Request.QueryString(CFSql_ChrContent)," ","")),"from")>0 Then
Call CFSql_PromptTitle()
End IF
Case "update"'update作額外處理,因update..set..
If Instr(LCase(replace(Request.QueryString(CFSql_ChrContent)," ","")),"update")>0 and Instr(LCase(replace(Request.QueryString(CFSql_ChrContent)," ","")),"set")>0 Then
Call CFSql_PromptTitle()
End IF
Case Else
If Instr(LCase(replace(Request.QueryString(CFSql_ChrContent)," ","")),CFSql_Sqlchrs(CFSql_i))>0 Then
Call CFSql_PromptTitle()
End IF
End Select
Next
Next
End IF
Sub CFSql_PromptTitle()
Response.Write "<Script Language=JavaScript>alert('SQL通用防注入系統提示你↓/n/n請不要在參數中包含非法字元嘗試注入!/n/nhttp://www.1715.cn/n/http://www.77do.com /n/n系統版本:V1.0(ASP)版 By:塵封');</Script>"
response.Write "<script LANGUAGE='javascript'>history.go(-1);</script>"
response.End()'提示就結束輸出
End Sub%>
另存新檔:CF_Sql.asp檔案就可以了