Install ModSecurity 3 & OWASP Core Rule Set with Apache (HTTPD) on Fedora Linux 35

ModSecurity, often referred to as Modsec, is a free, open-source web application firewall (WAF). ModSecurity was created as a module for the Apache HTTP Server. However, since its early days, the WAF has grown and now covers an array of HyperText Transfer Protocol request and response filtering capabilities for various platforms such as Microsoft IIS, Nginx, and Apache.

How the WAF works, the ModSecurity engine is deployed in front of the web application, allowing the engine to scan the incoming and outgoing HTTP connections. ModSecurity is most commonly used in conjunction with the OWASP Core Rule Set (CRS), an open-source set of rules written in ModSecurity’s SecRules language and is highly regarded among the security industry.

OWASP Rule Set with ModSecurity can almost instantly help protect your server against:

  • Bad user agents
  • DDOS
  • Cross website scripting
  • SQL injection
  • Session hijacking
  • Other Threats

In the following tutorial, you will learn how to install ModSecurity with Apache on Fedora 35 Workstation or Server.

For further information on configuring Apache (HTTPD) on Fedora, visit How to Install Apache (HTTPD) on Fedora 35.

Prerequisites

  • Recommended OS: Fedora Linux 35.
  • User account: A user account with sudo or root access.

Update Operating System

Update your Fedora operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@fedora ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Fedora.

To use the root account, use the following command with the root password to log in.

su

Compile Apache (HTTPD) Modsecurity 3 Module

The first step is to compile the Modsecurity 3 module. This may seem daunting at first, but afterward, it becomes pretty easy to do and maintain. The benefit of compiling the ModSecurity 3 module is that any urgent updates come out, you can update your servers immediately instead of waiting for packages to be updated.

First, install the Apache (HTTPD) DEVEL package.

sudo dnf install httpd-devel -y

Next, you will download and compile the libmodsecurity3 is the fundamental part of the WAF that does the HTTP filtering for your web applications.

Clone ModSecurity Repsoitory from Github

The first step is the clone from Github, and if you do not have git installed, you will need to execute the following command:

sudo dnf install git -y

Next, clone the libmodsecurity3 GIT repository as follows:

git clone --depth 1 -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity /usr/local/src/ModSecurity/

Once cloned, you will need to CD to the directory:

cd /usr/local/src/ModSecurity/

Install libmodsecurity3 Dependencies

To compile, you will need to install the following dependencies as follows:

sudo dnf install gcc-c++ flex doxygen yajl-devel bison yajl curl-devel zlib-devel pcre-devel autoconf automake git curl make libxml2-devel pkgconfig libtool httpd-devel redhat-rpm-config wget openssl openssl-devel nano GeoIP-devel -y

Now to finish off, install the following GIT submodules as follows:

git submodule init

Then update the submodules:

git submodule update

Building the ModSecurity Environment

The next step is now actually to build the environment first. Use the following command:

./build.sh

Note, you will possibly see the following error

fatal: No names found, cannot describe anything.

This can be safely ignored and now move on to the next step.

Now run the configure command.

./configure

Compiling the ModSecurity Source Code

Now that you have built and configured the environment for libmodsecurity3, it is time to compile it with the command make.

make

A handy trick is to specify the -j <number of cpu> as this can significantly increase compiling speed if you have a powerful server. For example, the LinuxCapable server has 6 CPUs, and I can use all 6 or at least use 4 to 5 to increase speed.

Example only:

make -j 6

After compiling the source code, now run the installation command in your terminal:

sudo make install

Note, the installation is done in the /usr/local/modsecurity/, which you will reference later in the tutorial.

Install ModSecurity-apache Connector

The ModSecurity-apache connector is the connection point between Apache and libmodsecurity. It is the component that communicates between Apache and ModSecurity (libmodsecurity3).

Clone ModSecurity-apache Repsoitory from Github

Similar to the previous step cloning the libmodsecurity3 repository, you will need to clone the connector repository again using the following command:

git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-apache.git /usr/local/src/ModSecurity-apache/

Install ModSecurity-apache Connector

Next, CD directory into the apache connector cloned directory as follows:

