这个还是值得深入学习一下的
<%
'正则表达式相关的变量
Dim regEx, Match, Match2, Matches, Matches2,ScriptName,UserTrueIP,sqltype,tupfile
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.MultiLine = True
ScriptName = Trim(Request.ServerVariables("SCRIPT_NAME"))
UserTrueIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If UserTrueIP = "" Then UserTrueIP = Request.ServerVariables("REMOTE_ADDR")
UserTrueIP = ReplaceBadChar(UserTrueIP)
Const EnableStopInjection = True '是否启用防SQL注入功能,True为启用,False为禁用
If EnableStopInjection = True Then
If Request.QueryString <> "" Then
Call StopInjection(Request.QueryString)
sqltype="QueryString"
End If
If Request.Cookies <> "" Then
Call StopInjection(Request.Cookies)
sqltype="Cookies"
End If
tupfile=LCase(Mid(ScriptName, InStrRev(ScriptName, "/") + 1))
If Request.Form<>"" Then
Call StopInjection2(Request.Form)
sqltype="Form"
End If
End If
'**************************************************
'函数名:ReplaceBadChar
'作 用:过滤非法的SQL字符
'参 数:strChar-----要过滤的字符
'返回值:过滤后的字符
'**************************************************
Function ReplaceBadChar(strChar)
If strChar = "" Or IsNull(strChar) Then
ReplaceBadChar = ""
Exit Function
End If
Dim strBadChar, arrBadChar, tempChar, i
strBadChar = "+,',%,^,&,?,(,),<,>,[,],{,},/,,;,:," & Chr(34) & "," & Chr(0) & ",--"
arrBadChar = Split(strBadChar, ",")
tempChar = strChar
For i = 0 To UBound(arrBadChar)
tempChar = Replace(tempChar, arrBadChar(i), "")
Next
tempChar = Replace(tempChar, "@@", "@")
ReplaceBadChar = tempChar
End Function
Sub StopInjection(Values)
Dim FoundInjection
regEx.Pattern = "'|;|#|([\s\b+()]+(select|insert|delete|declare|alter|create|backup|exists|daxia123|jxmmtv|<script|/script>)[\s\b+]*)"
Dim sItem, sValue
For Each sItem In Values
sValue = Values(sItem)
If regEx.Test(sValue) Then
FoundInjection = True
Response.Write "很抱歉,由于您提交的内容中含有危险的SQL注入代码,致使本次操作无效! "
Response.Write "<br>字段名:" & sItem
Response.Write "<br>字段值:" & sValue
Response.Write "<br>关键字:"
Set Matches = regEx.Execute(sValue)
For Each Match In Matches
Response.Write FilterJS(Match.value)
FilterJStb=FilterJStb&FilterJS(Match.value)
Next
Call LogtoTxt(sqltype,sItem,sValue,FilterJStb)
'Response.Write "<br><br>如果您是正常提交仍出现上面的提示,请联系站长暂时禁用掉防SQL注入功能,操作完成后再打开。"
End If
Next
If FoundInjection = True Then
Response.End
End If
End Sub
Sub StopInjection2(Values)
Dim FoundInjection
regEx.Pattern = "[';#()][\s+()](select|insert|delete|declare|exec|alter|create|backup|exists|daxia123|jxmmtv|<script|/script>)[\s+]"
Dim sItem, sValue
For Each sItem In Values
sValue = Values(sItem)
If regEx.Test(sValue) Then
FoundInjection = True
Response.Write "很抱歉,由于您提交的内容中含有危险的SQL注入代码,致使本次操作无效! "
Response.Write "<br>字段名:" & sItem
Response.Write "<br>字段值:" & sValue
Response.Write "<br>关键字:"
Set Matches = regEx.Execute(sValue)
For Each Match In Matches
Response.Write FilterJS(Match.value)
Next
'Response.Write "<br><br><br><br>如果您是正常提交仍出现上面的提示,请联系站长暂时禁用掉防SQL注入功能,操作完成后再打开。"
End If
Next
If FoundInjection = True Then
Response.End
End If
End Sub
Sub LogtoTxt(sqltype,sItem,sValue,FilterJStb)
dim fso99,LogFilePath99,Sql_act
set fso99 = createobject("scripting.filesystemobject")
LogFilePath99=server.mappath("")+"\ll\SqlinToFileDvbbs.txt"
set Sql_act = fso99.OpenTextFile(LogFilePath99,8,true)
Sql_act.write("操作IP:")
Sql_act.Write(UserTrueIP)
Sql_act.write(" 操作时间:")
Sql_act.write(Now)
Sql_act.write(" 操作页面:")
Sql_act.write(ScriptName)
Sql_act.write(" 提交方式:")
Sql_act.write(sqltype)
Sql_act.write(" 字段名:")
Sql_act.write(sItem)
Sql_act.write(" 字段值:")
Sql_act.write(sValue)
Sql_act.write(" 关键字:")
Sql_act.write(FilterJStb)
Sql_act.writeline
Sql_act.writeline
Sql_act.Close
'response.Write(LogFilePath99)
End sub
'=================================================
'函数名:FilterJS()
'作 用:过滤非法JS字符
'参 数:strInput 需要过滤的内容
'=================================================
Function FilterJS(ByVal strInput)
If IsNull(strInput) Or Trim(strInput) = "" Then
FilterJS = ""
Exit Function
End If
Dim reContent
' 替换掉HTML字符实体(Character Entities)名字和分号之间的空白字符,比如:ä ;替换成ä
regEx.Pattern = "(&#*\w+)[\x00-\x20]+;"
strInput = regEx.Replace(strInput, "$1;")
' 将无分号结束符的数字编码实体规范成带分号的标准形式
regEx.Pattern = "(&#x*[0-9A-F]+);*"
strInput = regEx.Replace(strInput, "$1;")
' 将 < > & "字符实体中的 & 替换成 & 以便在进行HtmlDecode时保留这些字符实体
'RegEx.Pattern = "&(amp|lt|gt|nbsp|quot);"
'strInput = RegEx.Replace(strInput, "&$1;")
' 将HTML字符实体进行解码,以消除编码字符对后续过滤的影响
'strInput = HtmlDecode(strInput);
' 将ASCII码表中前32个字符中的非打印字符替换成空字符串,保留 9、10、13、32,它们分别代表 制表符、换行符、回车符和空格。
regEx.Pattern = "[\x00-\x08\x0b-\x0c\x0e-\x19]"
strInput = regEx.Replace(strInput, "")
oldhtmlString = ""
Do While oldhtmlString <> strInput
oldhtmlString = strInput
regEx.Pattern = "(<[^>]+src[\x00-\x20]*=[\x00-\x20]*[^>]*?)&#([^>]*>)" '过虑掉 src 里的 &#
strInput = regEx.Replace(strInput, "$1&#$2")
regEx.Pattern = "(<[^>]+style[\x00-\x20]*=[\x00-\x20]*[^>]*?)&#([^>]*>)" '过虑掉style 里的 &#
strInput = regEx.Replace(strInput, "$1&#$2")
regEx.Pattern = "(<[^>]+style[\x00-\x20]*=[\x00-\x20]*[^>]*?)\\([^>]*>)" '替换掉style中的 "\"
strInput = regEx.Replace(strInput, "$1/$2")
Loop
' 替换以on和xmlns开头的属性
regEx.Pattern = "on(load\s*=\s*""*'*resizepic\(this\)'*""*)"
strInput = regEx.Replace(strInput, "off$1")
regEx.Pattern = "on(mousewheel\s*=\s*""*'*return\s*bbimg\(this\)'*""*)"
strInput = regEx.Replace(strInput, "off$1")
regEx.Pattern = "(<[^>]+[\x00-\x20""'/])(on|xmlns)([^>]*)>"
strInput = regEx.Replace(strInput, "$1pe$3>")
regEx.Pattern = "off(load\s*=\s*""*'*resizepic\(this\)'*""*)"
strInput = regEx.Replace(strInput, "on$1")
regEx.Pattern = "off(mousewheel\s*=\s*""*'*return\s*bbimg\(this\)'*""*)"
strInput = regEx.Replace(strInput, "on$1")
' 替换javascript
regEx.Pattern = "([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`'""]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:"
strInput = regEx.Replace(strInput, "$1=$2nojavascript...")
' 替换vbscript
regEx.Pattern = "([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`'""]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:"
strInput = regEx.Replace(strInput, "$1=$2novbscript...")
'替换style中的注释部分,比如:<div style="xss:expres/*comment*/sion(alert(x))">
regEx.Pattern = "(<[^>]+style[\x00-\x20]*=[\x00-\x20]*[^>]*?)/\*[^>]*\*/([^>]*>)"
strInput = regEx.Replace(strInput, "$1$2")
' 替换expression
regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*[eeE][xxX][ppP][rrR][eeE][ssS][ssS][iiI][ooO][nnN][\x00-\x20]*[\(\(][^>]*>"
strInput = regEx.Replace(strInput, "$1>")
' 替换behaviour
regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*behaviour[^>]*>>"
strInput = regEx.Replace(strInput, "$1>")
' 替换behavior
regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*behavior[^>]*>>"
strInput = regEx.Replace(strInput, "$1>")
' 替换script
regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*>"
strInput = regEx.Replace(strInput, "$1>")
' 替换namespaced elements 不需要
regEx.Pattern = "</*\w+:\w[^>]*>"
strInput = regEx.Replace(strInput, " ")
Dim oldhtmlString
oldhtmlString = ""
Do While oldhtmlString <> strInput
oldhtmlString = strInput
'实行严格过滤
regEx.Pattern = "</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>?"
strInput = regEx.Replace(strInput, " ")
'过滤掉SHTML的Include包含文件漏洞
regEx.Pattern = "<!--\s*#include[^>]*>"
strInput = regEx.Replace(strInput, "noshtml")
'If FilterLevel > 0 Then
' '实行严格过滤
' RegEx.Pattern = "</*(embed|object)[^>]*>"
' strInput = RegEx.Replace(strInput, "")
'End If
Loop
FilterJS = strInput
End Function
%>
这个能防你的COOKIE了吧
总结的很好,回复学习。
找到了阿哈 收集整理一下
支持了
我发的那个代码,有能过的不啊?
look~~~~~~~~~~
没人能过啊????
asp缘董也搞出来了 哈哈 听所很全的哦
支持猿洞牛{:4_60:}
感谢~好漂亮~收藏了~
看你的早八点 享受啊
我来学习下!!!!!
又是8点{:4_80:}
趁现在还早,看看先
来学习之 回复看看
要好好的学习下 挖洞洞
回复一下,好好学学
{:4_30:}