当前位置: 移动技术网 > IT编程>开发语言>Asp > 较为全面的asp防CC攻击代码分享

较为全面的asp防CC攻击代码分享

2017年12月08日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: <% dim cc_info(4),strinfo,strtemp if session("cc_info") = "" then cc_inf
复制代码 代码如下:

<%
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
%>

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网