MMNCS.COM
  • Web
    • WordPress
    • Joomla
    • Drupal
  • Tips & Tricks
    • Youtube
    • WordPress
    • Windows
    • Web
    • Twitter
    • Linux Ubuntu
    • Google
    • Facebook
    • Drupal
    • Developer
    • Designer
    • Apple
  • Tech News
    • Windows Phone
    • Servers
    • Search Engines
    • Nokia
    • Microsoft
    • iPhone
    • Google
    • Facebook
    • Browsers
    • Apple
  • Social Media
    • Youtube
    • Yahoo
    • Twitter
    • Google+
    • Facebook
  • Server
    • Web Server
      • NGINX
      • Apache Web Server
    • Ubuntu
    • Security
      • Access Control
    • Mail Server
    • Hosting
    • FTP Server
    • Firewall
    • Database
      • MySQL
    • Backup
  • SEO
    • Yahoo Search
    • Google Search
    • Google AdSense
    • Bing
  • Off-Topic
    • Weird
    • Music
    • Fun
    • Documentaries
  • Mobile
    • Windows Phone 7
    • iPhone
    • Android
  • Google
    • Google Translate
    • Google Plus
    • Google PageRank
    • Google Adwords
    • AdSense
  • Design & Dev
    • Webdevelopment
    • Version Control
      • Git Version Control
    • Programming
    • PHP
    • JavaScript
    • HTML
    • Development Environment
    • CSS

Related

  1. How To Setup UncomplicatedFirewall ufw on Linux ubuntu 10.04 and 11.04 and other Debian distributions [Server Setup]
  2. How to setup a firewall using Shorewall on Linux Ubuntu 11.04 and other Debian based distributions
  3. The easy way to install LAMP Server (LINUX-APACHE-MYSQL-PHP) + PhpMyAdmin
  • Share on Tumblr

How to protect Apache against DOS,DDOS or brute force attacks using mod_evasive and mod_security and mod_qos on Linux Ubuntu 11.04

by MMNCS on July 10th, 2011, updated August 15, 2011
mod-evasive-mod-qos-mod-security-dos-ddos-attack

In this article we will show how to install mod_evasive and mod_security or mod_qos.

 

These modules protect Apache against DOS,DDOS or brute force attacks on Linux Ubuntu 10.04 or other debian based distributions.

 

Here is first an description on mod_evasive and mod_security.

 

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 and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_evasive presently reports abuses via email and syslog facilities.
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 for maximum protection.
This module instantiates for each listener individually, and therefore has a built-in cleanup mechanism and scaling capabilities. Because of this per-child design, legitimate requests are never compromised (even from proxies and NAT addresses) but only scripted attacks. Even a user repeatedly clicking on ‘reload’ should not be affected unless they do it maliciously. mod_evasive is fully tweakable through the Apache configuration file, easy to incorporate into your web server, and easy to use.

 

See also:
How to password protect Apache directory for unwanted users using a htaccess file on a Linux Server

 

What is mod_security?
ModSecurity is a web application firewall (WAF). With over 70% of attacks now carried out over the web application level, organisations need all the help they can get in making their systems secure. WAFs are deployed to establish an increased external security layer to detect and/or prevent attacks before they reach web applications. ModSecurity provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring and real-time analysis with little or no changes to existing infrastructure.

 

Installation

sudo apt-get install libapache2-mod-evasive libapache-mod-security

 

Create a new directory for your log files:

sudo mkdir /var/log/apache/mod_evasive

 

Set ownership to Apache:

sudo chown www-data:www-data /var/log/apache2/mod_evasive/

 

Create a configuration file in your conf.d directory all files in this folder gets read by Apache Server

sudo nano /etc/apache2/conf.d/mod_evasive.conf

 

Add the following to your configuration file:

DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSLogDir /var/log/apache2/mod_evasive
DOSWhitelist 127.0.0.1

 

Here is what settings stand for:

  • DOSHashTableSize is the size of the hash table that is created for the IP addresses monitored.
  • DOSPageCount is the number of pages allowed to be loaded for the DOSPageInterval setting. In our case, 2 pages per 1 second before the IP gets flagged.
  • DOSSiteCount is the number of objects (ie: images, style sheets, javascripts, SSI, etc) allowed to be accessed in theDOSSiteInterval second. In our case, 50 objects per 1 second.
  • DOSPageInterval is the number of seconds the intervals are set for DOSPageCount
  • DOSSiteInterval is the number of seconds the intervals are set for DOSSiteCount
  • DOSBlockingPeriod is the number of seconds the IP address will recieve the Error 403 (Forbidden) page when they have been flagged.

 

Enable the modules and restart Apache Server:

sudo a2enmod mod-evasive
sudo a2enmod mod-security
sudo /etc/init.d/apache2 restart

Install mod_qos
Incomplete…

mod_qos is a quality of service module for the Apache Web Server. It implements control mechanisms that can provide different priority to different requests and controls server access based on available resources.

