改进的SQL防注入
发表于:2007-06-30来源:作者:点击数:
标签:
% @#ASP防注入之 解决方案 @#特殊页面处理@#因为有些页通过流式传递(比如含有文件上传的表单)@#如果单一使用穷举Form对象的操作就会出错@#所以要把这些页面过滤出来,同时在页面中使用sql(检测的字串)才行@#垃圾猪zero@new57.com@#http://blog.csdn.net/cfaq @
<%
@#ASP防注入之
解决方案@#特殊页面处理@#因为有些页通过流式传递(比如含有文件上传的表单)@#如果单一使用穷举Form对象的操作就会出错@#所以要把这些页面过滤出来,同时在页面中使用sql("检测的字串")才行@#垃圾猪zero@new57.com@#http://blog.csdn.net/cfaq
@#源码
下载http://www.new57.com/softback/sql.rar
@#将本页用include方法放在头部以让所有页都可以调用,比如include在conn.asp里@#如果有流式上传的页面请把该页加到表page中,以防form冲突
Dim N_no,N_noarray,req_Qs,req_F,N_i,N_dbstr,Conn,N_rs,N_userIP,N_thispageN_userip = Request.ServerVariables("REMOTE_ADDR")N_thispage = LCase(Request.ServerVariables("URL"))
N_no = "@#|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare" @#可以自己修改怀疑是注入操作的字串N_noarray = split(LCase(N_no),"|")
Call DBopen()Call N_check_Qs()Call N_checkPage()Call DBCLose()
@#检测当前页是否是特殊页是就调用 N_check_form()sub N_checkPage()
set N_rs = server.CreateObject("ADODB.RecordSet") N_rs.open "select * from page where spcpage like @#%"&N_thispage&"%@#",conn,1,1 if (N_rs.eof AND N_rs.Bof) then Call N_check_form() end if N_rs.Close() set N_rs = nothing
end sub
@#检测给定字串sub N_sql(agsql) @#这里是不记录
数据库,如果要改请自己修改 N_check "CUS",req_Qs,"OTHER"end sub
@#检测Request.Formsub N_check_form() If Request.Form<>"" Then For Each req_F In Request.Form N_check req_F,Request.Form(req_F),"POST" Next end ifend sub
@#检测Request.QueryStringsub N_check_Qs() If Request.QueryString<>"" Then For Each req_Qs In Request.QueryString N_check req_Qs,Request.QueryString(req_Qs),"GET" Next end ifend sub
@#检测sub N_check(ag,agsql,sqltype) For N_i=0 To Ubound(N_noarray) If Instr(LCase(agsql),N_noarray(N_i))<>0 Then call N_regsql(ag,agsql,sqltype) Response.Write "MO" end if Nextend sub
@#记录并停止输出@#ag 名称@#agsql 内容@#sqltype 类型sub N_regsql(ag,agsql,sqltype) if(sqltype<>"OTHER") then Conn.Execute("insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values(@#"&N_userip&"@#,@#"&N_thispage&"@#,@#"&sqltype&"@#,@#"&ag&"@#,@#"&agsql&"@#)") end if Response.Write "<Script Language=
JavaScript>alert(@#请不要在参数中包含非法字符尝试注入!@#);</Script>" Response.Write "<span style=@#font-size:12px@#>非法操作!系统做了如下记录↓<br>" Response.Write "操作IP:"&N_userip&"<br>" Response.Write "操作时间:"&Now&"<br>" Response.Write "操作页面:"&N_thispage&"<br>" Response.Write "提交方式:"&sqltype&"<br>" Response.Write "提交参数:"&ag&"<br>" Response.Write "提交数据:"&agsql&"</span>" Response.endend sub
Sub DBopen() N_dbstr="DBQ="+server.mappath("Sql.mdb")+";DefaultDir=;DRIVER={Microsoft A
clearcase/" target="_blank" >ccess Driver (*.mdb)};" Set Conn=Server.CreateObject("ADODB.CONNECTION") Conn.open N_dbstrend SUB
Sub DBCLose() Conn.close Set Conn = NothingEnd sub%>
原文转自:http://www.ltesting.net