This guide is intended as a relatively easy step by step guide to:
- Install and configure Apache2 ModSecurity and mod_evasive modules on Ubuntu 12.04 LTS server.
- Things have become much easier than before installing both these two excellent security modules for Apache2 in Ubuntu 12.04 LTS, as both modules are available in the standard Ubuntu 12.04 repositories.
- This is only a starting point for getting mod_security and mod_evasive working. Refer to both projects documentation for the various configuration option available and configure your security settings as required.
Requirements:
- Ubuntu 12.04 LTS server, or later installed on your machine.
- Apache2 webserver setup and configured.
1. Install ModSecurity on your server.
- Install the dependencies. Open the Terminal Window and enter :
sudo apt-get install libxml2 libxml2-dev libxml2-utils
sudo apt-get install libaprutil1 libaprutil1-dev
- 64bit users please note - Because of this bug you need to create a symbolic link to libxml2.so.2 or the installation will report the file missing and fail.
ln -s /usr/lib/x86_64-linux-gnu/libxml2.so.2 /usr/lib/libxml2.so.2
- Now install ModSecurity
sudo apt-get install libapache-mod-security
2. Configure ModSecurity rules.
- Activate the recommended default rules to get things going. Configure as needed. For complete information refer to the ModSecurity Reference Manual - click here.
sudo mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
- The default folder for ModSecurity rules is /etc/modsecurity/ . All .conf files will be included and need to be configured as required.
- We need to activate all the base rules and make sure they also get loaded.
- You might want to edit the SecRequestBodyLimit option in the modsecurity.conf file.
- SecRequestBodyLimit limits the page request size and limits file uploads to 128 KB by default. Change this to the size of files you would accept uploaded to the server.
- This settings is very important as it limits the size of all files that can be uploaded to the server. For CMS sites using Drupal or Wordpress this setting is the source of much pain.
- Open the Terminal Window and enter :
sudo nano /etc/modsecurity/modsecurity.conf
- First activate the rules by editing the SecRuleEngine option and set to On.
SecRuleEngine On
- Edit the following to option to increase the request limit to 16 MB and save the file :
SecRequestBodyLimit 16384000
SecRequestBodyInMemoryLimit 16384000
3. Download and install the latest Rule Set.
- Open the Terminal Window and enter :
cd /tmp
sudo wget https://github.com/SpiderLabs/owasp-modsecurity-crs/tarball/v2.2.5
This is not the latest version, the latest is 2.2.7, but when used we are unable to start the service, so as in other forums, they recommend to keep using v.2.2.5. After that everything worked for us smoothly!
sudo tar -zxvf modsecurity-crs_2.2.5.tar.gz
sudo cp -R modsecurity-crs_2.2.5/* /etc/modsecurity/
sudo rm modsecurity-crs_2.2.5.tar.gz
sudo rm -R modsecurity-crs_2.2.5
sudo mv /etc/modsecurity/modsecurity_crs_10_setup.conf.example /etc/modsecurity/modsecurity_crs_10_setup.conf
- Now we create symbolic links to all activated base rules. Open a terminal window and enter :
cd /etc/modsecurity/base_rules for f in * ; do sudo ln -s /etc/modsecurity/base_rules/$f /etc/modsecurity/activated_rules/$f ; done cd /etc/modsecurity/optional_rules for f in * ; do sudo ln -s /etc/modsecurity/optional_rules/$f /etc/modsecurity/activated_rules/$f ; done
- Now add these rules to Apache2. Open a terminal window and enter:
sudo nano /etc/apache2/mods-available/mod-security.conf
- Add the following to towards the end of the file with other includes and save the file :
Include "/etc/modsecurity/activated_rules/*.conf"
4. Check if ModSecurity is enabled and restart Apache.
- Before restarting Apache2 check if the modules has been loaded.
- Open the Terminal Window and enter :
sudo a2enmod headers
sudo a2enmod mod-security
- Then restart the Apache2 webserver :
sudo /etc/init.d apache2 restart
- OR
service apache2 restart
5. Install ModEvasive.
- Open the Terminal Window and enter :
sudo apt-get install libapache2-mod-evasive
6. Create log file directory for mod_evasive.
- Open the Terminal Window and enter :
sudo mkdir /var/log/mod_evasive
- Change the log folder permissions :
sudo chown www-data:www-data /var/log/mod_evasive/
7. Create mod-evasive.conf file and configure ModEvasive.
- Open the Terminal Window and enter :
sudo nano /etc/apache2/mods-available/mod-evasive.conf
- and add the following, changing the email value, and other options below as required :
<ifmodule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSLogDir /var/log/mod_evasive
DOSEmailNotify [email protected]
DOSWhitelist 127.0.0.1
</ifmodule>
8. Check if ModEvasive is enabled and restart Apache.
- Before restarting Apache2 check if the module has been loaded.
- Open the Terminal Window and enter :
sudo a2enmod mod-evasive
- Then restart the Apache2 webserver :
sudo /etc/init.d/apache2 restart
- OR
service apache2 restart
Janeth Kent
Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN AND DEVELOPMENT.
Related Posts
The ultimate cybersecurity checklist for programmers
In today's digital age, cybersecurity has become an essential concern for programmers. With cyber threats on the rise, it is crucial for programmers to adopt robust security practices to protect…
Network attacks and how to avoid them
Nowadays it is impossible to list all the different types of attacks that can be carried out on a network, as in the world of security this varies continuously. We…
How To Use Varnish As A Highly Available Load Balancer On Ubuntu 20.04 With SSL
Load balancing with high availability can be tough to set up. Fortunately, Varnish HTTP Cache server provides a dead simple highly available load balancer that will also work as a…
6 Best Alternative Privacy Focused Browsers in 2021
In today's article we take a look at free private browsers which are relevant in 2021. We will compare their advantages and disadvantages, specs, etc. Let's get into it. What are alternative…
htaccess Rules to Help Protect from SQL Injections and XSS
This list of rules by no means is a sure bet to secure your web services, but it will help in preventing script-kiddings from doing some basic browsing around. MySQL injection…
Security of Internet providers: can we trust it?
This year has been a time of many changes. Now, more people are connected to the Internet through their home routers for teleworking, shopping, or leisure. This is where the…
Brief History of Biometric Authentication
These days, biometric authentication seems to be part of every little gadget or device we use. You’ve no doubt used it when logging onto your laptop, your tablet, or your…
A beginner’s guide to software vulnerabilities
What are software vulnerabilities The number of devices connected to the Internet is growing every day. And among those devices we find not only computers and smartphones, but also an ever-rising…
The BleedingTooth vulnerability and other Bluetooth security risks
Have you ever heard of BleedingTooth? And we do not mean the really disturbing looking mushroom which goes by this name and is totally real (we double checked) but one of…
Network and port scanning with Zenmap
This article goes out to all the computer nerds who are, when it comes to networking, more on the noob-side of the crowd. It does not have to be complicated…
Google Dorks: How to find interesting data and search like hacker
Go the words Google and Hacking together? Well if you thought that we will learn how to use hack Google, you might be wrong. But we can Use Google search engine…
How to block any website with a password from your browser
We are going to explain how to block any website with a password from your browser, and for this purpose we are going to use an extension called Block Site.…