近段時間由於修改一個asp程序(有SQL注入漏洞),在網上找了很多相關的一些防范辦法,都不近人意,所以我將現在網上的一些方法綜合改良了一下,寫出這個ASP函數,供大家參考。
以下是引用片段:
Function SafeRequest(ParaName)
Dim ParaValue
ParaValue=Request(ParaName)
if IsNumeric(ParaValue) = True then
SafeRequest=ParaValue
exit Function
elseIf Instr(LCase(ParaValue),"select ") > 0 or Instr(LCase(ParaValue),"insert ") > 0 or Instr(LCase(ParaValue),"delete from") > 0 or Instr(LCase(ParaValue),"count(") > 0 or Instr(LCase(ParaValue),"drop table") > 0 or Instr(LCase(ParaValue),"update ") > 0 or Instr(LCase(ParaValue),"truncate ") > 0 or Instr(LCase(ParaValue),"asc(") > 0 or Instr(LCase(ParaValue),"mid(") > 0 or Instr(LCase(ParaValue),"char(") > 0 or Instr(LCase(ParaValue),"xp_cmdshell") > 0 or Instr(LCase(ParaValue),"exec master") > 0 or Instr(LCase(ParaValue),"net localgroup administrators") > 0 or Instr(LCase(ParaValue)," and ") > 0 or Instr(LCase(ParaValue),"net user") > 0 or Instr(LCase(ParaValue)," or ") > 0 then
Response.Write "<script language='Javascript'>"
Response.Write "alert('非法的請求!');" '發現SQL注入攻擊提示信息
Response.Write "location.href='http://blog.knowsky.com/';" '發現SQL注入攻擊轉跳網址
Response.Write "<script>"
Response.end
else
SafeRequest=ParaValue
End If
End function
使用SafeRequest函數替換你的Request