Giter Site home page Giter Site logo

mod_evasive's Introduction

mod_evasive

Fork of mod_evasive for Apache 2.4. Original module by Deep Logic, Inc

WHAT IS MOD_EVASIVE ?

mod_evasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera.

Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following:

  • Requesting the same page more than a few times per second
  • Making more than 50 concurrent requests on the same child per second
  • Making any requests while temporarily blacklisted (on a blocking list)

This method has worked well in both single-server script attacks as well as distributed attacks, but just like other evasive tools, is only as useful to the point of bandwidth and processor consumption (e.g. the amount of bandwidth and processor required to receive/process/respond to invalid requests), which is why it's a good idea to integrate this with your firewalls and routers.

This module instantiates for each listener individually, and therefore has a built-in cleanup mechanism and scaling capabilities. Because of this, legitimate requests are rarely ever compromised, only legitimate attacks. Even a user repeatedly clicking on 'reload' should not be affected unless they do it maliciously.

Three different module sources have been provided:

Apache v1.3 API: mod_evasive.c Apache v2.0 API: mod_evasive20.c Apache v2.4 API: mod_evasive24.c NSAPI (iPlanet): mod_evasiveNSAPI.c *

NOTE: mod_evasiveNSAPI is a port submitted by Reine Persson [email protected] and is not officially supported as part of the mod_evasive project.

HOW IT WORKS

A web hit request comes in. The following steps take place:

  • The IP address of the requestor is looked up on the temporary blacklist
  • The IP address of the requestor and the URI are both hashed into a "key". A lookup is performed in the listener's internal hash table to determine if the same host has requested this page more than once within the past 1 second.
  • The IP address of the requestor is hashed into a "key". A lookup is performed in the listerner's internal hash table to determine if the same host has requested more than 50 objects within the past second (from the same child).

If any of the above are true, a 403 response is sent. This conserves bandwidth and system resources in the event of a DoS attack. Additionally, a system command and/or an email notification can also be triggered to block all the originating addresses of a DDoS attack.

Once a single 403 incident occurs, mod_evasive now blocks the entire IP address for a period of 10 seconds (configurable). If the host requests a page within this period, it is forced to wait even longer. Since this is triggered from requesting the same URL multiple times per second, this again does not affect legitimate users.

The blacklist can/should be configured to talk to your network's firewalls and/or routers to push the attack out to the front lines, but this is not required.

mod_evasive also performs syslog reporting using daemon.alert. Messages will look like this:

Aug 6 17:41:49 elijah mod_evasive[23184]: [ID 801097 daemon.alert] Blacklisting address x.x.x.x: possible attack.

WHAT IS THIS TOOL USEFUL FOR?

This tool is excellent at fending off request-based DoS attacks or scripted attacks, and brute force attacks. When integrated with firewalls or IP filters, mod_evasive can stand up to even large attacks. Its features will prevent you from wasting bandwidth or having a few thousand CGI scripts running as a result of an attack.

If you do not have an infrastructure capable of fending off any other types of DoS attacks, chances are this tool will only help you to the point of your total bandwidth or server capacity for sending 403's. Without a solid infrastructure and address filtering tool in place, a heavy distributed DoS will most likely still take you offline.

HOW TO INSTALL

APACHE v1.3

Without DSO Support:

  1. Extract this archive into src/modules in the Apache source tree

  2. Run ./configure --add-module=src/modules/evasive/mod_evasive.c

  3. make, install

  4. Restart Apache

With DSO Support, Ensim, or CPanel:

  1. $APACHE_ROOT/bin/apxs -iac mod_evasive.c

  2. Restart Apache

APACHE v2.0

  1. Extract this archive

  2. Run $APACHE_ROOT/bin/apxs -i -a -c mod_evasive20.c

  3. The module will be built and installed into $APACHE_ROOT/modules, and loaded into your httpd.conf

  4. Restart Apache

