ASP上两个防止SQL注入式攻击Function

时间:2008-03-17 16:18:41   来源:   作者:

'==========================
'过滤提交表单中的SQL
'==========================
function ForSqlForm()
 dim fqys,errc,i,items
 dim nothis(18)
 nothis(0)="net user"

http://www.cnjiaocheng.com

 nothis(1)="xp_cmdshell" http://www.cnjiaocheng.com

 nothis(2)="/add"

来源中国教程网

 nothis(3)="exec%20master.dbo.xp_cmdshell"

http://www.cnjiaocheng.com

 nothis(4)="net localgroup administrators" http://www.cnjiaocheng.com

 nothis(5)="select" 来源中国教程网

 nothis(6)="count" http://www.cnjiaocheng.com

 nothis(7)="asc" 来源中国教程网

 nothis(8)="char"

http://www.cnjiaocheng.com

 nothis(9)="mid"

http://www.cnjiaocheng.com

 nothis(10)="'"

http://www.cnjiaocheng.com

 nothis(11)=":" http://www.cnjiaocheng.com

 nothis(12)="""" http://www.cnjiaocheng.com

 nothis(13)="insert" 来源中国教程网

 nothis(14)="delete"

http://www.cnjiaocheng.com

 nothis(15)="drop" http://www.cnjiaocheng.com

 nothis(16)="truncate" http://www.cnjiaocheng.com

 nothis(17)="from"

http://www.cnjiaocheng.com

 nothis(18)="%"
 
 'nothis(19)="@" 

http://www.cnjiaocheng.com

 errc=false 来源中国教程网

 for i= 0 to ubound(nothis)
  for each items in request.Form
  if instr(request.Form(items),nothis(i))<>0 then
   response.write("<div>")
   response.write("你所填写的信息:" & server.HTMLEncode(request.Form(items)) & "<br>含非法字符:" & nothis(i))
   response.write("</div>")
   response.write("对不起,你所填写的信息含非法字符!<a href=""#"" onclick=""history.back()"">返回</a>")
   response.End()
  end if
  next
 next
end function
'==========================
'过滤查询中的SQL
'==========================
function ForSqlInjection()
 dim fqys,errc,i
 dim nothis(19)
 fqys = request.ServerVariables("QUERY_STRING")
 nothis(0)="net user"

http://www.cnjiaocheng.com

 nothis(1)="xp_cmdshell"

http://www.cnjiaocheng.com

 nothis(2)="/add" 来源中国教程网

 nothis(3)="exec%20master.dbo.xp_cmdshell" http://www.cnjiaocheng.com

 nothis(4)="net localgroup administrators" 来源中国教程网

 nothis(5)="select"

http://www.cnjiaocheng.com

 nothis(6)="count"

来源中国教程网

 nothis(7)="asc" http://www.cnjiaocheng.com

 nothis(8)="char"

http://www.cnjiaocheng.com

 nothis(9)="mid" http://www.cnjiaocheng.com

 nothis(10)="'" 来源中国教程网

 nothis(11)=":"

来源中国教程网

 nothis(12)=""""

http://www.cnjiaocheng.com

 nothis(13)="insert"

http://www.cnjiaocheng.com

 nothis(14)="delete"

http://www.cnjiaocheng.com

 nothis(15)="drop" 来源中国教程网

 nothis(16)="truncate"

来源中国教程网

 nothis(17)="from" http://www.cnjiaocheng.com

 nothis(18)="%"
 
 nothis(19)="@"  http://www.cnjiaocheng.com

 errc=false 来源中国教程网

 for i= 0 to ubound(nothis)

http://www.cnjiaocheng.com

 if instr(FQYs,nothis(i))<>0 then http://www.cnjiaocheng.com

 errc=true http://www.cnjiaocheng.com

 end if 来源中国教程网

 next http://www.cnjiaocheng.com

 if errc then
 response.write "查询信息含非法字符!<a href=""#"" onclick=""history.back()"">返回</a>"
 response.end

http://www.cnjiaocheng.com

 end if

http://www.cnjiaocheng.com

end function

http://www.cnjiaocheng.com