Denial-of-Service (DoS) attack is an attempt to make a machine or network resource unavailable to its intended users, such as to temporarily or indefinitely interrupt or suspend services of a host connected to the Internet. A distributed denial-of-service (DDoS) is where the attack source is more than one–and often thousands of-unique IP addresses.
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 and network management tool, and can be easily configured to talk to iptables, firewalls, routers, etc. mod_evasive presently reports abuses via email and syslog facilities.
mod_evasive appears to be in the Debian official repository, we will need to install using apt
# apt-get update # apt-get install libapache2-mod-evasive
We have mod_evasive installed but not configured, mod_evasive config is located at /etc/apache2/mods-available/evasive.conf. We will be editing that which should look similar to this
<IfModule mod_evasive20.c> #DOSHashTableSize 3097 #DOSPageCount 2 #DOSSiteCount 50 #DOSPageInterval 1 #DOSSiteInterval 1 #DOSBlockingPeriod 10 #DOSEmailNotify you@yourdomain.com #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'" #DOSLogDir "/var/log/mod_evasive" </IfModule>
This configuration is what I’m using which is working well and I recommend it if you don’t know how to go about the configuration
<IfModule mod_evasive20.c> DOSHashTableSize 2048 DOSPageCount 5 DOSSiteCount 100 DOSPageInterval 1 DOSSiteInterval 2 DOSBlockingPeriod 10 DOSEmailNotify you@yourdomain.com #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'" DOSLogDir "/var/log/mod_evasive" </IfModule>
As you’ll replace you@yourdomain.com with your email. Since mod_evasive doesn’t create the log directory automatically, we are to create it for it:
# mkdir /var/log/mod_evasive # chown :www-data /var/log/mod_evasive # chmod 771 /var/log/mod_evasive
Once setup is done, make sure mod_evasive is enabled by typing:
# a2enmod evasive
Restart Apache for changes to take effect
# systemctl restart apache2
mod_evasive set up correctly, now we are going to test if our web server has protection again DoS attack using ab (Apache Benchmark). Install ab if you don’t have it by typing:
# apt-get install apache2-utils
Current stat of our /var/log/mod_evasive
root@debian-server:/var/log/mod_evasive# ls -l total 0 root@debian-server:/var/log/mod_evasive#
We will now send bulk requests to the server, causing a DoS attack by typing:
# ab -n 100 -c 10 http://10.23.21.109/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.23.21.109 (be patient).....done Server Software: Apache/2.4.10 Server Hostname: 10.23.21.109 Server Port: 80 Document Path: / Document Length: 11104 bytes Concurrency Level: 10 Time taken for tests: 0.205 seconds Complete requests: 100 Failed requests: 70 (Connect: 0, Receive: 0, Length: 70, Exceptions: 0) Non-2xx responses: 70 Total transferred: 373960 bytes HTML transferred: 353140 bytes Requests per second: 488.51 [#/sec] (mean) Time per request: 20.471 [ms] (mean) Time per request: 2.047 [ms] (mean, across all concurrent requests) Transfer rate: 1784.01 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 1.5 1 7 Processing: 3 15 28.0 10 177 Waiting: 2 14 28.0 9 176 Total: 3 17 28.4 12 182 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 14 80% 15 90% 18 95% 28 98% 175 99% 182 100% 182 (longest request)
Sending 100 request on 10 concurrent requests per request, the current stat of my /var/log/mod_evasive directory is now
root@debian-server:/var/log/mod_evasive# ls -l total 4 -rw-r--r-- 1 www-data www-data 5 Dec 15 22:10 dos-10.42.0.1
Checking Apache access logs at /var/log/apache2/access.log we can see all connections from ApacheBench/2.3 were dropped to 403
The post Protecting Apache Server From Denial-of-Service Attacks appeared first on NixPal.
At Canonical, the work of our teams is strongly embedded in the open source principles…
Welcome to the Ubuntu Weekly Newsletter, Issue 873 for the week of December 29, 2024…
Have WiFi troubles on your Ubuntu 24.04 system? Don’t worry, you’re not alone. WiFi problems…
The following is a post from Mark Shuttleworth on the Ubuntu Discourse instance. For more…
I don’t like my prompt, i want to change it. it has my username and…
Introduction: A Fragile Trust The Ruby ecosystem relies heavily on RubyGems.org as the central platform…