ASP anti-CC attack code sharing

Source: Internet
Author: User
Tags error code readfile servervariables

<%


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) = In ' 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 floor 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 prohibits viewing/


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


' Records 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.