[ Log In | Register ]       
Resource Database Index -> Source Code -> PHP Based DoS Blocker
Description // Info



Source Code

  1. <?php
  2.     define ('BLACKLIST','black.list');
  3.  
  4.     $list=file(BLACKLIST);
  5.  
  6.     foreach ($list as $addr)  {
  7.             $addr=trim($addr);
  8.             $host_addr=$_SERVER['REMOTE_ADDR'];
  9.  
  10.             // Semplice indirizzo IP
  11.             if ($host_addr==$addr)
  12.                     die ("Your IP is {$addr} and you're not allowed to view this page\n");
  13.  
  14.             // Subnet di classe C
  15.             else if (preg_match('/(\d+\.\d+\.\d+)\.0\/24/',$addr,$sub))  {
  16.                     $subnet=trim($sub[1]);
  17.  
  18.                     if (preg_match("/^{$subnet}/",$host_addr))
  19.                             die ("Your IP is {$host_addr} and you're not allowed to view this page\n");
  20.             }
  21.  
  22.             // Subnet di classe B
  23.             else if (preg_match('/(\d+\.\d+)\.0\.0\/16/',$addr,$sub))  {
  24.                     $subnet=trim($sub[1]);
  25.  
  26.                     if (preg_match("/^{$subnet}/",$host_addr))
  27.                             die ("Your IP is {$host_addr} and you're not allowed to view this page\n");
  28.             }
  29.  
  30.             // Subnet di classe A
  31.             else if (preg_match('/(\d+)\.0\.0\.0\/8/',$addr,$sub))  {
  32.                     $subnet=trim($sub[1]);
  33.  
  34.                     if (preg_match("/^{$subnet}/",$host_addr))
  35.                             die ("Your IP is {$host_addr} and you're not allowed to view this page\n");
  36.             }
  37.     }
  38.     ?>


Comments

POSTED BY: nexos ON 2010-10-08 13:46:50
I won't use this script, because there are more effective ways to block (especially http) dos. This script was userfull if it would save the dosing ips on its onwn. but i don't think this would work in php. some simple iptables rules are much more effective and fast. In addition, if your blacklist goes bigger and you are dosed, this script will put your webserver over the edge, because it reads and searches in the file every time a website is requested...

You must be logged in to post comments.

 Network Access...
USER ID
PASSWORD

 Code Information
Language:
PHP

Version:
1


Submitted:
2008-07-15 - 09:47:55


Author:

E-Mail
Website

Greetz:


[ Download | Report Issue ]

 Code Search
Search by Language
+ Assembly
+ ASP
+ ASP.NET
+ C#
+ C/C++
+ Cobol
+ Delphi
+ Java
+ Javascript
+ Pascal
+ Perl
+ PHP
+ Python
+ VB6
+ VB.NET

Advanced Search




 
 
By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the User Agreement.

© 2008 r00tsecurity network. All rights reserved.
[ About Us | Contact Us | Support Us | Legal | Advertise | User Agreement | Privacy Policy ]