新手入门:防范SQL注入攻击的新办法

时间:2008-10-07 12:23:38  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:ue  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(") > ...
  正文:近段时间由于修改一个ASP/ target=_blank class=infotextkey>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

"新手入门:防范SQL注入攻击的新办法"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/ASP/2008-10-07/3508.html


关键字:

关于《新手入门:防范SQL注入攻击的新办法》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td