Asp教程

通过asp实例结合结合ACCESS,MSSQL来更好的深入Asp学习 - 爬坡者

« ASP六大对象常用语句示范SQL注入原理,值得一看! »

[转]防范SQL注入攻击的新办法

近段时间由于修改一个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://dev.yesky.com/';"  '发现SQL注入攻击转跳网址 
 Response.Write "<script>" 
 Response.end 
else 
SafeRequest=ParaValue 
End If 
End function 

  使用SafeRequest函数替换你的Request.

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80710

Copyright 2007-2008 papozhe.com [asp教程] All Rights Reserved.
浙ICP备07030537号
免责申明:所有文章除特别声明,均来自网上,主要为学习用!内容仅供参考,版权归原作者。如侵犯您利益,请来信告知.
Email:papozhe$Gmail.com QQ:76336503