vps被cc攻擊的解決方法
1.首先,在vps網站根目錄中新建一個ip.php文件;
2.ip.php文件創建好后,打開,并文件中添加以下內容,用于查找出cc攻擊的源IP;
$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 ”;
?>