Use the ModSecurity Apache module on a cloud server with Ubuntu 16.04
ModSecurity is a free web application firewall (WAF) which is a simple, powerful way to protect a server against web-based malware and hacking attempts. Learn how to install ModSecurity and the officially-recommended OWASP Core Rule Set (CRS) which will protect a server against malware and hacking in the form of SQL injection, session hijacking, cross-site scripting, Trojans, and many other forms of web-based exploits.
- Unlimited traffic
- Fast SSD NVMe storage
- Free Plesk Web Host Edition
Requirements
- A Cloud Server running Linux (Ubuntu 16.04)
- Apache installed and running.
Apache is installed and running on a Standard installation by default. If your server was created with a Minimal installation, you will need to install and configure Apache before you proceed.
Install ModSecurity
Install the libapache2-modsecurity package:
Use apachectl -M | grep security to verify that the package has been installed. The server will respond with:
Create a directory for the ModSecurity rules:
Create a file for ModSecurity rules and open the file for editing:
Add the following to the file:
Save and exit the file. Then restart Apache for the changes to take effect:
Install and configure the OWASP Core Rule Set (CRS)
The OWASP Core Rule Set (CRS) extends the functionality of ModSecurity by providing a set of security rules to protect your server.
First, install the git package:
Go to the /etc/apache2 directory:
Download the OWASP installation files:
Move to the new OWASP directory:
Create a copy of the example setup file and rename it:
Open the main Apache configuration file for editing:
Scroll down to the section which reads:
Add the following two lines:
Save and exit the file. Then restart Apache for the changes to take effect:
- 99.9% uptime
- PHP 8.3 with JIT compiler
- SSL, DDoS protection, and backups
Verify that ModSecurity is installed and the OWASP CRS is loaded
You can test ModSecurity's OWASP CRS by visiting the URL:
Where example.com is replaced with your server's domain name or IP address.
You will be denied access with a 403: Forbidden error. Furthermore, this error will be noted in the /var/log/apache2/error.log file, with an entry similar to:
Update the OWASP Core Rule Set (CRS)
The OWASP CRS comes with a script you can run to update the rules with the latest version. To update OWASP:
If you run it now to test the command, it will respond with:
We recommend that you periodically run this script to update the OWASP CRS for the latest security patches.