## QoS Settings
# handles connections from up to 100000 different IPs
QS_ClientEntries 100000

# will allow only 50 connections per IP
QS_SrvMaxConnPerIP 50

# maximum number of active TCP connections is limited to 256
MaxClients 256

# disables keep-alive when 70% of the TCP connections are occupied:
QS_SrvMaxConnClose 180

# minimum request/response speed (deny slow clients blocking the server):
QS_SrvMinDataRate 150 1200

# and limit request header and body:
LimitRequestFields 30
QS_LimitRequestBody 102400

http://opensource.adnovum.ch/mod_qos/

http://ha.ckers.org/slowloris/

http://ha.ckers.org/blog/20090504/using-denial-of-service-for-hacking/

You may be interested in

  1. How To Setup UncomplicatedFirewall ufw on Linux ubuntu 10.04 and 11.04 and other Debian distributions [Server Setup]
  2. How to password protect Apache directory for unwanted users using a htaccess file on a Linux Server
  3. How to setup a firewall using Shorewall on Linux Ubuntu 11.04 and other Debian based distributions
  4. The easy way to install LAMP Server (LINUX-APACHE-MYSQL-PHP) + PhpMyAdmin
  5. How to install and setup php development environment using Eclipse, LAMP and xDebug on Linux Ubuntu 10.04 & 11.04 [Developer]

support and subscribe to the site

Follow @mmncs
Posted in Apache Web Server, Hosting, Security, Server Tags: 2011, Apache, Apache Web Server, DDOS attack, Dedicated Server, DOS attack, Guide, Install, Linux, mod_evasive, mod_qos, mod_security, Setup, ubuntu, VPS
« Comedy Movie Clip: Barry Munday – Support group for people with genital mutilation or deformity
How To Setup Openssh-sftp-server on Synology NAS and connect using sshfs from your Linux Server »


Comments

You can leave a response, or trackback from your own site.
  1. 28-7-2011
    Dannielle Drainer

    Thank you so much for sharing!

    Reply
  2. 10-4-2012
    Danny Coulombe

    You have a little mistake on the creation of the direction “mod_evasive”. You wrote “apache”, but it’s “apache2″.

    Otherwise, thank you very much for this tutorial!

    Danny

    Reply
  3. 3-10-2012
    Josh Sommers

    Absolutely fantastic! Thank you for putting this together. One note, though: `sudo mkdir /var/log/apache/mod_evasive` should be `sudo mkdir /var/log/apache2/mod_evasive`

    Reply

Leave a Reply

Click here to cancel reply.

