More comprehensive ASP anti-CC attack code sharing _ Application Tips

Source: Internet
Author: User
Tags readfile servervariables
Copy Code code as follows:

<%
Dim Cc_info (4), strinfo,strtemp
If session ("cc_info") = "" Then
Cc_info (0) = "cclog.txt" ' Log file name
Cc_info (1) = Request.ServerVariables ("Http_x_forwarded_for")
Cc_info (2) = Request.ServerVariables ("REMOTE_ADDR")
Cc_info (3) = Ten ' n seconds is not allowed to refresh the current page
Cc_info (4) = "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 ' 0 off anti-refresh
Const chkproxy = 1 ' 0 Turn off proxy authentication
Const Chkbadip = 1 ' 0 off 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, no refresh 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 is prohibited to view * *
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 log
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

'/* third-level judgment, IP blacklist prohibited View * *
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 ("Write 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 ("Read 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
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.