DDOS attack prevention by using mod_evasive

What is Mod_evasive?

One way to stop one of the more basic attacks on a server is mod_evasive. This article will assist you the process of installing and configuring mod_evasive. This apache module will help you to protect the server against people sending too many requests to the webserver in an attempt to flood it. If it detects too many connections from a specific IP, that  IP  will be blocked on the server. This is especially useful when the server is continuously attacked. With the default configuration it will block the offending IP for 10 minutes. If it continues to try and flood mod_evasive will automatically add more time to this.

Installation:

Follow these commands for Apache 1.3.x.
# cd /usr/local/src
# wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
# tar -zxf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# /usr/local/apache/bin/apxs -cia mod_evasive.c
======================================
Follow this commands for Apache 2.0.x.
# cd /usr/local/src
# wget http://www.zdziarski.com/projects/mod_evas/mod_evasive_1.10.1.tar.gz
# tar -zxf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# /usr/sbin/apxs -cia mod_evasive20.c
===========================================

Configuration:

If you are adding this module to apache 1.3.x, the following lines need to be added to the httpd.conf  below the AddModule section.

<IfModule mod_evasive.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 100
DOSPageInterval 2
DOSSiteInterval 2
DOSBlockingPeriod 600
</IfModule>

If you are using apache 2.0.x, you need to scroll down to the LoadModule section in the httpd.conf and add the following:

<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 100
DOSPageInterval 2
DOSSiteInterval 2
DOSBlockingPeriod 10
DOSBlockingPeriod 600
</IfModule>

Exit and save the httpd.conf

Now you need to restart the apache service..

# service httpd restart

It should be working for you.

DOSHashTableSize:

The hash table size defines the number of top-level nodes for each child’s hash table. Increasing this number will provide faster performance by decreasing the number of iterations required to get to the record, but consumes more memory for table space. You should increase this if you have a busy web server. The value you specify will automatically be tiered up to the next prime number in the primes list (see mod_evasive.c for a list of primes used).

DOSPageCount:

This is the threshold for the number of requests for the same page (or URI) per page interval. Once the threshold for that interval has been exceeded, the IP address of the client will be added to the blocking list.

DOSSiteCount:

This is the threshold for the total number of requests for any object by the same client on the same listener per site interval. Once the threshold for that interval has been exceeded, the IP address of the client will be added to the blocking list.

DOSPageInterval:

The interval for the page count threshold; defaults to 1 second intervals.

DOSSiteInterval:

The interval for the site count threshold; defaults to 1 second intervals.

DOSBlockingPeriod:

The blocking period is the amount of time (in seconds) that a client will be blocked for if they are added to the blocking list. During this time, all subsequent requests from the client will result in a 403 (Forbidden) and the timer being reset (e.g. another 10 seconds). Since the timer is reset for every subsequent request, it is not necessary to have a long blocking period; in the event of a Ddos attack, this timer will keep getting reset.

Tagged . Bookmark the permalink.

Leave a Reply