package BanBots; use strict; use warnings; use lib "/home/kirsle/public_html"; use BotTrap; # Our list of user agents to ban. our @ua = ( '^[A-Za-z0-9]+$', # Random arrangements of random letters and numbers. 'compatible \; MSIE 6\.0', # Spambot (note extra space before the semicolon) 'Microsoft URL Control', # E-mail Harvester that sells e-mails to the Chinese 'HMSE_Robot', # E-mail Harvester / Content Scraper #'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.5) Gecko/20070718 Fedora/2.0.0.5-1.fc7 Firefox/2.0.0.5', ); # Our list of IP addresses to ban. our @ip = ( '^63\.148\.99\.2(2[4-9]|[3-4][0-9]|5[0-5])$', # Cyveillence Spybot '^12\.148\.196\.(12[8-9]|1[3-9][0-9]|2[0-4][0-9]|25[0-5])$', # NameProtect Spybot '^64\.140\.49\.6([6-9])$', # Turnitin Spybot #'^68\.61\.139\.194$', ); # Our list of HTTP Referers to ban. our @ref = ( 'iaea\.org', # Spambot ); use CGI::Carp qw(fatalsToBrowser); ################################################################################ ## 1. Check User Agents ## ################################################################################ if (defined $ENV{HTTP_USER_AGENT}) { foreach my $agent (@ua) { if ($ENV{HTTP_USER_AGENT} =~ /$agent/) { # 403 Error. &give403(); } } } ################################################################################ ## 2. Check IP Addresses ## ################################################################################ my $remote_addr = $ENV{REMOTE_ADDR}; if (exists $ENV{X_FORWARDING_FOR}) { $remote_addr = $ENV{X_FORWARDING_FOR}; } foreach my $addr (@ip) { if ($remote_addr =~ /$addr/) { # 403 Error. &give403(); } } ################################################################################ ## 3. Check Referring URLs ## ################################################################################ if (defined $ENV{HTTP_REFERER}) { foreach my $url (@ref) { if ($ENV{HTTP_REFERER} =~ /$url/) { # 403 Error. &give403(); } } } ################################################################################ ## 4. Check Bot-Trapped IP Addresses ## ################################################################################ my $isBanned = &BotTrap::IsBanned ($ENV{REMOTE_ADDR}); croak $isBanned; if ($isBanned) { &give403(); } sub give403 { print "Status: 403\n" . "Content-Type: text/html\n\n"; print qq~ 403 Forbidden

403 Forbidden

You have been banned from this website. If you feel that this is an error, please contact the webmaster of this site at the following address:

Admin ~; exit(0); } 1;