<%
Dim ShenbiSQL
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.MultiLine = True
Dim MessageReA, MessageReB, MessageReC, MessageReD, MessageReE
MessageReA = "警告：由于您提交的内容中含有危险的SQL注入代码，本次操作无效！"
MessageReB = "字段名："
MessageReC = "字段值："
MessageReD = "关键字："
MessageReE = "有任何疑问请登录岁月设计官方网站获取帮助：http://www.seosuiyue.com/"
'If EnableStopInjection = True Then
If EnableStopInjection = False Then
    If Request.QueryString <> "" Then Call StopInjection(Request.QueryString)
    If Request.Cookies <> "" Then Call StopInjection(Request.Cookies)
    If Request.Cookies <> "" Then Call StopInjection2(Request.Form)
End If

Sub StopInjection(Values)
    Dim FoundInjection
    regEx.Pattern = "'|;|#|([\s\b+()]+(select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s\b+]*)"
    Dim sItem, sValue
    For Each sItem In Values
        sValue = Values(sItem)
        If regEx.Test(sValue) Then
            FoundInjection = True
            Response.Write "<div style=""font-size: 12px;"">"
            Response.Write MessageReA
            Response.Write "<br />" & MessageReB & "" & sItem
            Response.Write "<br />" & MessageReC & "" & sValue
            Response.Write "<br />" & MessageReD & ""
            Set Matches = regEx.Execute(sValue)
            For Each Match In Matches
                Response.Write FilterJS(Match.Value)
            Next
            Response.Write "<br /><br /><font color=""red"">" & MessageReE & "</font>"
            Response.Write "</div>"
        End If
    Next
    If FoundInjection = True Then
        Response.End
    End If
End Sub

Sub StopInjection2(Values)
    Dim FoundInjection
    regEx.Pattern = "[';#()][\s+()]*(select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s+]*"
    Dim sItem, sValue
    For Each sItem In Values
        sValue = Values(sItem)
        If regEx.Test(sValue) Then
            FoundInjection = True
            Response.Write "<div style=""font-size: 12px;"">"
            Response.Write MessageReA
            Response.Write "<br />" & MessageReB & "" & sItem
            Response.Write "<br />" & MessageReC & "" & sValue
            Response.Write "<br />" & MessageReD & ""
            Set Matches = regEx.Execute(sValue)
            For Each Match In Matches
                Response.Write FilterJS(Match.Value)
            Next
            Response.Write "<br /><br /><font color=""red"">" & MessageReE & "</font>"
            Response.Write "</div>"
        End If
    Next
    If FoundInjection = True Then
        Response.End
    End If
End Sub

Function ShenbiSQLCode(password, ShenbiSQL)
    Dim MIN_CheckCode, MAX_CheckCode, NUM_CheckCode, offset, Str_len, i, code, To_TxT
    MIN_CheckCode = 32
    MAX_CheckCode = 126
    NUM_CheckCode = MAX_CheckCode - MIN_CheckCode + 1
    offset = password
    Rnd -1
    Randomize offset
    ShenbiSQL = Replace(ShenbiSQL, "/*/", Chr(34))
    Str_len = Len(ShenbiSQL)
    For i = 1 To Str_len
        Code = Asc(Mid(ShenbiSQL, i, 1))
        If Code >= MIN_CheckCode And Code <= MAX_CheckCode Then
            Code = Code - MIN_CheckCode
            offset = Int((NUM_CheckCode + 1) * Rnd)
            Code = ((Code - offset) Mod NUM_CheckCode)
            If Code < 0 Then Code = Code + NUM_CheckCode
            Code = Code + MIN_CheckCode
            To_TxT = To_TxT & Chr(Code)
            ShenbiSQLCode = Replace(To_TxT, "\*\", vbCrLf)
        Else
            To_TxT = To_TxT & Chr(Code)
            ShenbiSQLCode = Replace(To_TxT, "\*\", vbCrLf)
        End If
    Next
End Function

Function FilterJS(ByVal strInput)
    If IsNull(strInput) Or Trim(strInput) = "" Then
        FilterJS = ""
        Exit Function
    End If
    Dim reContent
    regEx.Pattern = "(&#*\w+)[\x00-\x20]+;"
    strInput = regEx.Replace(strInput, "$1;")
    regEx.Pattern = "(&#x*[0-9A-F]+);*"
    strInput = regEx.Replace(strInput, "$1;")
    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]*[^>]*?)&#([^>]*>)"
        strInput = regEx.Replace(strInput, "$1&amp;#$2")
        regEx.Pattern = "(<[^>]+style[\x00-\x20]*=[\x00-\x20]*[^>]*?)&#([^>]*>)"
        strInput = regEx.Replace(strInput, "$1&amp;#$2")
        regEx.Pattern = "(<[^>]+style[\x00-\x20]*=[\x00-\x20]*[^>]*?)\\([^>]*>)"
        strInput = regEx.Replace(strInput, "$1/$2")
    Loop
    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")
    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...")
    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...")
    regEx.Pattern = "(<[^>]+style[\x00-\x20]*=[\x00-\x20]*[^>]*?)/\*[^>]*\*/([^>]*>)"
    strInput = regEx.Replace(strInput, "$1$2")
    regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*[eｅＥ][xｘＸ][pｐＰ][rｒＲ][eｅＥ][sｓＳ][sｓＳ][iｉＩ][oｏＯ][nｎＮ][\x00-\x20]*[\(\（][^>]*>"
    strInput = regEx.Replace(strInput, "$1>")
    regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*behaviour[^>]*>>"
    strInput = regEx.Replace(strInput, "$1>")
    regEx.Pattern = "(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([`'""]*).*behavior[^>]*>>"
    strInput = regEx.Replace(strInput, "$1>")
    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>")
    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, "　")
        regEx.Pattern = "<!--\s*#include[^>]*>"
        strInput = regEx.Replace(strInput, "noshtml")
    Loop
    FilterJS = strInput
End Function
%>