APACHE v2.4

  1. Extract this archive

  2. Run $APACHE_ROOT/bin/apxs -i -a -c mod_evasive24.c

  3. The module will be built and installed into $APACHE_ROOT/modules, and loaded into your httpd.conf

  4. Restart Apache

NSAPI SunONE (iPlanet,netscape) Installation

Tested on: iPlanet 4.1sp12 iPlanet 6.0sp5

Edit compile script for your environment and compile mod_evasiveNSAPI.c to a shared library.

CONFIGURATION

mod_evasive has default options configured, but you may also add the following block to your httpd.conf:

APACHE v1.3

DOSHashTableSize 3097 DOSPageCount 2 DOSSiteCount 50 DOSPageInterval 1 DOSSiteInterval 1 DOSBlockingPeriod 10

APACHE v2.0

DOSHashTableSize 3097 DOSPageCount 2 DOSSiteCount 50 DOSPageInterval 1 DOSSiteInterval 1 DOSBlockingPeriod 10

APACHE v2.4

DOSHashTableSize 3097 DOSPageCount 2 DOSSiteCount 50 DOSPageInterval 1 DOSSiteInterval 1 DOSBlockingPeriod 10

Optionally you can also add the following directives:

DOSEmailNotify	[email protected]
DOSSystemCommand	"su - someuser -c '/sbin/... %s ...'"
DOSLogDir		"/var/lock/mod_evasive"

You will also need to add this line if you are building with dynamic support:

APACHE v1.3

AddModule mod_evasive.c

APACHE v2.0

LoadModule evasive20_module modules/mod_evasive20.so

(This line is already added to your configuration by apxs)

APACHE v2.4

LoadModule evasive24_module modules/mod_evasive24.so

(This line is already added to your configuration by apxs)

NSAPI SunONE (iPlanet,Netscape) Configuration

Configure iPlanet 4.1

Edit obj.conf:

Init fn="load-modules" funcs="mod_evasive_init,mod_evasive_check" shlib="/opt/ns-4.1/plugins/lib/mod_evasive.sl"

Init fn="mod_evasive_init" DOSPageCount=2 DOSSiteCount=50 DOSPageInterval=1 DOSSiteInterval=1 DOSBlockingPeriod=10 DOSWhitelist="10.60.0.7,10.65.0.10"

In the default object: PathCheck fn=mod_evasive_check

Or an own object NameTrans fn=mod_evasive_check

Configure iPlanet 6.0

Edit magnus.conf:

Init fn="load-modules" funcs="mod_evasive_init,mod_evasive_check" shlib="/opt/iplanet-6.0/plugins/lib/mod_evasive.sl"

Init fn="mod_evasive_init" DOSWhitelist="10.60.0.7,10.65.0.10"

Edit obj.conf: In the default object: PathCheck fn=mod_evasive_check

Or an own object NameTrans fn=mod_evasive_check

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 consume 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 threshhold for the number of requests for the same page (or URI) per page interval. Once the threshhold for that interval has been exceeded, the IP address of the client will be added to the blocking list.

DOSSiteCount

This is the threshhold for the total number of requests for any object by the same client on the same listener per site interval. Once the threshhold 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 threshhold; defaults to 1 second intervals.

DOSSiteInterval

The interval for the site count threshhold; 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 DoS attack, this timer will keep getting reset.

DOSEmailNotify

If this value is set, an email will be sent to the address specified whenever an IP address becomes blacklisted. A locking mechanism using /tmp prevents continuous emails from being sent.

NOTE: Be sure MAILER is set correctly in mod_evasive.c (or mod_evasive20.c). The default is "/bin/mail -t %s" where %s is used to denote the destination email address set in the configuration. If you are running on linux or some other operating system with a different type of mailer, you'll need to change this.

DOSSystemCommand

If this value is set, the system command specified will be executed whenever an IP address becomes blacklisted. This is designed to enable system calls to ip filter or other tools. A locking mechanism using /tmp prevents continuous system calls. Use %s to denote the IP address of the blacklisted IP.

DOSLogDir

Choose an alternative temp directory

By default "/tmp" will be used for locking mechanism, which opens some security issues if your system is open to shell users.

http://security.lss.hr/index.php?page=details&ID=LSS-2005-01-01

In the event you have nonprivileged shell users, you'll want to create a directory writable only to the user Apache is running as (usually root), then set this in your httpd.conf.

WHITELISTING IP ADDRESSES

IP addresses of trusted clients can be whitelisted to insure they are never denied. The purpose of whitelisting is to protect software, scripts, local searchbots, or other automated tools from being denied for requesting large amounts of data from the server. Whitelisting should not be used to add customer lists or anything of the sort, as this will open the server to abuse. This module is very difficult to trigger without performing some type of malicious attack, and for that reason it is more appropriate to allow the module to decide on its own whether or not an individual customer should be blocked.

To whitelist an address (or range) add an entry to the Apache configuration in the following fashion:

DOSWhitelist 127.0.0.1 DOSWhitelist 127.0.0.*

Wildcards can be used on up to the last 3 octets if necessary. Multiple DOSWhitelist commands may be used in the configuration.

TWEAKING APACHE

The keep-alive settings for your children should be reasonable enough to keep each child up long enough to resist a DOS attack (or at least part of one). Remember, it is the child processes that maintain their own internal IP address tables, and so when one exits, so does all of the IP information it had. For every child that exits, another 5-10 copies of the page may get through before putting the attacker back into '403 Land'. With this said, you should have a very high MaxRequestsPerChild, but not unlimited as this will prevent cleanup.

You'll want to have a MaxRequestsPerChild set to a non-zero value, as DosEvasive cleans up its internal hashes only on exit. The default MaxRequestsPerChild is usually 10000. This should suffice in only allowing a few requests per 10000 per child through in the event of an attack (although if you use DOSSystemCommand to firewall the IP address, a hole will no longer be open in between child cycles).

TESTING

Want to make sure it's working? Run test.pl, and view the response codes. It's best to run it several times on the same machine as the web server until you get 403 Forbidden messages. Some larger servers with high child counts may require more of a beating than smaller servers before blacklisting addresses.

Please don't use this script to DoS others without their permission.

KNOWN BUGS

  • This module appears to conflict with the Microsoft Frontpage Extensions. Frontpage sucks anyway, so if you're using Frontpage I assume you're asking for problems, and not really interested in conserving server resources anyway.

FEEDBACK

Please feel free to fork and fix issues or open new ones.

Original author: [email protected]

mod_evasive's People

Contributors

shivaas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mod_evasive's Issues

Apache 2.4.6 (CentOS7) - undefined symbol: evasive24_module

Hi,

I keep getting the following error once installed mod_evasive24 on Apache 2.4.6 (CentOs7):

httpd: Syntax error on line 56 of /etc/httpd/conf/httpd.conf: Syntax error on line 78 of /etc/httpd/conf.modules.d/00-base.conf: Can't locate API module structure `evasive24_module' in file /usr/lib64/httpd/modules/mod_evasive24.so: /usr/lib64/httpd/modules/mod_evasive24.so: undefined symbol: evasive24_module

Is there anything that needs to be tweaked? Or is it not compatible with 2.4.6?

Thx for your help.

Query : on blocking

what if 20 users use simultaneously from specific organization (which will be single ip ), will it check user agent before blocking ?

DOSLogDir

Debian

I tried different variants for path of the log dir
for example:
DOSLogDir "/var/log/mod_evasive"
DOSLogDir /var/log/apache2
etc.
but I don't see any log file

DOSLogDir is an abuse vector itself

Being that each attack source is written to an individual file in DOSLogDir, this leaves the machine open to inode abuse due to the sheer volume of files that can/will be created and apparently never cleaned up.

DOSLogdir
Directory where lock files will be created to prevent continuous emails from being sent or system commands from getting executed

However, even if DOSEmailNotify or DOSSystemCommand are commented out, these files are still created.

It would be great to simply let the module use syslog in this case.

Edit: Perhaps adding a cleanup routine to the module to remove the related DOSLogDir files when the associated hash table entry expires would be prudent here as well.

Needed to tweak

To run on our CentOS machine we needed to alter the print $SOCKET line. Thus,

#!/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=> "127.0.0.1:80");
if (! defined $SOCKET) { die $!; }
print $SOCKET "GET /?$_ HTTP/1.0\r\n\r\n";
$response = <$SOCKET>;
print $response;
close($SOCKET);
}

How whitelist or disable mod_evasive for a specific domain than entire server or all websites?

Hi,

We are using mod_evasive since years and its great module protecting the server against DDoS attack but we now got a situation where we need to disable mod_evasive just for a domain on a shared hosting server than disabling it from entire server.

If there any way we can whitelist/disable mod_evasive for a specific domain on a shared hosting server where hundreds of websites are hosted?

Thank you in advance.

Apache 2.4 - ignoring .conf file

I'm having issues with this fork ignoring my .conf files. It continues to log to /tmp and whitelisted IPs get blocked. I'm on Ubuntu 14.04 LTS and Apache 2.4.

Relevant configs + permissions:

ryan@ip-10-0-5-164:~$ sudo cat /etc/apache2/mods-available/evasive20.conf
<IfModule mod_evasive24.so>
    DOSHashTableSize    3097
    DOSPageCount        1
    DOSSiteCount        1
    DOSPageInterval     1
    DOSSiteInterval     1
    DOSBlockingPeriod   90

    DOSWhitelist    127.0.0.1

    #DOSEmailNotify      [email protected]
    #DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
    DOSLogDir           /var/log/apache2/mod_evasive
</IfModule>
ryan@ip-10-0-5-164:~$ sudo cat /etc/apache2/mods-available/evasive20.load
LoadModule evasive20_module   /usr/lib/apache2/modules/mod_evasive24.so
ryan@ip-10-0-5-164:~$ ls -l /usr/lib/apache2/modules/ | grep evasive
-rw-r--r-- 1 root root   58838 Feb 18 00:12 mod_evasive24.so

mod is enabled:

ryan@ip-10-0-5-164:~$ sudo a2enmod evasive20
Module evasive20 already enabled

Running the conventional Perl test script results in 403s and log files output to /tmp:

ryan@ip-10-0-5-164:~$ perl test.pl
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
ryan@ip-10-0-5-164:~$ ls -l /tmp
total 16
-rw-r--r-- 1 www-data www-data    6 Feb 18 17:02 dos-127.0.0.1

compilation error Apache 2.4.25

/usr/share/apr-1.0/build/libtool --mode=compile --tag=disable-static x86_64-linux-gnu-gcc -prefer-pic -pipe -g -O2 -fdebug-prefix-map=/build/apache2-2.4.25=. -fstack-protector-strong -Wformat -Werror=format-security -DBUILD_DATETIME='"2017-07-18T18:37:33"' -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -c -o mod_evasive20.lo mod_evasive20.c && touch mod_evasive20.slo

libtool: compile: x86_64-linux-gnu-gcc -pipe -g -O2 -fdebug-prefix-map=/build/apache2-2.4.25=. -fstack-protector-strong -Wformat -Werror=format-security -DBUILD_DATETIME=\"2017-07-18T18:37:33\" -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -c mod_evasive20.c -fPIC -DPIC -o .libs/mod_evasive20.o

mod_evasive20.c: In function ‘access_checker’:
mod_evasive20.c:142:39: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
       if (is_whitelisted(r->connection->remote_ip))
                                       ^~
mod_evasive20.c:146:43: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
       n = ntt_find(hit_list, r->connection->remote_ip);
                                           ^~
