自己写一个防止SQL注入函数

王朝asp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

<%

function sqlcheck(Str,errtype)

if Instr(LCase(Str),"select ") > 0 or Instr(LCase(Str),"insert ") > 0 or Instr(LCase(Str),"delete ") > 0 or Instr(LCase(Str),"delete from ") > 0 or Instr(LCase(Str),"count(") > 0 or Instr(LCase(Str),"drop table") > 0 or Instr(LCase(Str),"update ") > 0 or Instr(LCase(Str),"truncate ") > 0 or Instr(LCase(Str),"asc(") > 0 or Instr(LCase(Str),"mid(") > 0 or Instr(LCase(Str),"char(") > 0 or Instr(LCase(Str),"xp_cmdshell") > 0 or Instr(LCase(Str),"exec master") > 0 or Instr(LCase(Str),"net localgroup administrators") > 0 or Instr(LCase(Str),"and ") > 0 or Instr(LCase(Str),"net user") > 0 or Instr(LCase(Str),"or ") > 0 then

Response.write("<script language=javascript>" & vbcrlf & "window.location.href ='ShowError.asp?errtype=" & errtype & "'" & vbcrlf & "</script>")

Response.End

end if

Str=Replace(Str,"_","") '过滤SQL注入_

Str=Replace(Str,"*","") '过滤SQL注入*

Str=Replace(Str," ","") '过滤SQL注入空格

Str=Replace(Str,chr(34),"") '过滤SQL注入"

Str=Replace(Str,chr(39),"") '过滤SQL注入'

Str=Replace(Str,chr(91),"") '过滤SQL注入[

Str=Replace(Str,chr(93),"") '过滤SQL注入]

Str=Replace(Str,chr(37),"") '过滤SQL注入%

Str=Replace(Str,chr(58),"") '过滤SQL注入:

Str=Replace(Str,chr(59),"") '过滤SQL注入;

Str=Replace(Str,chr(43),"") '过滤SQL注入+

Str=Replace(Str,"{","") '过滤SQL注入{

Str=Replace(Str,"}","") '过滤SQL注入}

sqlcheck=Str '返回经过上面字符替换后的Str

end function

%>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有