从别的地方看到的一个防注入函数

本文介绍了一个用于防范SQL注入攻击的函数实现。该函数通过检查和过滤特定字符串来阻止潜在的恶意输入,确保数据库的安全性和应用的稳定性。

这个函数还是比较全面的,先判断字符串,再过滤特殊字符
不过我认为防御最好的办法就是用数字传入再转换类型

function sqlcheck(Str)
  
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
    
Call Qcdn.Err_List("请不要在参数中包含非法字符尝试注入!",1)
    Response.End
    
exit function
  
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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值