<%

'最后修改日期：2014-1-16 By HSK
If Request.ServerVariables("Script_Name") <> "/Database.asp" And Instr(Request.ServerVariables("Script_Name"), "/Include/LabelAdd.asp") = 0 Then
    On Error Resume Next
    If Request.querystring <> "" Then
        Call StopHacker(Request.querystring, "'|<[^>]+?style=[\w]+?:expression\(|<[^>]*?=[^>]*?&#[^>]*?>|\b(alert|confirm|prompt)\b|^\+/v(8|9)|\bonmouse(over|move)=\b|\b(and|or)\b.+?(>|<|=|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)")
    End If
    If Request.ServerVariables("HTTP_REFERER") <> "" Then
        Call Test(Request.ServerVariables("HTTP_REFERER"), "'|\b(and|or)\b.+?(>|<|=|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)")
    End If
    If Request.Cookies <> "" Then
        Call StopHacker(Request.Cookies, "\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)")
    End If
    Call StopHacker(Request.Form, "<[^>]+?style=[\w]+?:expression\(|\bonmouse(over|move)=\b|\b(alert|confirm|prompt)\b|^\+/v(8|9)|<[^>]*?=[^>]*?&#[^>]*?>|\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|<\s*img[^>]+?http://|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)")
End If

Function Test(Values, Re)
    Dim Regex
    Set Regex = New regexp
    Regex.ignorecase = True
    Regex.Global = True
    Regex.Pattern = Re
    If Regex.Test(Values) Then
        IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
        If IP = "" Then
            IP = Request.ServerVariables("REMOTE_ADDR")
        End If
        'sLog ("<br><br>操作IP: " & IP & "<br>操作时间: " & Now() & "<br>操作页面：" & Request.ServerVariables("URL") & "<br>提交方式: " & Request.ServerVariables("Request_Method") & "<br>提交来路地址: " & Request.ServerVariables("HTTP_REFERER"))
        Response.Write ("<div style='position:fixed;top:0px;width:100%;height:100%;background-color:white;color:green;font-weight:bold;border-bottom:5px solid #999;'><br>抱歉！您的提交带有不合法参数，并且IP已被系统记录。<br><br>如果你是正常操作看到此提示，请联系客服人员处理，谢谢!</div>")
        Response.end
    End If
    Set Regex = Nothing
End Function


Function StopHacker(Values, Re)
    Dim l_get, l_get2, n_get, Regex, IP
    For Each n_get In Values
        For Each l_get In Values
            l_get2 = Values(l_get)
            Set Regex = New regexp
            Regex.ignorecase = True
            Regex.Global = True
            Regex.Pattern = Re
            If Regex.Test(l_get2) Then
                IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
                If IP = "" Then
                    IP = Request.ServerVariables("REMOTE_ADDR")
                End If
                sLog ("<br><br>操作IP: " & IP & "<br>操作时间: " & Now() & "<br>操作页面：" & Request.ServerVariables("URL") & "<br>提交方式: " & Request.ServerVariables("Request_Method") & "<br>提交参数: " & l_get & "<br>提交数据: " & l_get2)
                Response.Write ("<div style='position:fixed;top:0px;width:100%;height:100%;background-color:white;color:green;font-weight:bold;border-bottom:5px solid #999;'><br>抱歉！您的提交带有不合法参数，并且IP已被系统记录。<br><br>如果你是正常操作看到此提示，请联系客服人员处理，谢谢!</div>")
                Response.end
            End If
            Set Regex = Nothing
        Next
    Next
End Function

Sub sLog(Logs)
    On Error Resume Next
    Dim TopPath, FS, TS
    TopPath = Server.Mappath("/非法提交记录#.txt")
    Set FS = CreateObject("Scripting.FileSystemObject")
    If Not FS.FILEEXISTS(TopPath) Then
        Set TS = FS.createtextfile(TopPath, True)
        TS.Close
    End If
    Set TS = FS.OpenTextFile(TopPath, 8)
    TS.writeline (Logs)
    TS.Close
    Set TS = Nothing
    Set FS = Nothing
End Sub

%>
