{"id":15798,"date":"2023-05-09T22:32:44","date_gmt":"2023-05-09T22:32:44","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=15798"},"modified":"2023-06-21T22:15:49","modified_gmt":"2023-06-21T22:15:49","slug":"how-to-install-mod_security-apache-module","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-mod_security-apache-module\/","title":{"rendered":"How to Install mod_security Apache Module"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-1024x840.png\" alt=\"secured server\" width=\"1024\" height=\"840\" class=\"alignnone size-large wp-image-15801 rounded shadow lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-1024x840.png 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-300x246.png 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-128x105.png 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-420x345.png 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-540x443.png 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-720x591.png 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-960x788.png 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-1140x936.png 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-1217x999.png 1217w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-877x720.png 877w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server-1316x1080.png 1316w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/secured-server.png 1472w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/840;\" \/><\/p>\n<p>Mod_security is an open-source web application firewall module that can be used to protect <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache web servers<\/a> from various attacks such as <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-a-ddos-attack\/\">DDoS<\/a>, SQL injection, cross-site scripting, and many more.<\/p>\n<p>Let&#8217;s say you have a web application that accepts user input and stores it in a database. An attacker can use SQL injection to execute malicious SQL statements and gain unauthorized access to your database. Without mod_security, your <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-are-web-servers-and-why-are-they-needed\/\">web server<\/a> would be vulnerable to this attack.<\/p>\n<p>However, with mod_security enabled and configured, it can detect and block SQL injection attacks. For example, if an attacker sends a malicious SQL statement in the user input, mod_security will detect it and block the request, preventing the SQL injection attack from succeeding.<\/p>\n<p>Here&#8217;s an example of a mod_security rule that can block SQL injection attacks:<\/p>\n<pre>\r\nSecRule REQUEST_FILENAME|ARGS|ARGS_NAMES|REQUEST_HEADERS \\\r\n    \"(?:\\b(?:(?:s(?:elect(?:\\s+.*?)?\\s+from|et(?:\\s+.*?)?\\s+)|\\\r\n    union(?:\\s+.*?)?\\s+select(?:\\s+.*?)?\\s+|\\\r\n    (?:create|alter|drop|truncate)(?:\\s+.*?)?\\s+table|\\\r\n    (?:insert(?:\\s+.*?)?\\s+into|update(?:\\s+.*?)?\\s+|\\\r\n    delete(?:\\s+.*?)?\\s+from)(?:\\s+.*?)?\\s+)\\b|\\b\\d+\\b)\" \\\r\n    \"id:'990012',phase:2,rev:'2.2.5',t:none,t:urlDecodeUni,t:lowercase,\\\r\n    msg:'SQL Injection Attack',logdata:'%{TX.0}',severity:'2',\\\r\n    setvar:'tx.msg=%{rule.msg}',setvar:tx.sql_injection_score=+%{tx.critical_anomaly_score},\\\r\n    setvar:tx.anomaly_score=+%{tx.critical_anomaly_score},setvar:tx.%{rule.id}-SQLi=%{matched_var_name}'\"\r\n<\/pre>\n<p>This rule will look for SQL injection attacks in the request headers, filenames, arguments, and argument names. If it detects a SQL injection attack, it will block the request and log the event.<\/p>\n<p>By using mod_security rules like this, you can protect your web server from various attacks and enhance its security.<\/p>\n<p>In this short how-to, we will go through the steps to install the mod_security Apache module on CentOS.<\/p>\n<h2>Step 1: Install mod_security Apache Module<\/h2>\n<p>Once you have installed the Apache web server, you can proceed with the installation of the mod_security Apache module. You can do this by using the following command:<\/p>\n<pre>\r\nsudo yum install mod_security\r\n<\/pre>\n<p>This will install the mod_security Apache module and its dependencies.<\/p>\n<h2>Step 2: Enable and Configure mod_security Apache Module<\/h2>\n<p>After installing the mod_security Apache module, you need to enable and configure it. You can do this by editing the Apache configuration file located at \/etc\/httpd\/conf\/httpd.conf. Open the file using a text editor such as Nano or Vim:<\/p>\n<pre>\r\nsudo nano \/etc\/httpd\/conf\/httpd.conf\r\n<\/pre>\n<p>Locate the following lines and uncomment them by removing the &#8216;#&#8217; symbol at the beginning of the lines:<\/p>\n<pre>\r\n#LoadModule security2_module modules\/mod_security2.so\r\n#Include conf.d\/mod_security.conf\r\n<\/pre>\n<p>Save and exit the file.<\/p>\n<p>Next, you need to configure the mod_security Apache module by creating a configuration file at \/etc\/httpd\/modsecurity.d\/modsecurity.conf. You can do this by using the following command:<\/p>\n<pre>\r\nsudo nano \/etc\/httpd\/modsecurity.d\/modsecurity.conf\r\n<\/pre>\n<p>Add the following lines to the file:<\/p>\n<pre>\r\nSecRuleEngine On\r\nSecRequestBodyAccess On\r\nSecResponseBodyAccess On\r\n<\/pre>\n<p>Save and exit the file.<\/p>\n<h2>Step 3: Restart Apache Web Server<\/h2>\n<p>After enabling and configuring the mod_security Apache module, you need to restart the Apache web server to apply the changes. You can do this by using the following command:<\/p>\n<pre>\r\nsudo service httpd restart\r\n<\/pre>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">sudo<\/span> &#8211; a command that allows users to run programs with the security privileges of another user, typically the superuser.<\/li>\n<li><span class=\"fw-bold\">yum<\/span> &#8211; a package manager for CentOS.<\/li>\n<li><span class=\"fw-bold\">httpd<\/span> &#8211; the Apache web server.<\/li>\n<li><span class=\"fw-bold\">mod_security<\/span> &#8211; an open-source web application firewall (WAF) module that can be used to protect Apache web servers from various attacks.<\/li>\n<li><span class=\"fw-bold\">nano<\/span> &#8211; a text editor for the terminal.<\/li>\n<li><span class=\"fw-bold\">service<\/span> &#8211; a command to control system services.<\/li>\n<\/ul>\n<h2>Conclusion:<\/h2>\n<p>In this guide, we have covered several important topics related to Linux system administration, including how to install Adobe Flash Player, create a file using the touch command, check the Linux system reboot date and time, check current users in Ubuntu, install the &#8220;man&#8221; command, install Wine on CentOS, and install the mod_security Apache module.<\/p>\n<p>By following these step-by-step guides, you can perform various tasks on your Linux system with ease, enhance its functionality, and improve its security. Moreover, by using commands such as &#8220;sudo&#8221;, &#8220;yum&#8221;, and various other Linux commands, you can execute these tasks with the necessary permissions and ensure that your system is secure.<\/p>\n<p>It is essential to understand and implement these commands and techniques to manage and secure your Linux system effectively. <\/p>\n<p>Interested in enhancing the security of your Apache web server and preventing DDoS attacks? Then you might be interested in reading my &#8220;<a href=\"https:\/\/webhostinggeeks.com\/blog\/8-easy-steps-to-safeguard-an-apache-web-server-and-prevent-ddos\/\">Prevent DDoS Attacks on Apache Guide<\/a>&#8220;. The guide provides 8 practical steps that you can take to secure your Apache web server and prevent DDoS attacks, including installing a web application firewall, configuring Apache modules, limiting access to sensitive information, and many more.<\/p>\n<p>If you have any questions or suggestions, feel free to comment below, and we will do our best to help you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mod_security is an open-source web application firewall module that can be used to protect Apache web servers from various attacks such as DDoS, SQL injection, cross-site scripting, and many more&#8230;.<\/p>\n","protected":false},"author":6,"featured_media":15801,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1103],"tags":[1199,2079,1576],"class_list":["post-15798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","tag-apache","tag-apache-module","tag-mod_security"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/15798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=15798"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/15798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/15801"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=15798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=15798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=15798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}