apache:install_mod_security_and_mod_evasive
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
apache:install_mod_security_and_mod_evasive [2016/10/12 21:58] – peter | apache: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 ====== | ||
- | |||
- | **ModSecurity** is a toolkit for real-time web application monitoring, logging, and access control. | ||
- | |||
- | ===== Install ModSecurity ===== | ||
- | |||
- | To install [[http:// | ||
- | |||
- | Install the dependencies. | ||
- | |||
- | <code bash> | ||
- | sudo apt-get install libxml2 libxml2-dev libxml2-utils | ||
- | sudo apt-get install libaprutil1 libaprutil1-dev | ||
- | </ | ||
- | |||
- | **NOTE**: | ||
- | |||
- | <code bash> | ||
- | ln -s / | ||
- | </ | ||
- | |||
- | |||
- | Install ModSecurity: | ||
- | |||
- | <code bash> | ||
- | sudo apt-get install libapache-mod-security | ||
- | </ | ||
- | |||
- | |||
- | ===== Configure ModSecurity rules. ===== | ||
- | |||
- | Activate the recommended default rules to get things going. | ||
- | |||
- | <code bash> | ||
- | sudo mv / | ||
- | </ | ||
- | |||
- | The default folder for ModSecurity rules is **/ | ||
- | |||
- | 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. | ||
- | |||
- | This settings is very important as it limits the size of all files that can be uploaded to the server. | ||
- | |||
- | Execute the command: | ||
- | |||
- | <code bash> | ||
- | sudo vi / | ||
- | </ | ||
- | |||
- | First activate the rules by editing the **SecRuleEngine** option and set to On and modify your server signature. | ||
- | |||
- | <file bash / | ||
- | SecRuleEngine On | ||
- | SecServerSignature FreeOSHTTP | ||
- | </ | ||
- | |||
- | Edit the following to option to increase the request limit to 16 MB and save the file: | ||
- | |||
- | <file bash / | ||
- | SecRequestBodyLimit 16384000 | ||
- | SecRequestBodyInMemoryLimit 16384000 | ||
- | </ | ||
- | |||
- | |||
- | ===== Download and install the latest OWASP Core Rule Set ===== | ||
- | |||
- | The OWASP ModSecurity CRS Project' | ||
- | |||
- | Download and install the latest [[https:// | ||
- | |||
- | 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 the wget for master below with the a specific version you would like to use e.g : **v2.2.5**. | ||
- | | ||
- | Execute the following commands: | ||
- | |||
- | <code bash> | ||
- | cd /tmp | ||
- | sudo wget -O SpiderLabs-owasp-modsecurity-crs.tar.gz https:// | ||
- | sudo tar -zxvf SpiderLabs-owasp-modsecurity-crs.tar.gz | ||
- | sudo cp -R SpiderLabs-owasp-modsecurity-crs-*/ | ||
- | sudo rm SpiderLabs-owasp-modsecurity-crs.tar.gz | ||
- | sudo rm -R SpiderLabs-owasp-modsecurity-crs-* | ||
- | sudo mv / | ||
- | </ | ||
- | |||
- | |||
- | Create symbolic links to all activated base rules. | ||
- | |||
- | <code bash> | ||
- | cd / | ||
- | for f in * ; do sudo ln -s / | ||
- | |||
- | cd / | ||
- | for f in * ; do sudo ln -s / | ||
- | </ | ||
- | |||
- | |||
- | Add these rules to Apache2. | ||
- | |||
- | <code bash> | ||
- | sudo vi / | ||
- | </ | ||
- | |||
- | |||
- | Add the following to towards the end of the file with other includes and save the file: | ||
- | |||
- | <file bash / | ||
- | Include "/ | ||
- | </ | ||
- | |||
- | |||
- | ===== Check if ModSecurity is enabled and restart Apache ===== | ||
- | |||
- | Before restarting Apache2 check if the modules has been loaded. | ||
- | |||
- | Execute the following commands: | ||
- | |||
- | <code bash> | ||
- | sudo a2enmod headers | ||
- | sudo a2enmod mod-security | ||
- | </ | ||
- | |||
- | |||
- | Restart the Apache2 webserver: | ||
- | |||
- | <code bash> | ||
- | sudo /etc/init.d apache2 restart | ||
- | </ | ||
- | |||
- | or | ||
- | |||
- | <code bash> | ||
- | service apache2 restart | ||
- | </ | ||
- | |||
- | |||
- | ===== Install ModEvasive ===== | ||
- | |||
- | Install [[http:// | ||
- | |||
- | Execute the following: | ||
- | |||
- | <code bash> | ||
- | sudo apt-get install libapache2-mod-evasive | ||
- | </ | ||
- | |||
- | |||
- | ===== Create log file directory for mod_evasive ===== | ||
- | |||
- | Execute the following: | ||
- | |||
- | <code bash> | ||
- | sudo mkdir / | ||
- | </ | ||
- | |||
- | |||
- | Change the log folder permissions: | ||
- | |||
- | <code bash> | ||
- | sudo chown www-data: | ||
- | </ | ||
- | |||
- | |||
- | ===== Create mod-evasive.conf file and configure ModEvasive ===== | ||
- | |||
- | Execute the following: | ||
- | |||
- | <code bash> | ||
- | sudo vi / | ||
- | </ | ||
- | |||
- | Add the following, changing the email value, and other options below as required: | ||
- | |||
- | <file bash / | ||
- | < | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | </ | ||
- | </ | ||
- | |||
- | |||
- | ===== Fix mod-evasive email bug ===== | ||
- | |||
- | Because of [[https:// | ||
- | |||
- | A temporary workaround is to create a symlink to the mail program. | ||
- | |||
- | Execute the following: | ||
- | |||
- | <code bash> | ||
- | sudo ln -s / | ||
- | </ | ||
- | |||
- | |||
- | ===== Check if ModEvasive is enabled and restart Apache ===== | ||
- | |||
- | Before restarting Apache2 check if the module has been loaded. | ||
- | |||
- | Execute the following: | ||
- | |||
- | <code bash> | ||
- | sudo a2enmod mod-evasive | ||
- | </ | ||
- | |||
- | |||
- | Restart the Apache2 webserver: | ||
- | |||
- | <code bash> | ||
- | sudo / | ||
- | </ | ||
- | |||
- | or | ||
- | |||
- | <code bash> | ||
- | service apache2 restart | ||
- | </ | ||
apache/install_mod_security_and_mod_evasive.1476309532.txt.gz · Last modified: 2020/07/15 09:30 (external edit)