{"id":914,"date":"2018-12-03T05:25:55","date_gmt":"2018-12-03T05:25:55","guid":{"rendered":"http:\/\/orissawebhosting.in\/blog\/?p=914"},"modified":"2019-06-27T12:40:15","modified_gmt":"2019-06-27T12:40:15","slug":"how-to-install-modsecurity-on-apache-for-centos-7","status":"publish","type":"post","link":"https:\/\/orissawebhosting.in\/blog\/how-to-install-modsecurity-on-apache-for-centos-7\/","title":{"rendered":"How to install ModSecurity on Apache for CentOS 7"},"content":{"rendered":"<h4 class=\"entry-title\">ModSecurity\u00a0Introduction<\/h4>\n<p>ModSecurity is a toolkit for real-time web application monitoring, logging, and access control. you can consider it as an enabler, there are no hard rules telling you what to do, instead, it is up to you to choose your own path through the available features.\u00a0The freedom to choose what to do is an essential part of ModSecurity\u2019s identity and goes very well with its open source nature. With full access to the source code, your freedom to choose extends to the ability to customize and extend the tool itself to make it fit your needs.<\/p>\n<h4>Install ModSecurity<\/h4>\n<pre><code class=\"prefixed\">yum install mod_security<\/code><\/pre>\n<p>Verify if the ModSecurity module was loaded with your Apache:<\/p>\n<pre><code class=\"prefixed\">apachectl\u00a0-M | grep --color sec<\/code><\/pre>\n<p>You should see a module named \u201csecurity2_module (shared)\u201d which indicates that the module was loaded.<\/p>\n<p>The installation includes a recommended configuration file which has to be renamed with the command below:<\/p>\n<pre><code class=\"prefixed\">mv \/etc\/modsecurity\/modsecurity.conf{-recommended,}<\/code><\/pre>\n<p>Restart Apache:<\/p>\n<pre><code class=\"prefixed\">systemctl restart apache2<\/code> systemctl restart httpd<\/pre>\n<h4>Configuring ModSecurity<\/h4>\n<p>If you want to add rules or edit some existing rules you should open the \u201cmodsecurity.conf\u201d and make changes. Here we are going to point to some common rules and configurations:<\/p>\n<pre><code class=\"prefixed\">vi \/etc\/modsecurity\/modsecurity.conf<\/code><\/pre>\n<p>Find\u00a0the following line:<\/p>\n<pre><code>SecRuleEngine DetectionOnly<\/code><\/pre>\n<p>And change it like below:<\/p>\n<pre><code>SecRuleEngine On<\/code><\/pre>\n<p>Another directive to modify is \u201cSecResponseBodyAccess\u201d This configures whether response bodies are buffered. This is only necessary if data leakage detection and protection is required. Therefore, leaving it On will use up servers resources and also increase the log file size.<\/p>\n<p>Find the following line:<\/p>\n<pre><code>SecResponseBodyAccess On<\/code><\/pre>\n<p>And turn it off like below:<\/p>\n<pre><code>SecResponseBodyAccess Off<\/code><\/pre>\n<p>We also can limit the maximum data that can be posted to your web application:<\/p>\n<pre><code>SecRequestBodyLimit\nSecRequestBodyNoFilesLimit<\/code><\/pre>\n<p>The \u201cSecRequestBodyLimit\u201d specifies the maximum post data size. If anything larger is sent by a client the server will respond with a \u201c413 Request Entity Too Large\u201d error. If your web application doesn\u2019t have any file uploads this value can be greatly reduced.<\/p>\n<p>The default value of the configuration file is:<\/p>\n<p><a href=\"http:\/\/orissawebhosting.in\/blog\/how-to-use-rsync-to-sync-with-a-remote-system\/\">Click here<\/a><\/p>\n<pre><code>\n<\/code><\/pre>\n<h4>Rule-Set Recommendation<\/h4>\n<p>You can also use free ModSecurity \u00a0rules\u00a0provided by Cybersecurity companies like\u00a0Comodo.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ModSecurity\u00a0Introduction ModSecurity is a toolkit for real-time web application monitoring, logging, and access control. you can consider it as an enabler, there are no hard rules telling you what to do, instead, it is up to you to choose your own path through the available features.\u00a0The freedom to choose what to do is an essential part of ModSecurity\u2019s identity and goes very well with its open source nature. With full access to the source code, your freedom to choose extends to the ability to customize and extend the tool itself&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/914"}],"collection":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=914"}],"version-history":[{"count":7,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/914\/revisions"}],"predecessor-version":[{"id":952,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/914\/revisions\/952"}],"wp:attachment":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}