Trackbacks & pingbacks

    Search terms for this article

    • apache client denied,
    • how to check for ddos linux,
    • ubuntu mod_security 11.04,
    • htaccess ddos page second,
    • apache 2 module for blocking ddos,
    • anti ddos protection ubuntu,
    • mod_security for ddos protection,
    • mod_qos windows installer,
    • optimal apache2 configuration in linux,
    • ddos protection apache friends,
    • anti dos mod_security,
    • apache ddos schutz windows,
    • cpanel per user apache status,
    • ddos apache php howto,
    • apache2 ddos protection module,
    • mod security prevent dos,
    • windows apache ddos prevention,
    • linux firewall for apache attacks,
    • mod_evasive ddos ubuntu,
    • модуль от ддоса для апача windows,
    • apache controlling DOS attacks,
    • apache protection ddos,
    • protect debian ddos attack,
    • mod_security brute force protect,
    • windows Apache2.2 ddos,
    • read log file for ddos apache,
    • ubuntu ddos attack,
    • ubuntu ddos protection firewall,
    • mod security limit connections,
    • apache mod_security dos attack,
    • Subscribe

      Find MMNCS.COM on Facebook, about guides, tutorials and learning within webdevelopment, drupal, MySQL, PHP, WordPress, SEO...
      Follow MMNCS.COM on Twitter and get the latest updates
      Follow @mmncs
      Subscribe to MMNCS.COM newsletter, about guides, tutorials and learning within webdevelopment, drupal, MySQL, PHP, WordPress, Programming, Technology, SEO...
    • The Best technology news guides tips tricks on the Internet
    • best online art gallery, paintings, illustrations, fine art photography
    • Services

      Check your Google PageRank checker optimize seo serp page rank
      Take a picture of any website, WordPress Screenshot demo
    • Latest

      Facebook Helps Breakup on One-Third of Marriages in the U.K.

      Facebook Helps Breakup on One-Third of Marriages in the U.K.

      December 30th, 2011

      Husbands and wives in the United Kingdom headed for divorce are increasingly citing Facebook in thei[...]

      Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

      Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

      December 30th, 2011

      Here's another awesome application for the Nokia Lumia 800 and other Windows Phones. Skyscanner allo[...]

      Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

      Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

      December 29th, 2011

      Rumor has it that the one thing that is notoriously missing (well, one of the things) from any Wind[...]

      Why I’m Replacing My iPhone With Nokia Lumia 800 And Why Android Is No Option

      Why I’m Replacing My iPhone With Nokia Lumia 800 And Why Android Is No Option

      December 7th, 2011

      Spoiler alert: This article is about how great the new Nokia Lumia 800 is, so if you are an iPho[...]

      Apple iPhone 4S Battery Drain Is Starting To Become A Serious Issue [iOs 5]

      Apple iPhone 4S Battery Drain Is Starting To Become A Serious Issue [iOs 5]

      November 29th, 2011

      Waiting on the next expected fix from Apple, iPhone 4S users complaining of rapid battery drain are [...]

    • musicfordriving com music for driving underground experimental electronic electronica dj rock jazz upcomming interesting music hot list hype
    • Selected

      Bill Gurley; Too Many Start-Ups Chase Too Little Cash

      Bill Gurley; Too Many Start-Ups Chase Too Little Cash

      November 14th, 2011

      Venture capitalist Bill Gurley has noticed something new this autumn: a big jump in the number of wh[...]

      The Best Programming Contest Ever Made – The AI Challenge Ants 2011 [Developer]

      The Best Programming Contest Ever Made - The AI Challenge Ants 2011 [Developer]

      October 30th, 2011

      The best programming contest ever made! Well that is what they state. The AI Challenge Ants 2011 is [...]

      Take A Picture Of Any Website [WordPress Screenshot Demo]

      Take A Picture Of Any Website [WordPress Screenshot Demo]

      October 28th, 2011

      Take a picture of any website. Just enter the website address in the form and press the button "Take[...]

      Optimize Your Time And Write Better CSS With {less} – [CSS Stylesheets]

      Optimize Your Time And Write Better CSS With {less} - [CSS Stylesheets]

      October 23rd, 2011

      If you think parts of CSS is repetitive, tedious, and … well, very boring. Have a look here. LESS [...]

      Call Your Friends For Free –  Cut The Expensive Voice And Text Plans To The Bare Minimum [Mobile Apps]

      Call Your Friends For Free - Cut The Expensive Voice And Text Plans To The Bare Minimum [Mobile Apps]

      October 14th, 2011

      After been using Viber for some time now. We highly recommend this mobile application for all smartp[...]

    • News

      Facebook Helps Breakup on One-Third of Marriages in the U.K.

      Facebook Helps Breakup on One-Third of Marriages in the U.K.

      December 30th, 2011

      Husbands and wives in the United Kingdom headed for divorce[...]

      Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

      Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

      December 30th, 2011

      Here's another awesome application for the Nokia Lumia 800 and[...]

      Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

      Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

      December 29th, 2011

      Rumor has it that the one thing that is notoriously missing[...]

    • Social Media

      Solved: Facebook XFBML Like Button Bug Creates a Vertical Scroll-Bar [Web Developer]

      Solved: Facebook XFBML Like Button Bug Creates a Vertical Scroll-Bar [Web Developer]

      September 16th, 2011

      After been doing a lot of work on the site I noticed when testing in IE8 and Firefox 3.6.x that I wa[...]

      Add a Cool Google Plus Profile Add to Circles Widget to Your Website [Google Plus]

      Add a Cool Google Plus Profile Add to Circles Widget to Your Website [Google Plus]

      August 11th, 2011

      Google Plus has created a very simple widget to embed your Google Plus profile on websites. This wid[...]

      How To Export All Your Facebook Friends To Google+ Using Yahoo Mail [Google+]

      How To Export All Your Facebook Friends To Google+ Using Yahoo Mail [Google+]

      August 8th, 2011

      Since the popular Chrome extension Facebook Friends Exporter got blocked we needed another way of ge[...]

    • Google

      Check Your Google Page Rank Here – Updated To Use The New Google PageRank Query URL

      Check Your Google Page Rank Here - Updated To Use The New Google PageRank Query URL

      October 8th, 2011

      Check PAGE RANK of Web site pages Instantly This is a free service to check Google™ page rank ins[...]

      Add a Simple Google Translate DropDown Box To Your Web Site [Tips & Tricks]

      Add a Simple Google Translate DropDown Box To Your Web Site [Tips & Tricks]

      September 6th, 2011

      Google Translate is the best free online translation service today and I often wonder why I rarely s[...]

      Google Closes Down 10 Mayor Business Areas [Tech News]

      Google Closes Down 10 Mayor Business Areas [Tech News]

      September 5th, 2011

      Google closes down 10 business areas in which the company itself calls "autumn-cleaning."The cle[...]

    • Home
    • About
    • Contact
    • Wollawonka
    Copyright © MMNCS.COM is a site aimed at web developers, system engineers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites. We cover Open Source recommendations, Linux Server guides, PHP, HTML, CSS, Drupal & WordPress Tutorials, Guides, Tips & Technology News.