您的位置:首页 > 编程语言 > ASP

asp 防止SQL注入

2006-06-26 20:21 316 查看
防止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在自己的程序前,基本上能保证检测到。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: