較為全面的asp防CC攻擊代碼分享
更新時(shí)間:2011年11月02日 23:42:03 作者:
較為全面的asp防CC攻擊代碼分享,主要是用session進(jìn)行判斷。
復(fù)制代碼 代碼如下:
<%
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秒內(nèi)禁止刷新當(dāng)前頁(yè)面
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關(guān)閉防刷新
Const chkProxy = 1 '0關(guān)閉代理驗(yàn)證
Const chkBadIP = 1 '0關(guān)閉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秒內(nèi)禁止刷新*/
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("系統(tǒng)繁忙,請(qǐng)稍候再試!錯(cuò)誤代碼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("系統(tǒng)繁忙,請(qǐng)稍候再試!錯(cuò)誤代碼002")
Response.End()
End If
End If
'/*第三層判斷,IP黑名單禁止查看*/
If chkBadIP = 1 Then
If InStr(strInfo,CC_Info(2))>0 Then
Response.Write("系統(tǒng)繁忙,請(qǐng)稍候再試!錯(cuò)誤代碼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("寫(xiě)入文件"&filename&"失敗,可能您的系統(tǒng)不支持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&"失敗,可能您的系統(tǒng)不支持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
%>
相關(guān)文章
利用ASP實(shí)現(xiàn)在線生成電話圖片效果腳本附演示
利用ASP實(shí)現(xiàn)在線生成電話圖片效果腳本附演示...2007-11-11asp中的rs.open與conn.execute的區(qū)別說(shuō)明
不管是rs.open sql,conn還是conn.execute(sql) [這里的SQL是delete,update,insert]執(zhí)行以后都會(huì)返回一個(gè)關(guān)閉的記錄集2011-01-01基于ASPJPEG 制作了一個(gè)夢(mèng)寐已久的批量水印工具步驟
基于ASPJPEG 制作了一個(gè)夢(mèng)寐已久的批量水印工具步驟,需要的朋友可以參考下。2010-04-04ASP實(shí)現(xiàn)智能搜索實(shí)現(xiàn)代碼
asp下智能搜索功能的實(shí)現(xiàn),方便大家學(xué)習(xí)2008-06-06ASP開(kāi)發(fā)中數(shù)據(jù)庫(kù)文件調(diào)用的捷徑
本文針對(duì)ASP程序設(shè)計(jì)中最基礎(chǔ)、也是最關(guān)鍵的部分"數(shù)據(jù)庫(kù)文件的調(diào)用"進(jìn)行說(shuō)明,同時(shí)談?wù)凙SP程序設(shè)計(jì)中數(shù)據(jù)庫(kù)文件調(diào)用的一些技巧2006-09-09ASP也使用ORM,給ASP上所有的SQL注入畫(huà)上句號(hào)
PS:KJ大牛寫(xiě)的文章,昨天跟一朋友聊天的時(shí)候提到了ADO的command查詢,我竟然把這個(gè)東西給忘記了,看來(lái)記性真的是太差了,找到了kj大牛的文章,拜讀一下。2008-12-12ASP.Net?MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼
這篇文章主要介紹了ASP.Net?MVC利用NPOI導(dǎo)入導(dǎo)出Excel的問(wèn)題記錄,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05