站在技術的頂端,才能看清腳下的路該通向何方--技術工程師之路!
<%
'================================================================================================================
dim conn
dim connstr
dim db
db="data/da.mdb" '資料庫檔案位置
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
'On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.commandtimeout=20
conn.open ConnStr
'If Err Then
'err.Clear
'Set Conn = Nothing
'Response.Write "<br><br><br><br><br><br><br><div align='center'>資料庫連接出錯!請檢查連線資料庫的引數及字串設定是否正確!</div>"
'Response.End
'End If
'-----------------------------------------------------------------------------------------------------
'-----------------------------------------------------------------------------------------------------
'為了系統的安全,直接在有資料庫連線的地方都加上SQL注入的免疫
'自定義需要過濾的字串,用 "|" 分隔
Fy_In = "'| ; | and | or | exec | insert | select | delete | update | count | * | % |chr(| char(| mid | master | truncate | declare "
'----------------------------------
Fy_Inf = split(Fy_In,"|")
If Request.QueryString<>"" Then
For Each Fy_Get In Request.QueryString
For Fy_Xh=0 To Ubound(Fy_Inf)
If Instr(LCase(Request.QueryString(Fy_Get)),Fy_Inf(Fy_Xh))<>0 Then
'--------寫入資料庫----------頭-----
conn.Execute("insert into web_errlog(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','GET','"&Fy_Get&"','"&replace(Request.QueryString(Fy_Get),"'","''")&"')")
'--------寫入資料庫----------尾-----
response.redirect("/Error.html")
response.end
End If
Next
Next
End If
'=======================================================
'
Function changechr(fString)
If Not IsNull(fString) Then
fString = trim(fString)
'fString = replace(fString, ";", ";") '分號過濾
fString = replace(fString, "--", "——") '--過濾
fString = replace(fString, "%20", "") '特殊字元過濾
fString = replace(fString, "==", "") '==過濾
'fString = replace(fString, ">", ">")
'fString = replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ") '
fString = Replace(fString, CHR(9), " ") '
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'") '單引號過濾
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
changechr = fString
End If
End Function
%>