Jump to content

Anti DDos Script


TuQuoQueBrute

Recommended Posts

Hi all,

 

Im realy new to php , but i already love it. Before writing more, sorry my english dont be mad plz.

 

So i write this script to prevent dos and ddos attacks and it looks like this

 


<?php
$kk= $_SERVER['REMOTE_ADDR'];
$aa="2.txt";
$bb=fopen($aa, "w");
$aa1="22.txt";
$bb1=fopen($aa1, "a");
$dd="$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n$kk\n";
$dd1="$kk\n";
fwrite($bb, $dd);
fwrite($bb1, $dd1);
fclose($bb);
fclose($bb1);

$zz= file_get_contents("2.txt");
$zz1= file_get_contents("22.txt");
if ($zz == $zz1) { echo '<html><body bgcolor="#FF000000" text="#FFFFFF" oncontextmenu="return false;"><center><font face="Verdana, Arial"><h1>ANTI DDOS!</h1><b>IP '.$kk.' Banned.<br /><p> <p />Have a bad day...!</b></font></center></body></html>';
$file="22.txt";
$linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
 $line = fgets($handle);
 $linecount++;
}

fclose($handle);

if ($linecount > 20 ) unlink('22.txt');
$ht= fopen('.htaccess', "a");
$ht1= "deny from $kk\n";
fwrite($ht, $ht1);
fclose($ht);
exit();
}else{
$file="22.txt";
$linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
 $line = fgets($handle);
 $linecount++;
}

fclose($handle);
if ($linecount > 20 ) unlink('22.txt');
}
$aaa= $_SERVER['REQUEST_METHOD'];
if ($aaa == POST) { $ht= fopen('.htaccess', "a");
$ht1= "deny from $kk\n";
fwrite($ht, $ht1);
fclose($ht);
echo '<html><body bgcolor="#FF000000" text="#FFFFFF" oncontextmenu="return false;"><center><font face="Verdana, Arial"><h1>ANTI DDOS!</h1><b>IP '.$kk.' Banned.<br /><p> <p />Have a bad day...!</b></font></center></body></html>';
exit();
}else{
}
?>

 

hmmm... what it does is: if the last 20 ips entering the website are the same, it ban the ip cause may be a dos attempt, to enter the website the browser or the client have to do a GET request, so if any one do a POST request it ban the ip.

 

So i have this php doubht is there any function that allow me to know the amount of data sent by the user to the server?

Link to comment
https://forums.phpfreaks.com/topic/273922-anti-ddos-script/
Share on other sites

PHP is too late in the process to handle DDoS attacks. The whole point of such an attack is to make your server use more resources to deal with requests and this script will play right into that.

 

Your operating system/firewall is where you should focus your efforts. IIRC you can configure iptables to reject DDoSes, and failing that some automated log file reader (along the lines of fail2ban) can pick up the rest.

Link to comment
https://forums.phpfreaks.com/topic/273922-anti-ddos-script/#findComment-1409556
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.