学会这几招,遇到CC攻击时有用
发布时间:1503299958 作者:Reton技术部
最近朋友的网站受到CC攻击,就向我咨询,因为我对防cc攻击也不是很了解,所以我也不敢一下子给他什么好的答案。今天,我就写了下面的资料,看能不能给他,和大家一个好的方案,如果大家有对防CC攻击更好的主意,请留言与我,我们一起学习,谢谢!
if (isset($_SERVER)){
$realip = $_SERVER[HTTP_X_FORWARDED_FOR];
}
else
{
$realip = getenv("HTTP_X_FORWARDED_FOR");
}
if($realip""){
$remoteip=$_SERVER['REMOTE_ADDR'];
log_ip($remoteip,$realip);
}
function log_ip($remote_ip,$real_ip)
{
$temp_time = date("y-m-d G:i:s");
$temp_result = $temp_time."\t".$real_ip."\t".$remote_ip."\n";
if(!$fhandle=fopen("cc_log.txt","a+")){
print "error";
exit;
}
fwrite($fhandle,$temp_result);
fclose($fhandle);
}
?>
此段代码作用:
将代理访问的真实IP记录到日志中,以便排查分析。
以下是cc_log.txt的内容(此代码生产是因我通过CC攻击软件攻击生产的)
Time Real_ip Remote_ip
09-09-05 13:50:47 122.144.131.72 60.248.212.230
09-09-05 13:50:47 122.144.131.72 60.248.212.230
09-09-05 13:50:47 122.144.131.72 60.248.212.230
09-09-05 13:50:48 122.144.131.72 60.248.212.230
09-09-05 13:50:48 122.144.131.72 60.248.212.230
09-09-05 13:50:48 122.144.131.72 60.248.212.230
09-09-05 13:50:49 122.144.131.72 60.248.212.230
09-09-05 13:50:49 122.144.131.72 219.146.172.91
09-09-05 13:50:49 122.144.131.72 219.146.172.91
09-09-05 13:50:49 122.144.131.72 219.146.172.91
09-09-05 13:50:49 122.144.131.72 219.146.172.91
09-09-05 13:50:49 122.144.131.72 219.146.172.91
09-09-05 13:50:49 122.144.131.72 60.248.212.230
09-09-05 13:50:49 122.144.131.72 60.248.212.230
09-09-05 13:50:50 122.144.131.72 219.146.172.91
09-09-05 13:50:50 122.144.131.72 219.146.172.91
09-09-05 13:50:50 122.144.131.72 219.146.172.91
09-09-05 13:50:50 122.144.131.72 219.146.172.91
09-09-05 13:50:50 122.144.131.72 219.146.172.91
09-09-05 13:50:51 122.144.131.72 60.248.212.230
<?php
session_start();
$timestamp = time();
$cc_nowtime = $timestamp ;
if (session_is_registered('cc_lasttime')){
$cc_lasttime = $_SESSION['cc_lasttime'];
$cc_times = $_SESSION['cc_times'] + 1;
$_SESSION['cc_times'] = $cc_times;
}else{
$cc_lasttime = $cc_nowtime;
$cc_times = 1;
$_SESSION['cc_times'] = $cc_times;
$_SESSION['cc_lasttime'] = $cc_lasttime;
}
if (($cc_nowtime - $cc_lasttime)<5){
if ($cc_times>=10){
header(sprintf("Location: %s",'http://127.0.0.1'));
exit;
}
}else{
$cc_times = 0;
$_SESSION['cc_lasttime'] = $cc_nowtime;
$_SESSION['cc_times'] = $cc_times;
}
?>
【在百度搜索更多 学会这几招,遇到CC攻击时有用】