您所在的位置:首页 > 资讯教程 > 软件教程 > 系统工具 > asp过滤SQL注入

asp过滤SQL注入

2017-07-12 21:48:23  来源:互联网  次阅读

 <%

'================================================================================================================
dim conn
dim connstr
dim db
db="data/da.mdb" '数据库文件位置
   connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
 'On Error Resume Next
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.commandtimeout=20
 conn.open ConnStr
 'If Err Then
  'err.Clear
  'Set Conn = Nothing
  'Response.Write "<br><br><br><br><br><br><br><div align='center'>数据库连接出错!请检查连接数据库的参数及字符串设置是否正确!</div>"
  'Response.End
 'End If
'-----------------------------------------------------------------------------------------------------
'-----------------------------------------------------------------------------------------------------

'为了系统的安全,直接在有数据库连接的地方都加上SQL注入的免疫
'自定义需要过滤的字串,用 "|" 分隔
Fy_In = "'| ; | and | or | exec | insert | select | delete | update | count | * | % |chr(| char(| mid | master | truncate | declare "
'----------------------------------
Fy_Inf = split(Fy_In,"|")
If Request.QueryString<>"" Then
For Each Fy_Get In Request.QueryString
For Fy_Xh=0 To Ubound(Fy_Inf)
If Instr(LCase(Request.QueryString(Fy_Get)),Fy_Inf(Fy_Xh))<>0 Then
'--------写入数据库----------头-----
conn.Execute("insert into web_errlog(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','GET','"&Fy_Get&"','"&replace(Request.QueryString(Fy_Get),"'","''")&"')")
'--------写入数据库----------尾-----
response.redirect("/Error.html")
response.end
End If
Next
Next
End If

'=======================================================
'
Function changechr(fString)
If Not IsNull(fString) Then
fString = trim(fString)
'fString = replace(fString, ";", ";")    '分号过滤
fString = replace(fString, "--", "——") '--过滤
fString = replace(fString, "%20", "")   '特殊字符过滤
fString = replace(fString, "==", "")    '==过滤
'fString = replace(fString, ">", "&gt;")
'fString = replace(fString, "<", "&lt;")
fString = Replace(fString, CHR(32), " ")  '&nbsp;
fString = Replace(fString, CHR(9), " ")   '&nbsp;
fString = Replace(fString, CHR(34), "&quot;")
fString = Replace(fString, CHR(39), "&#39;") '单引号过滤
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
changechr = fString
End If
End Function
%>

大家都在看

回到顶部

下载声明 | 法律声明 | 版权声明 | 发布软件 | 网站地图

本站所有软件,都由网友上传,如有侵犯你的版权,请发邮件给 [email protected]