熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp防CC攻擊代碼分享

2013-11-13 10:35:20  來源: .NET編程 

  <%
Dim CC_Info()strInfostrTemp
If Session("CC_Info") = "" Then
CC_Info() = "cclogtxt" 日志文件名
CC_Info() = RequestServerVariables("HTTP_X_FORWARDED_FOR")
CC_Info() = RequestServerVariables("REMOTE_ADDR")
CC_Info() = N秒內禁止刷新當前頁面
CC_Info() = "badiptxt" IP黑名單文件名
Session("CC_Info") = CC_Info() &"|"& CC_Info() &"|"& CC_Info() &"|"& CC_Info() &"|"& CC_Info()
Else
strInfo = Split(Session("CC_Info")"|")
CC_Info() = strInfo()
CC_Info() = strInfo()
CC_Info() = strInfo()
CC_Info() = strInfo()
CC_Info() = strInfo()
End If

Const chkRefresh = 關閉防刷新
Const chkProxy = 關閉代理驗證
Const chkBadIP = 關閉IP黑名單

If Session("BadIP") = "" Then
strInfo = ReadFile(CC_Info())
If strInfo = "" Then strInfo = "chinavbnet"
Session("BadIP") = strInfo
Else
strInfo = Session("BadIP")
End If

/*第一層判斷N秒內禁止刷新*/
If chkRefresh = Then
If Session("RefreshTime")="" Then
Session("RefreshTime")=Now()
Else
If DateDiff("s" Session("RefreshTime") Now()) < CInt(CC_Info()) Then
ResponseWrite("系統繁忙請稍候再試!錯誤代碼")
ResponseEnd()
Else
Session("RefreshTime")=Now()
End If
End If
End If

/*第二層判斷代理禁止查看*/
If chkProxy = Then
If CC_Info() <> "" Then
If InStr(strInfoCC_Info()) = Then
strTemp = CC_Info() & vbCrLf
If InStr(strInfoCC_Info()) = Then
strTemp = strTemp & "[" & CC_Info() & "]" & vbCrLf
End If
SaveLog CC_Info()strTemp
strInfo = strInfo & strTemp
Session("BadIP") = strInfo
End If
記錄CC攻擊日志
SaveLog CC_Info()CC_Info() & "["& CC_Info() & "]" & Now() &vbCrLf
ResponseWrite("系統繁忙請稍候再試!錯誤代碼")
ResponseEnd()
End If
End If

/*第三層判斷IP黑名單禁止查看*/
If chkBadIP = Then
If InStr(strInfoCC_Info())> Then
ResponseWrite("系統繁忙請稍候再試!錯誤代碼")
ResponseEnd()
End If
End If

ForReading=ForWriting=ForAppending=
Function SaveLog(filename filecontent)
On Error Resume Next
Dim fso thisfile
filename = ServerMapPath(filename)
Set fso = CreateObject("ScriptingFileSystemObject")
If Err <> Then
ResponseWrite("寫入文件"&filename&"失敗可能您的系統不支持FSO!")
ResponseEnd()
End If
Set thisfile = fsoOpenTextFile(filename True)
thisfilewrite (filecontent)
thisfileClose
Set fso = Nothing
End Function

Function ReadFile(filename)
On Error Resume Next
Dim fso thisfile
Set fso = CreateObject("ScriptingFileSystemObject")
If Err <> Then
ResponseWrite("讀取文件"&filename&"失敗可能您的系統不支持FSO!")
ResponseEnd()
End If
Set thisfile = fsoOpenTextFile(ServerMapPath(filename) True)
ReadFile = thisfileReadAll
thisfileClose
Set thisfile = Nothing
Set fso = Nothing
End Function
%>


From:http://tw.wingwit.com/Article/program/net/201311/14057.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.