cd /usr/local/src/ModSecurity-apache/

First, run the following command.

./autogen.sh

Next, you will compile the ModSecurity-apache Connector module.

./configure --with-libmodsecurity=/usr/local/src/ModSecurity/

Now make (create) the dynamic modules with the following command:

make

Finally, use the make install command to complete the compile process.

sudo make install

Note, this will save the Apache connection to the path /usr/lib64/httpd/modules/mod_security3.so.

Setup Modsecurity 3 in Apache (HTTPD)

Now that you have compiled the module required, you now need to proceed to enable, configure and test the module in Apache before downloading and installing any rule sets.

Enable Modsecurity Module

The first step, create the following file using any text editor. The tutorial will use nano.

sudo nano /etc/httpd/conf/httpd.conf

Next, add the following to the end of the file.

LoadModule security3_module /usr/lib64/httpd/modules/mod_security3.so

Next, use CTRL+O then CTRL+X to save and exit the file.

Create and Configure Directory and Files for ModSecurity

You will need to create a directory to store the configuration files and future rules, OWASP CRS for the tutorial.

Use the following command to create the /etc/httpd/modsec/ directory as follows:

sudo mkdir /etc/httpd/modsec/

Now, you need to copy the sample ModSecurity configuration file back from our cloned GIT directory:

sudo cp /usr/local/src/ModSecurity/modsecurity.conf-recommended /etc/httpd/modsec/modsecurity.conf

Using your favorite text editor, open the modsecurity.conf file as follows:

sudo nano /etc/httpd/modsec/modsecurity.conf

By default, ModSecurity configuration has the rule engine specified as (DetectionOnly), which in other words, runs ModSecurity and detects all malicious behavior but does not action blocks or bans and logs all the HTTP transactions that it flags. This should only be used if you have lots of false positives or have increased the security level settings to an extreme level and testing to see if any false positives occur.

To change this behavior to (on), find the following on line 7:

SecRuleEngine DetectionOnly

Change the line to this to enable ModSecurity:

SecRuleEngine On

Now save the modsecurity.conf file using (CTRL+O) then exit (CTRL+X).

The next part is to create the following file modsec-config.conf. Here you will add the modsecurity.conf file along and later on other rules such as OWASP CRS, and if you are using WordPress, the WPRS CRS rule set.

Use the following command to create the file and open it:

sudo nano /etc/httpd/modsec/modsec-config.conf

Once inside the file, add the following line:

Include /etc/httpd/modsec/modsecurity.conf

Save the modsec-config.conf file with (CTRL+O) then (CTRL+X) exit.

Next, copy ModSecurity’s unicode.mapping file with the CP command as follows:

sudo cp /usr/local/src/ModSecurity/unicode.mapping /etc/httpd/modsec/

Before you restart the Apache service, you must enable Modsecurity on your virtual host. Open up the file location, and add the following lines.

modsecurity on;
modsecurity_rules_file /etc/httpd/modsec/modsec-config.conf;

Example configuration only:

<Directory "/var/www/html/">
    modsecurity on
    modsecurity_rules_file /etc/httpd/modsec/modsec-config.conf
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

To make the changes live, restart your service using the systemctl command:

sudo systemctl restart httpd

Install OWASP Core Rule Set for ModSecurity

ModSecurity on its own does not protect your webserver, and you need to have rules. One of the most famous, respected, and well-known rules is the OWASP CRS rule set. The rules are the most widely used amongst web servers and other WAFs, and most other similar systems base most of their rules off this CRS. Installing this ruleset will automatically give you a great source of protection against most emerging threats on the Internet by detecting malicious actors and blocking them.

Using the wget command, download the OWASP CRS 3.3.2 archive as follows:

wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v3.3.2.zip

For those that want to live on the edge, you can download the nightly build. Only use the nightly if you are prepared to keep re-compiling and checking the CoreRuleSet Github frequently for updates and be more confident at figuring out issues. Technically the nightly can be more secure but potentially can create problems.

For novice users, use the stable version and do not use the below version.

wget https://github.com/coreruleset/coreruleset/archive/refs/tags/nightly.zip

Install the Unzip package if you do not have this installed on your server:

sudo dnf install unzip -y

Now unzip the master.zip archive as follows:

sudo unzip v3.3.2.zip -d /etc/httpd/modsec/

As to before, like the modsecurity.conf sample configuration, OWASP CRS comes with a sample configuration file that you need to rename. It is best to use the CP command and keep a backup for the future in case you need to restart again.

sudo cp /etc/httpd/modsec/coreruleset-3.3.2/crs-setup.conf.example /etc/httpd/modsec/coreruleset-3.3.2/crs-setup.conf

To enable the rules, open the /etc/httpd/modsec/modsec-config.conf using any text editor again:

sudo nano /etc/httpd/modsec/modsec-config.conf

Once inside the file again, add the following two additional lines:

Include /etc/httpd/modsec/coreruleset-3.3.2/crs-setup.conf
Include /etc/httpd/modsec/coreruleset-3.3.2/rules/*.conf

Save the file (CTRL+O) and exit (CTRL+T).

Restart your Apache service to make the changes live as follows:

sudo systemctl restart httpd

Using and Understanding OWASP CRS

OWASP core rule has quite a lot of options, the default settings, however, out of the box, will protect most servers immediately without hurting your natural visitors and good SEO bots. Below, some areas will be covered to help explain. Further reading would be best to investigate all the options in the configuration files themselves as they have quite a bit of text data to explain what they are.

Open up your CRS-setup.conf file as follows:

sudo nano /etc/httpd/modsec/coreruleset-3.3.2/crs-setup.conf

Note, this is the dev version configuration with additional items compared to version 3.3.

From here, you can modify most of your OWASP CRS settings.

OWASP CRS Scoring

To break it down, ModSecurity has two modes:

Anomaly Scoring Mode

# -- [[ Anomaly Scoring Mode (default) ]] --
# In CRS3, anomaly mode is the default and recommended mode, since it gives the
# most accurate log information and offers the most flexibility in setting your
# blocking policies. It is also called "collaborative detection mode".
# In this mode, each matching rule increases an 'anomaly score'.
# At the conclusion of the inbound rules, and again at the conclusion of the
# outbound rules, the anomaly score is checked, and the blocking evaluation
# rules apply a disruptive action, by default returning an error 403.

Self-Contained Mode

# -- [[ Self-Contained Mode ]] --
# In this mode, rules apply an action instantly. This was the CRS2 default.
# It can lower resource usage, at the cost of less flexibility in blocking policy
# and less informative audit logs (only the first detected threat is logged).
# Rules inherit the disruptive action that you specify (i.e. deny, drop, etc).
# The first rule that matches will execute this action. In most cases this will
# cause evaluation to stop after the first rule has matched, similar to how many
# IDSs function.

Anomaly Scoring is generally for most users the best mode to use.

There are four paranoia levels:

  • Paranoia Level 1 – Default level and recommended for most users.
  • Paranoia Level 2 – Advanced users only.
  • Paranoia Level 3 – Expert users only.
  • Paranoia Level 4 – Not recommended at all, except for exceptional circumstances.
# -- [[ Paranoia Level Initialization ]] ---------------------------------------
#
# The Paranoia Level (PL) setting allows you to choose the desired level
# of rule checks that will add to your anomaly scores.
#
# With each paranoia level increase, the CRS enables additional rules
# giving you a higher level of security. However, higher paranoia levels
# also increase the possibility of blocking some legitimate traffic due to
# false alarms (also named false positives or FPs). If you use higher
# paranoia levels, it is likely that you will need to add some exclusion
# rules for certain requests and applications receiving complex input.
#
# - A paranoia level of 1 is default. In this level, most core rules
#   are enabled. PL1 is advised for beginners, installations
#   covering many different sites and applications, and for setups
#   with standard security requirements.
#   At PL1 you should face FPs rarely. If you encounter FPs, please
#   open an issue on the CRS GitHub site and don't forget to attach your
#   complete Audit Log record for the request with the issue.
# - Paranoia level 2 includes many extra rules, for instance enabling
#   many regexp-based SQL and XSS injection protections, and adding
#   extra keywords checked for code injections. PL2 is advised
#   for moderate to experienced users desiring more complete coverage
#   and for installations with elevated security requirements.
#   PL2 comes with some FPs which you need to handle.
# - Paranoia level 3 enables more rules and keyword lists, and tweaks
#   limits on special characters used. PL3 is aimed at users experienced
#   at the handling of FPs and at installations with a high security
#   requirement.
# - Paranoia level 4 further restricts special characters.
#   The highest level is advised for experienced users protecting
#   installations with very high security requirements. Running PL4 will
#   likely produce a very high number of FPs which have to be
#   treated before the site can go productive.
#
# All rules will log their PL to the audit log;
# example: [tag "paranoia-level/2"]. This allows you to deduct from the
# audit log how the WAF behavior is affected by paranoia level.
#
# It is important to also look into the variable
# tx.enforce_bodyproc_urlencoded (Enforce Body Processor URLENCODED)
# defined below. Enabling it closes a possible bypass of CRS.

Test OWASP CRS on your Server

To test if OWASP rules are working on your server, open up your Internet Browser and use the following:

https://www.yourdomain.com/index.html?exec=/bin/bash

You should receive a 403 forbidden error. If not, then a step has been missed.

The most common problem is missing to change DetectionOnly to On, as covered earlier in the tutorial.

Example:

How to Install ModSecurity 3 & OWASP Core Rule Set with Apache (HTTPD) on Fedora 35

To confirm further, print out the last 20 lines from the /var/log/modsec_audit.log. Remember to change the path if you have modified the location.

tail -f /var/log/modsec_audit.log -n 20

Example output:

/var/log/modsec_audit.log
[joshua@fedora ~]$ tail -f /var/log/modsec_audit.log 
ModSecurity: Warning. Matched "Operator `Rx' with parameter `^[\d.:]+$' against variable `REQUEST_HEADERS:Host' (Value: `127.0.0.1' ) [file "/etc/httpd/modsec/coreruleset-3.3.2/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "718"] [id "920350"] [rev ""] [msg "Host header is a numeric IP address"] [data "127.0.0.1"] [severity "4"] [ver "OWASP_CRS/3.3.2"] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/210/272"] [tag "PCI/6.5.10"] [hostname "fe80::654b:1260:d130:95f1%ens33"] [uri "/index.html"] [unique_id "1642052773"] [ref "o0,9v46,9"]
ModSecurity: Warning. Matched "Operator `PmFromFile' with parameter `unix-shell.data' against variable `ARGS:exec' (Value: `/bin/bash' ) [file "/etc/httpd/modsec/coreruleset-3.3.2/rules/REQUEST-932-APPLICATION-ATTACK-RCE.conf"] [line "480"] [id "932160"] [rev ""] [msg "Remote Command Execution: Unix Shell Code Found"] [data "Matched Data: bin/bash found within ARGS:exec: /bin/bash"] [severity "2"] [ver "OWASP_CRS/3.3.2"] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-shell"] [tag "platform-unix"] [tag "attack-rce"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/152/248/88"] [tag "PCI/6.5.2"] [hostname "fe80::654b:1260:d130:95f1%ens33"] [uri "/index.html"] [unique_id "1642052773"] [ref "o1,8v21,9t:urlDecodeUni,t:cmdLine,t:normalizePath,t:lowercase"]
ModSecurity: Access denied with code 403 (phase 2). Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `8' ) [file "/etc/httpd/modsec/coreruleset-3.3.2/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "80"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 8)"] [data ""] [severity "2"] [ver "OWASP_CRS/3.3.2"] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "fe80::654b:1260:d130:95f1%ens33"] [uri "/index.html"] [unique_id "1642052773"] [ref ""]

---oz52491W---I--

---oz52491W---J--

---oz52491W---Z--

Dealing with False Positives & Custom Rules Exclusion

One of the often never-ending tasks is dealing with false positives, ModSecurity and OWASP CRS do a great job together, but it comes at the cost of your time, but given the protection, you get it is worth it. For starters, never putting the paranoia level up high to start with is the golden rule.

A good rule of thumb is to run the rule set for a few weeks to months with hardly any false positives, then increase, for example, paranoia level 1 to paranoia level 2, so you are not swamped with a ton simultaneously.

Excluding False Positives known Applications

Modsecurity, by default, can whitelist everyday actions that lead to false positives as below:

#SecAction \
# "id:900130,\
#  phase:1,\
#  nolog,\
#  pass,\
#  t:none,\
#  setvar:tx.crs_exclusions_cpanel=1,\
#  setvar:tx.crs_exclusions_dokuwiki=1,\
#  setvar:tx.crs_exclusions_drupal=1,\
#  setvar:tx.crs_exclusions_nextcloud=1,\
#  setvar:tx.crs_exclusions_phpbb=1,\
#  setvar:tx.crs_exclusions_phpmyadmin=1,\
#  setvar:tx.crs_exclusions_wordpress=1,\
#  setvar:tx.crs_exclusions_xenforo=1"

To enable, for example, WordPress, phpBB, and phpMyAdmin as you use all three, uncomment the lines and leave the (1) number intact, change the other services you do not use, for instance, Xenforo to (0) as you do not want to whitelist these rules. Example below:

SecAction \
"id:900130,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.crs_exclusions_cpanel=0,\
setvar:tx.crs_exclusions_dokuwiki=0,\
setvar:tx.crs_exclusions_drupal=0,\
setvar:tx.crs_exclusions_nextcloud=0,\
setvar:tx.crs_exclusions_phpbb=1,\
setvar:tx.crs_exclusions_phpmyadmin=1,\
setvar:tx.crs_exclusions_wordpress=1,\
setvar:tx.crs_exclusions_xenforo=0"

You can also modify the syntax, which would be cleaner. For example:

SecAction \
"id:900130,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.crs_exclusions_phpbb=1,\
setvar:tx.crs_exclusions_phpmyadmin=1,\
setvar:tx.crs_exclusions_wordpress=1"

As you can see, removed are the options not needed, and added (“) at the end of WordPress for correct syntax.

Excluding Rules in Before CRS

To deal with custom exclusions, firstly, you need to change the name from the REQUEST-900-EXCLUSION-RULES-BEFORE-CRS-SAMPLE.conf file with the cp command as follows:

sudo cp /etc/httpd/modsec/coreruleset-3.4-dev/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example /etc/httpd/modsec/coreruleset-3.4-dev/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf

A point to remember, when creating exclusion rules, each one must have id:<rule number> and be unique, or else when your test your Apache service, you will get an error. Example “id:1544,phase:1,log,allow,ctl:ruleEngine=off”, the id 1544 cannot be used for a second rule.

For example, some REQUEST_URI’s will raise false positives. The example below is two with Google pagespeed beacon and WMUDEV plugin for WordPress:

SecRule REQUEST_URI "@beginsWith /wp-load.php?wpmudev" "id:1544,phase:1,log,allow,ctl:ruleEngine=off"
SecRule REQUEST_URI "@beginsWith /ngx_pagespeed_beacon" "id:1554,phase:1,log,allow,ctl:ruleEngine=off"

As you can see, any URL that begins with the path will be automatically allowed.

Another option is to whitelist IP addresses, a few ways you can go about this:

SecRule REMOTE_ADDR "^195\.151\.128\.96" "id:1004,phase:1,nolog,allow,ctl:ruleEngine=off"

## or ###

SecRule REMOTE_ADDR "@ipMatch 127.0.0.1/8, 195.151.0.0/24, 196.159.11.13" "phase:1,id:1313413,allow,ctl:ruleEngine=off"

The @ipMatch can be used more extensively for subnets. If you want to deny a subnet or IP address change, allow to deny. With some know-how, you can also create blacklists and whitelists and configure this with fail2ban. The possibilities can often be endless.

One last example is to disable only rules that trigger false positives, not blanket whitelisting the entire path, as you saw with the first REQUEST_URI example. However, this takes more time and testing. For instance, you want to remove rules 941000 and 942999 from your /admin/ area as it keeps triggering false bans and blocks for your team, find in your modsecurity logs file the rule ID and then disable only that ID with RemoveByID as the example below:

SecRule REQUEST_FILENAME "@beginsWith /admin" "id:1004,phase:1,pass,nolog,ctl:ruleRemoveById=941000-942999"

Examples can be found on the ModSecurity GIT wiki page; LinuxCapable will, in the future, create a tutorial on this part as there is quite a lot to cover.

Optional – Include Project Honeypot

Project Honey Pot is the first and only distributed system for identifying spammers and the spambots they use to scrape addresses from your website. Using the Project Honey Pot system, you can install custom-tagged addresses to the time and IP address of a visitor to your site. If one of these addresses begins receiving email, we can tell that the messages are spam, the exact moment when the address was harvested, and the IP address that gathered it.

ModSecurity can have the option to integrate Project Honeypot, which will query the database and block any addresses that are on the HoneyPot blacklist. Note, using this can lead to false positives, but overall it is considered very reliable compared to similar alternatives.

Step 1. Create an account a free account.

Step 2. Once you have signed up and logged in, on the dashboard, find the line (Your http:BL API key) and click get one.

How to Install ModSecurity 3 & OWASP Core Rule Set with Apache (HTTPD) on Fedora 35

Step 3. Go back to the CRS-setup.conf file by opening it using a text editor:

sudo nano /etc/httpd/modsec/coreruleset-3.3.2/crs-setup.conf

Step 4. Find the line starting with #SecHttpBlKey, which is on line 629.

#SecHttpBlKey XXXXXXXXXXXXXXXXX
#SecAction "id:900500,\
#  phase:1,\
#  nolog,\
#  pass,\
#  t:none,\
#  setvar:tx.block_search_ip=1,\
#  setvar:tx.block_suspicious_ip=1,\
#  setvar:tx.block_harvester_ip=1,\
#  setvar:tx.block_spammer_ip=1"

Step 5. Change the SecHttpBlKey XXXXXXXXXXXXXXXXX with your key from Project HoneyPot.

Example:

SecHttpBlKey amhektvkkupe

Step 6. Next, uncomment all the lines to enable the rule. If you want to deactivate a rule, instead of (1), put (0) instead to disable the Project Honeypot scan option.

By default, block_search_ip=0 is for search engine bots, do not enable this unless you wish Bing, Google, and other good bots coming to your site.

SecHttpBlKey amhektvkkupe
SecAction "id:900500,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.block_search_ip=0,\
setvar:tx.block_suspicious_ip=1,\
setvar:tx.block_harvester_ip=1,\
setvar:tx.block_spammer_ip=1"

Note, do not use amhektvkkupe. Use your key instead!

Step 7. Restart Apache (HTTPD) service.

sudo systemctl restart httpd

WordPress WPRS Rule Set for ModSecurity

Another option for WordPress users is to install and run alongside your OWASP CRS rule set, a well-known project entitled WPRS rule set. As this is optional and isn’t for everyone, the tutorial will not cover it in this section. However, if you would like to install this for extra protection if you use WordPress on your server, please visit our tutorial on Installing WordPress ModSecurity Rule Set (WPRS).

Create ModSecurity LogRotate file:

Given how many lines and information it can log, ModSecurity will grow quite quickly. As you are compiling the module and it isn’t installed through any official repository, you will need to create your own log rotate file.

First, create and open your ModSecurity rotate file modsec:

sudo nano /etc/logrotate.d/modsec

Add the following code:

/var/log/modsec_audit.log
{
        rotate 31
        daily
        missingok
        compress
        delaycompress
        notifempty
}

This will keep logs for 31 days. If you prefer to have less, change 31 to say 7 days equally a week’s worth of logs. You should be rotating daily for ModSecurity. If you need to review the log files having a weekly file will be a disaster to sift through, given how large it will be.

Comments and Conclusion

In the tutorial, you understand compiling, installing, and enabling ModSecurity 3 and setting up the OWASP Core Rule Set amongst the top parts. Overall, deploying ModSecurity to your server will provide instant protection. However, patience, time, and dedication to learning will be a great security feature. The last thing you want is to block SEO bots or, more importantly, real users that could be potential customers.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!