Comprehensive asp anti-CC code
<%
Dim CC_Info (4), strInfo, strTemp
If Session ("CC_Info") = "" Then
CC_Info (0) = Invalid cclog.txt "'Log File Name
CC_Info (1) = Request. ServerVariables ("HTTP_X_FORWARDED_FOR ")
CC_Info (2) = Request. ServerVariables ("REMOTE_ADDR ")
CC_Info (3) = 10'n' seconds do not refresh the current page
CC_Info (4) = Invalid badip.txt "'IP blacklist file name
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' www.2cto.com 0 disable anti-Refresh
Const chkProxy = 1' 0 disable proxy Authentication
Const chkBadIP = 1' 0 Disable IP blacklist
If Session ("BadIP") = "" Then
StrInfo = ReadFile (CC_Info (4 ))
If strInfo = "" Then strInfo = "chinavb.net"
Session ("BadIP") = strInfo
Else
StrInfo = Session ("BadIP ")
End If
'/* First-level judgment, refreshing prohibited in N seconds */
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 ("the system is busy. Please try again later! Error code 001 ″)
Response. End ()
Else
Session ("RefreshTime") = Now ()
End If
End If
End If
'/* Second-level judgment. The agent cannot view it */
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
'Record CC attack logs
SaveLog CC_Info (0), CC_Info (1) & "[" & CC_Info (2) & "]" & Now () & vbCrLf
Response. Write ("the system is busy. Please try again later! Error Code 002 ″)
Response. End ()
End If
End If
'/* Layer 3 judgment, IP blacklist prohibited viewing */
If chkBadIP = 1 Then
If InStr (strInfo, CC_Info (2)> 0 Then
Response. Write ("the system is busy. Please try again later! Error Code 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 ("Writing File" & filename & "failed, your system may not support 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 ("reading file" & filename & "failed, your system may not support 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
%>