Recently, due to modifying an ASP program (which has a SQL injection vulnerability), I found a lot of related prevention methods on the Internet, but none of them were satisfactory. So I comprehensively improved some of the methods on the Internet and wrote this ASP function. For your reference.
Here is a quote:
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('Illegal request!');" 'SQL injection attack prompt message found
Response.Write "location.href='http://blog.downcodes.com/';" 'SQL injection attack redirect URL found
Response.Write "<script>"
Response.end
else
SafeRequest=ParaValue
End If
End function
replaces your Request with the SafeRequest function