較為全面的asp防CC攻擊代碼分享

來源:互聯網
上載者:User

複製代碼 代碼如下:<%
Dim CC_Info(4),strInfo,strTemp
If Session("CC_Info") = "" Then
CC_Info(0) = "cclog.txt" '記錄檔名
CC_Info(1) = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
CC_Info(2) = Request.ServerVariables("REMOTE_ADDR")
CC_Info(3) = 10 'N秒內禁止重新整理當前頁面
CC_Info(4) = "badip.txt" 'IP黑名單檔案名稱
Session("CC_Info") = CC_Info(0) &"|"& CC_Info(1) &"|"& CC_Info(2) &"|"& CC_Info(3) &"|"& CC_Info(4)
Else
strInfo = Split(Session("CC_Info"),"|")
CC_Info(0) = strInfo(0)
CC_Info(1) = strInfo(1)
CC_Info(2) = strInfo(2)
CC_Info(3) = strInfo(3)
CC_Info(4) = strInfo(4)
End If

Const chkRefresh = 1 '0關閉防重新整理
Const chkProxy = 1 '0關閉代理驗證
Const chkBadIP = 1 '0關閉IP黑名單

If Session("BadIP") = "" Then
strInfo = ReadFile(CC_Info(4))
If strInfo = "" Then strInfo = "chinavb.net"
Session("BadIP") = strInfo
Else
strInfo = Session("BadIP")
End If

'/*第一層判斷,N秒內禁止重新整理*/
If chkRefresh = 1 Then
If Session("RefreshTime")="" Then
Session("RefreshTime")=Now()
Else
If DateDiff("s", Session("RefreshTime"), Now()) < CInt(CC_Info(3)) Then
Response.Write("系統繁忙,請稍候再試!錯誤碼001")
Response.End()
Else
Session("RefreshTime")=Now()
End If
End If
End If

'/*第二層判斷,代理禁止查看*/
If chkProxy = 1 Then
If CC_Info(1) <> "" Then
If InStr(strInfo,CC_Info(1)) = 0 Then
strTemp = CC_Info(1) & vbCrLf
If InStr(strInfo,CC_Info(2)) = 0 Then
strTemp = strTemp & "[" & CC_Info(2) & "]" & vbCrLf
End If
SaveLog CC_Info(4),strTemp
strInfo = strInfo & strTemp
Session("BadIP") = strInfo
End If
'記錄CC攻擊日誌
SaveLog CC_Info(0),CC_Info(1) & "["& CC_Info(2) & "]" & Now() &vbCrLf
Response.Write("系統繁忙,請稍候再試!錯誤碼002")
Response.End()
End If
End If

'/*第三層判斷,IP黑名單禁止查看*/
If chkBadIP = 1 Then
If InStr(strInfo,CC_Info(2))>0 Then
Response.Write("系統繁忙,請稍候再試!錯誤碼003")
Response.End()
End If
End If

'ForReading=1,ForWriting=2,ForAppending=8
Function SaveLog(filename, filecontent)
On Error Resume Next
Dim fso, thisfile
filename = Server.MapPath(filename)
Set fso = CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
Response.Write("寫入檔案"&filename&"失敗,可能您的系統不支援FSO!")
Response.End()
End If
Set thisfile = fso.OpenTextFile(filename, 8, True)
thisfile.write (filecontent)
thisfile.Close
Set fso = Nothing
End Function

Function ReadFile(filename)
On Error Resume Next
Dim fso, thisfile
Set fso = CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
Response.Write("讀取檔案"&filename&"失敗,可能您的系統不支援FSO!")
Response.End()
End If
Set thisfile = fso.OpenTextFile(Server.MapPath(filename), 1, True)
ReadFile = thisfile.ReadAll
thisfile.Close
Set thisfile = Nothing
Set fso = Nothing
End Function
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.