mod_evasive20.c:158:56: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
         snprintf(hash_key, 2048, "%s_%s", r->connection->remote_ip, r->uri);
                                                        ^~
mod_evasive20.c:165:47: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
             ntt_insert(hit_list, r->connection->remote_ip, time(NULL));
                                               ^~
mod_evasive20.c:180:58: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
         snprintf(hash_key, 2048, "%s_SITE", r->connection->remote_ip);
                                                          ^~
mod_evasive20.c:187:47: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
             ntt_insert(hit_list, r->connection->remote_ip, time(NULL));
                                               ^~
mod_evasive20.c:208:117: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
         snprintf(filename, sizeof(filename), "%s/dos-%s", log_dir != NULL ? log_dir : DEFAULT_LOG_DIR, r->connection->remote_ip);
                                                                                                                     ^~
mod_evasive20.c:212:36: warning: implicit declaration of function ‘getpid’ [-Wimplicit-function-declaration]
             fprintf(file, "%ld\n", getpid());
                                    ^~~~~~
mod_evasive20.c:212:30: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=]
             fprintf(file, "%ld\n", getpid());
                              ^
mod_evasive20.c:215:90: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
             LOG(LOG_ALERT, "Blacklisting address %s: possible DoS attack.", r->connection->remote_ip);
                                                                                          ^
mod_evasive20.c:46:82: note: in definition of macro ‘LOG’
 #define  LOG( A, ... ) { openlog("mod_evasive", LOG_PID, LOG_DAEMON); syslog( A, __VA_ARGS__ ); closelog(); }
                                                                                  ^~~~~~~~~~~
mod_evasive20.c:221:78: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
                 fprintf(file, "Subject: HTTP BLACKLIST %s\n\n", r->connection->remote_ip);
                                                                              ^~
mod_evasive20.c:222:81: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
                 fprintf(file, "mod_evasive HTTP Blacklisted %s\n", r->connection->remote_ip);
                                                                                 ^~
mod_evasive20.c:228:81: error: ‘conn_rec {aka struct conn_rec}’ has no member named ‘remote_ip’; did you mean ‘remote_host’?
               snprintf(filename, sizeof(filename), system_command, r->connection->remote_ip);
                                                                                 ^~
mod_evasive20.c:229:15: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Wunused-result]
               system(filename);
               ^~~~~~~~~~~~~~~~
apxs:Error: Command failed with rc=65536

Whitelist files/URLs on mod_evasive

Hello,

As soon as I enabled this module, I noticed that a number of IPs were blocked straight away, and all of those users use Safari on iOS.

After a quick investigation, I saw that those users were requesting "serviceworker.js" several times. This is a bug and this file should only be fetched once.

I reported that bug to Apple, but unfortunately the mess is already done and many users will continue to fetch this file several times -- https://bugs.webkit.org/show_bug.cgi?id=187435

mod_evasive allows me to whitelist IPs, but is there any way I can also whitelist files, folders or subdomains so that those will not count towards DOSPageCount or DOSSiteCount?

I'm only getting alerts and blocks for those who are fetching "serviceworker.js" so much.

Thank you very much,
Nuno

I can not install mod_evasive

Hi, I have plesk installed on your version onyx 17.5.3 but it does not have mod_evasive osea that I have to install via ssh but never install anything with just ssh and I have tried and it gives me many errors I need to install it correctly.

OS: CentOS Linux 7.3.1611 (Core)
Server version: Apache / 2.4.6 (CentOS)

Someone can help me with the correct installation.
regards

mod_Evasive block google bot

mod_evasive is great apache module to block site attack.
But Googlebot is giving us much requests every seconds and in most of cases and it is the heaviest http requester.
We can make mod_evasive not to judge Googlebot as dos attacker using whitelist funciton of mod_evasive but you can define it only by IP address.
If googlebot access to your site with unexpected IP, your server will return 403(forbidden) to googlebot and your site's rank in google will also drop.
please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.