近日筆者的小站遭受到SQL入侵,于是上網(wǎng)搜索了一些相關(guān)防SQL注入的方法。下面是一個通用的ASP網(wǎng)頁防SQL注入的代碼,個人感覺不錯。
用法:將上述代碼放入conn文件中即可,功能較全面……
以下是代碼片段: <% Dim GetFlag Rem(提交方式) Dim ErrorSql Rem(非法字符) Dim RequestKey Rem(提交數(shù)據(jù)) Dim ForI Rem(循環(huán)標(biāo)記) ErrorSql = "'~;~and~(~)~exec~update~count~*~%~chr~mid~master~truncate~char~declare" Rem(每個敏感字符或者詞語請使用半角 "~" 格開) ErrorSql = split(ErrorSql,"~") If Request.ServerVariables("REQUEST_METHOD")="GET" Then GetFlag=True Else GetFlag=False End If If GetFlag Then For Each RequestKey In Request.QueryString For ForI=0 To Ubound(ErrorSql) If Instr(LCase(Request.QueryString(RequestKey)),ErrorSql(ForI))<>0 Then response.write "<script>alert(""警告:\n請不要做任何嘗試"");location.href=""index.asp"";</script>" Response.End End If Next Next Else For Each RequestKey In Request.Form For ForI=0 To Ubound(ErrorSql) If Instr(LCase(Request.Form(RequestKey)),ErrorSql(ForI))<>0 Then response.write "<script>alert(""警告:\n請不要做任何嘗試"");location.href=""index.asp"";</script>" Response.End End If Next Next End If %> |
留言反饋