User Tools

Site Tools


apache:install_mod_security_and_mod_evasive

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
apache:install_mod_security_and_mod_evasive [2016/07/12 14:28] – created peterapache:install_mod_security_and_mod_evasive [2023/07/17 10:19] (current) – removed peter
Line 1: Line 1:
-====== Apache - Install mod_security and mod_evasive ====== 
- 
-===== Install [[http://www.modsecurity.org/|ModSecurity]] on your server. ===== 
- 
-Install the dependencies.  Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo apt-get install libxml2 libxml2-dev libxml2-utils 
-sudo apt-get install libaprutil1 libaprutil1-dev 
-</code> 
- 
-**NOTE**:  64bit users please note - Because of [[http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=670248|this bug]] you need to create a symbolic link to libxml2.so.2 or the installation will report the file missing and fail. 
- 
-<code bash> 
-ln -s /usr/lib/x86_64-linux-gnu/libxml2.so.2 /usr/lib/libxml2.so.2 
-</code> 
- 
-Now install ModSecurity: 
- 
-<code bash> 
-sudo apt-get install libapache-mod-security 
-</code> 
- 
- 
-===== Configure ModSecurity rules. ===== 
- 
-Activate the recommended default rules to get things going. Configure as needed. For complete information refer to the [[http://www.modsecurity.org/documentation/modsecurity-apache/2.5.9/modsecurity2-apache-reference.html|ModSecurity Reference Manual - click here]]. 
- 
-<code bash> 
-sudo mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf 
-</code> 
- 
-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: 
- 
-<code bash> 
-sudo vi /etc/modsecurity/modsecurity.conf 
-</code> 
- 
-First activate the rules by editing the **SecRuleEngine** option and set to On and modify your server signature. 
- 
-<file bash /etc/modsecurity/modsecurity.conf> 
-SecRuleEngine On 
-SecServerSignature FreeOSHTTP 
-</file> 
- 
-Edit the following to option to increase the request limit to 16 MB and save the file: 
- 
-<file bash /etc/modsecurity/modsecurity.conf> 
-SecRequestBodyLimit 16384000 
-SecRequestBodyInMemoryLimit 16384000 
-</file> 
- 
- 
-===== Download and install the latest OWASP Core Rule Set ===== 
- 
-We need to download and install the latest [[https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project|OWASP ModSecurity Core Rule Set]] from the project website.  Click [[https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project|here]] for more information. 
- 
-We will also activate the default CRS config file **modsecurity_crs_10_setup.conf.example**. 
- 
-If you prefer not to use the latest rules, replace master below with the a specific version you would like to use e.g : **v2.2.5**. 
-   
-Open the Terminal Window and enter: 
- 
-<code bash> 
-cd /tmp 
-sudo wget -O SpiderLabs-owasp-modsecurity-crs.tar.gz https://github.com/SpiderLabs/owasp-modsecurity-crs/tarball/master 
-sudo tar -zxvf SpiderLabs-owasp-modsecurity-crs.tar.gz 
-sudo cp -R SpiderLabs-owasp-modsecurity-crs-*/* /etc/modsecurity/ 
-sudo rm SpiderLabs-owasp-modsecurity-crs.tar.gz 
-sudo rm -R SpiderLabs-owasp-modsecurity-crs-* 
-sudo mv /etc/modsecurity/modsecurity_crs_10_setup.conf.example /etc/modsecurity/modsecurity_crs_10_setup.conf 
-</code> 
- 
-Now we create symbolic links to all activated base rules.  Open a terminal window and enter: 
- 
-<code bash> 
-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  
-</code> 
- 
-Now add these rules to Apache2.  Open a terminal window and enter: 
- 
-<code bash> 
-sudo vi /etc/apache2/mods-available/mod-security.conf 
-</code> 
- 
-Add the following to towards the end of the file with other includes and save the file: 
- 
-<file bash /etc/apache2/mods-available/mod-security.conf> 
-Include "/etc/modsecurity/activated_rules/*.conf" 
-</file> 
- 
- 
-===== Check if ModSecurity is enabled and restart Apache ===== 
- 
-Before restarting Apache2 check if the modules has been loaded. 
- 
-Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo a2enmod headers 
-sudo a2enmod mod-security 
-</code> 
- 
-Then restart the Apache2 webserver: 
- 
-<code bash> 
-sudo /etc/init.d apache2 restart 
-</code> 
- 
-OR 
- 
-<code bash> 
-service apache2 restart 
-</code> 
- 
- 
-===== Install [[http://www.zdziarski.com/blog/?page_id=442|ModEvasive]] ===== 
- 
-Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo apt-get install libapache2-mod-evasive 
-</code> 
- 
- 
-===== Create log file directory for mod_evasive ===== 
- 
-Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo mkdir /var/log/mod_evasive 
-</code> 
- 
-Change the log folder permissions: 
- 
-<code bash> 
-sudo chown www-data:www-data /var/log/mod_evasive/ 
-</code> 
- 
- 
-===== Create mod-evasive.conf file and configure ModEvasive ===== 
- 
-Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo vi /etc/apache2/mods-available/mod-evasive.conf 
-</code> 
- 
-and add the following, changing the email value, and other options below as required: 
- 
-<file bash /etc/apache2/mods-available/mod-evasive.conf> 
-<ifmodule mod_evasive20.c> 
-   DOSHashTableSize 3097 
-   DOSPageCount  2 
-   DOSSiteCount  50 
-   DOSPageInterval 1 
-   DOSSiteInterval  1 
-   DOSBlockingPeriod  10 
-   DOSLogDir   /var/log/mod_evasive 
-   DOSEmailNotify  EMAIL@DOMAIN.com 
-   DOSWhitelist   127.0.0.1 
-</ifmodule> 
-</file> 
- 
- 
-===== Fix mod-evasive email bug ===== 
- 
-Because of [[https://bugs.launchpad.net/ubuntu/+source/libapache-mod-evasive/+bug/605679|this bug]] mod-evasive does not send emails on Ubuntu 12.04. 
- 
-A temporary workaround is to create a symlink to the mail program. 
- 
-Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo ln -s /etc/alternatives/mail /bin/mail/ 
-</code> 
- 
- 
-===== Check if ModEvasive is enabled and restart Apache ===== 
- 
-Before restarting Apache2 check if the module has been loaded. 
- 
-Open the Terminal Window and enter: 
- 
-<code bash> 
-sudo a2enmod mod-evasive 
-</code> 
- 
-Then restart the Apache2 webserver: 
- 
-<code bash> 
-sudo /etc/init.d/apache2 restart 
-</code> 
- 
-or 
- 
-<code bash> 
-service apache2 restart 
-</code> 
  
apache/install_mod_security_and_mod_evasive.1468333708.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki