vps:vps被cc攻击如何解决
vps被cc攻击如何解决
vps被cc攻击的解决方法
1.首先,在vps网站根目录中新建一个ip.php文件;
2.ip.php文件创建好后,打开,并文件中添加以下内容,用于查找出cc攻击的源IP;
<?php
$real_ip = getenv(‘HTTP_X_FORWARDED_FOR’);
if(isset($real_ip)){
shell_exec(\"echo $real_ip > real_ip.txt\");
shell_exec(\"echo $_SERVER[\'REMOTE_ADDR\']> proxy.txt”);
}else{
shell_exec(\"echo $_SERVER[\'REMOTE_ADDR\'] > ips.txt”)\"
}
echo
?>
3.cc攻击的源IP查找到后,重新在vps网站根目录中新建一个ban.php文件;
4.最后,ban.php文件创建好后,在文件中添加以下内容,对IP进行封禁便可;
<?
$threshold = 10;
$ips = array_count_values(file(\'ips.txt’));
$ban_num = 0;
foreach($ips as $ip=>$num){
if($num > $threshold){
$ip = trim($ip);
$cmd = “iptables -I INPUT -p tcp --dport 80 -s $ip -j DROP”;
shell_exec($cmd);
echo “$ip baned! ”;
$ban_num ++;
}
}
$proxy_arr = array_unique(file(\'ips.txt’))\'
foreach($proxy_arr as $proxy){
$proxy = trim($proxy);
$cmd = “iptables -I INPUT -p tcp --dport 80 -s $ip -j DROP”;
shell_exec($cmd);
echo “$ip baned! ”;
$ban_num ++;
}
echo “total: $ban_num ips ”;
?>