asp 防止SQL注入

 

防止SQL注入 古老的话题,不需要太多的解释了,这里给出一个解决办法,

'**********************************
'防止SQL注入程序
'联系:QQ:49934843 EMAIL:cyh.yiheng@gmail.com
'***********************************

dim sql_Chk_Post,sql_Chk_Get,sql_Chk_In,sql_Chk_Inf,sql_Chk_Xh,sql_Chk_db,sql_Chk_dbstr,sql_Chk_Err
sql_Chk_Err = false
sql_Chk_In = "'|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
sql_Chk_Inf = split(sql_Chk_In,"|")
'--------POST部份------------------
If Request.Form<>"" Then
 For Each sql_Chk_Post In Request.Form
  For sql_Chk_Xh=0 To Ubound(sql_Chk_Inf)
   If Instr(LCase(Request.Form(sql_Chk_Post)),sql_Chk_Inf(sql_Chk_Xh))<>0 Then
    sql_Chk_Err = true
    alertError(sql_Chk_Post)
   End If
  Next
 Next
End If
'--------GET部份-------------------
If Request.QueryString<>"" Then
 For Each sql_Chk_Get In Request.QueryString
  For sql_Chk_Xh=0 To Ubound(sql_Chk_Inf)
   If Instr(LCase(Request.QueryString(sql_Chk_Get)),sql_Chk_Inf(sql_Chk_Xh))<>0 Then
    sql_Chk_Err = true
    alertError(sql_Chk_Get)
   End If
  Next
 Next
End If
'-------------------------------------

function alertError(byval sql_Chk_Date)
 Response.Write "<Script Language=JavaScript>alert('  SQL通用防注入系统提示↓/n/n请不要在参数中包含非法字符尝试注入!/n/n SQL通用防注入V2.0(ASP)完美版');</Script>"
 Response.Write "非法操作!系统做了如下记录↓<br>"
 Response.Write "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
 Response.Write "操作时间:"&Now&"<br>"
 Response.Write "操作页面:"&Request.ServerVariables("URL")&"<br>"
 Response.Write "提交参数:"&sql_Chk_Date&"<br>"
 Response.Write "提交数据:"&Request(sql_Chk_Date)
 Response.End
End function

 

将以上程序放在一个文件中,并include在自己的程序前,基本上能保证检测到。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值