Simple Perl Script To Test Mod_Evasive On Your Apache Web Server

One way to prevent DOS attack is to install mod_evasive for Apache. I wrote the article “Prevent DDoS Attack With mod_evasive in Apache 2” a while ago.

And now if you want to check if mod_evasive is working correctly, you can use the simple Perl script below:

#!/usr/bin/perl

# test.pl: small script to test mod_dosevasive's effectiveness

use IO::Socket;
use strict;

for(0..100) {
my($response);
my($SOCKET) = new IO::Socket::INET( Proto   => "tcp",
PeerAddr=> "target.com:80");
if (! defined $SOCKET) { die $!; }
print $SOCKET "GET /?$_ HTTP/1.0rnHost: 127.0.0.1rnrn";
$response = <$SOCKET>;
print $response;
close($SOCKET);
}

To run the script:

perl filename.pl

This script will do 100 requests to your web server and will return the response code. As you know, return code 200 means it successfully connected. But if it is 404 (not found) or 302 (redirect), that means the server blocked the request or is maybe down. If you have mod_evasive installed for Apache, you will see some of the codes will return 200 and then later return 302 — that means your mod_evasive is working correctly.

This Perl script is only a simple way to test web server security, especially simulating a DOS attack. There are still many ways to stress test your web server to know how many requests it can handle in a certain time.