{"id":12034,"date":"2019-03-21T03:59:55","date_gmt":"2019-03-21T03:59:55","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12034"},"modified":"2019-03-21T03:59:55","modified_gmt":"2019-03-21T03:59:55","slug":"protect-apache-against-brute-force-or-ddos-attacks-using-mod_security-and-mod_evasive-modules","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/21\/protect-apache-against-brute-force-or-ddos-attacks-using-mod_security-and-mod_evasive-modules\/","title":{"rendered":"Protect Apache Against Brute Force or DDoS Attacks Using Mod_Security and Mod_evasive Modules"},"content":{"rendered":"<p>For those of you in the hosting business, or if you\u2019re hosting your own servers and exposing them to the Internet, securing your systems against attackers must be a high priority.<\/p>\n<p><b>mod_security<\/b>\u00a0(an open source intrusion detection and prevention engine for web applications that integrates seamlessly with the web server) and\u00a0<b>mod_evasive<\/b>\u00a0are two very important tools that can be used to protect a web server against brute force or (D)DoS attacks.<\/p>\n<p><b>Read Also<\/b>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-linux-malware-detect-lmd-in-rhel-centos-and-fedora\/\" target=\"_blank\" rel=\"noopener\">How to Install Linux Malware Detect with ClamAV as Antivirus Engine<\/a><\/p>\n<p><b>mod_evasive<\/b>, as its name suggests, provides evasive capabilities while under attack, acting as an umbrella that shields web servers from such threats.<\/p>\n<div id=\"attachment_11270\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Mod_Security-Mod_evasive-in-CentOS.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11270\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Mod_Security-Mod_evasive-in-CentOS-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Mod_Security-Mod_evasive-in-CentOS-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Mod_Security-Mod_evasive-in-CentOS.jpg 720w\" alt=\"Install Mod_Security Mod_Evasive in CentOS\" width=\"620\" height=\"297\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Mod_Security and Mod_Evasive to Protect Apache<\/p>\n<\/div>\n<p><center><\/center>In this article we will discuss how to install, configure, and put them into play along with Apache on\u00a0<strong>RHEL<\/strong>\/<strong>CentOS 6<\/strong>\u00a0and\u00a0<strong>7<\/strong>\u00a0as well as\u00a0<strong>Fedora 21-15<\/strong>. In addition, we will simulate attacks in order to verify that the server reacts accordingly.<\/p>\n<p>This assumes that you have a LAMP server installed on your system. If not, please check this article before proceeding further.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-lamp-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">Install LAMP stack in RHEL\/CentOS 7<\/a><\/li>\n<\/ol>\n<p>You will also need to setup\u00a0<strong>iptables<\/strong>\u00a0as the default firewall front-end instead of\u00a0<a href=\"https:\/\/www.tecmint.com\/configure-firewalld-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">firewalld<\/a>\u00a0if you\u2019re running RHEL\/CentOS 7 or Fedora 21. We do this in order to use the same tool in both\u00a0<strong>RHEL<\/strong>\/<strong>CentOS 7<\/strong>\/<strong>6<\/strong>\u00a0and\u00a0<strong>Fedora 21<\/strong>.<\/p>\n<h3>Step 1: Installing Iptables Firewall on RHEL\/CentOS 7 and Fedora 21<\/h3>\n<p>To begin, stop and disable\u00a0<b>firewalld<\/b>:<\/p>\n<pre># systemctl stop firewalld\r\n# systemctl disable firewalld\r\n<\/pre>\n<div id=\"attachment_11259\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Disable-Firewalld-Service.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11259\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Disable-Firewalld-Service-620x251.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Disable-Firewalld-Service-620x251.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Disable-Firewalld-Service.png 621w\" alt=\"Disable Firewalld Service in CentOS 7\" width=\"620\" height=\"251\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Disable Firewalld Service<\/p>\n<\/div>\n<p>Then install the\u00a0<b>iptables-services<\/b>\u00a0package before enabling\u00a0<b>iptables<\/b>:<\/p>\n<pre># yum update &amp;&amp; yum install iptables-services\r\n# systemctl enable iptables\r\n# systemctl start iptables\r\n# systemctl status iptables\r\n<\/pre>\n<div id=\"attachment_11260\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Iptables-Firewall.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11260\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Iptables-Firewall-620x170.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Iptables-Firewall-620x170.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Install-Iptables-Firewall.png 895w\" alt=\"Install Iptables Firewall in CentOs 7\" width=\"620\" height=\"170\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Iptables Firewall<\/p>\n<\/div>\n<h3>Step 2: Installing Mod_Security and Mod_evasive<\/h3>\n<p>In addition to having a LAMP setup already in place, you will also have to\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">enable the EPEL repository<\/a>\u00a0in\u00a0<strong>RHEL<\/strong>\/<strong>CentOS 7<\/strong>\/<strong>6<\/strong>\u00a0in order to install both packages. Fedora users don\u2019t need to enable any repo, because epel is a already part of Fedora project.<\/p>\n<pre># yum update &amp;&amp; yum install mod_security mod_evasive\r\n<\/pre>\n<p>When the installation is complete, you will find the configuration files for both tools in\u00a0<b>\/etc\/httpd\/conf.d<\/b>.<\/p>\n<pre># ls -l \/etc\/httpd\/conf.d\r\n<\/pre>\n<div id=\"attachment_11261\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/mod_security-mod_evasive-Configurations.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11261\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/mod_security-mod_evasive-Configurations.png\" alt=\"mod_security + mod_evasive Configurations\" width=\"494\" height=\"193\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">mod_security + mod_evasive Configurations<\/p>\n<\/div>\n<p>Now, in order to integrate these two modules with\u00a0<b>Apache<\/b>\u00a0and have it load them when it starts, make sure the following lines appear in the top level section of\u00a0<b>mod_evasive.conf<\/b>\u00a0and\u00a0<b>mod_security.conf<\/b>, respectively:<\/p>\n<pre>LoadModule evasive20_module modules\/mod_evasive24.so\r\nLoadModule security2_module modules\/mod_security2.so\r\n<\/pre>\n<p>Note that\u00a0<b>modules\/mod_security2.so<\/b>\u00a0and\u00a0<b>modules\/mod_evasive24.so<\/b>\u00a0are the relative paths, from the\u00a0<b>\/etc\/httpd<\/b>\u00a0directory to the source file of the module. You can verify this (and change it, if needed) by listing the contents of the\u00a0<b>\/etc\/httpd\/modules<\/b>\u00a0directory:<\/p>\n<pre># cd \/etc\/httpd\/modules\r\n# pwd\r\n# ls -l | grep -Ei '(evasive|security)'\r\n<\/pre>\n<div id=\"attachment_11262\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Verify-mod_security-mod_evasive-Modules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11262\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Verify-mod_security-mod_evasive-Modules.png\" alt=\"Verify mod_security + mod_evasive Modules\" width=\"503\" height=\"110\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify mod_security + mod_evasive Modules<\/p>\n<\/div>\n<p>Then restart Apache and verify that it loads\u00a0<b>mod_evasive<\/b>\u00a0and\u00a0<b>mod_security<\/b>:<\/p>\n<pre># service httpd restart \t\t[On RHEL\/CentOS 6 and Fedora 20-18]\r\n# systemctl restart httpd \t\t[On RHEL\/CentOS 7 and Fedora 21]<\/pre>\n<pre>[Dump a list of loaded Static and Shared Modules]\r\n\r\n# httpd -M | grep -Ei '(evasive|security)'\t\t\t\t\r\n<\/pre>\n<div id=\"attachment_11263\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Check-mod_security-mod_evasive-Loaded.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11263\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Check-mod_security-mod_evasive-Loaded.png\" alt=\"Check mod_security + mod_evasive Modules Loaded\" width=\"537\" height=\"128\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check mod_security + mod_evasive Modules Loaded<\/p>\n<h3>Step 3: Installing A Core Rule Set and Configuring Mod_Security<\/h3>\n<p>In few words, a\u00a0<b>Core Rule Set<\/b>\u00a0(aka\u00a0<b>CRS<\/b>) provides the web server with instructions on how to behave under certain conditions. The developer firm of\u00a0<b>mod_security<\/b>\u00a0provide a free\u00a0<b>CRS<\/b>\u00a0called\u00a0<b>OWASP<\/b>\u00a0(<a href=\"https:\/\/www.owasp.org\/index.php\/Category:OWASP_ModSecurity_Core_Rule_Set_Project\" target=\"_blank\" rel=\"noopener\">Open Web Application Security Project<\/a>) ModSecurity CRS that can be downloaded and installed as follows.<\/p>\n<p><strong>1.<\/strong>\u00a0Download the\u00a0<b>OWASP CRS<\/b>\u00a0to a directory created for that purpose.<\/p>\n<pre># mkdir \/etc\/httpd\/crs-tecmint\r\n# cd \/etc\/httpd\/crs-tecmint\r\n# wget https:\/\/github.com\/SpiderLabs\/owasp-modsecurity-crs\/tarball\/master\r\n<\/pre>\n<div id=\"attachment_11264\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Download-mod_security-Core-Rules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11264\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Download-mod_security-Core-Rules-620x258.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Download-mod_security-Core-Rules-620x258.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Download-mod_security-Core-Rules.png 924w\" alt=\"Download mod_security Core Rules\" width=\"620\" height=\"258\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Download mod_security Core Rules<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0Untar the\u00a0<b>CRS<\/b>\u00a0file and change the name of the directory for one of our convenience.<\/p>\n<pre># tar xzf master\r\n# mv SpiderLabs-owasp-modsecurity-crs-ebe8790 owasp-modsecurity-crs\r\n<\/pre>\n<div id=\"attachment_11265\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Extract-mod_security-Core-Rules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11265\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Extract-mod_security-Core-Rules-620x110.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Extract-mod_security-Core-Rules-620x110.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Extract-mod_security-Core-Rules.png 732w\" alt=\"Extract mod_security Core Rules\" width=\"620\" height=\"110\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Extract mod_security Core Rules<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0Now it\u2019s time to configure mod_security. Copy the sample file with rules (<b>owasp-modsecurity-crs\/modsecurity_crs_10_setup.conf.example<\/b>) into another file without the\u00a0<b>.example<\/b>\u00a0extension:<\/p>\n<pre># cp modsecurity_crs_10_setup.conf.example modsecurity_crs_10_setup.conf<\/pre>\n<p>and tell\u00a0<b>Apache<\/b>\u00a0to use this file along with the module by inserting the following lines in the web server\u2019s main configuration file\u00a0<b>\/etc\/httpd\/conf\/httpd.conf<\/b>\u00a0file. If you chose to unpack the tarball in another directory you will need to edit the paths following the Include directives:<\/p>\n<pre>&lt;IfModule security2_module&gt;\r\n    Include crs-tecmint\/owasp-modsecurity-crs\/modsecurity_crs_10_setup.conf\r\n    Include crs-tecmint\/owasp-modsecurity-crs\/base_rules\/*.conf\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<p>Finally, it is recommended that we create our own configuration file within the\u00a0<b>\/etc\/httpd\/modsecurity.d<\/b>directory where we will place our customized directives (we will name it\u00a0<b>tecmint.conf<\/b>\u00a0in the following example) instead of modifying the\u00a0<b>CRS<\/b>\u00a0files directly. Doing so will allow for easier upgrading the CRSs as new versions are released.<\/p>\n<pre>&lt;IfModule mod_security2.c&gt;\r\n\tSecRuleEngine On\r\n\tSecRequestBodyAccess On\r\n\tSecResponseBodyAccess On \r\n\tSecResponseBodyMimeType text\/plain text\/html text\/xml application\/octet-stream \r\n\tSecDataDir \/tmp\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<p>You can refer to the\u00a0<a href=\"https:\/\/github.com\/SpiderLabs\/ModSecurity\/wiki\/Reference-Manual#Configuration_Directives\" target=\"_blank\" rel=\"noopener\">SpiderLabs\u2019 ModSecurity GitHub<\/a>\u00a0repository for a complete explanatory guide of\u00a0<b>mod_security<\/b>\u00a0configuration directives.<\/p>\n<h3>Step 4: Configuring Mod_Evasive<\/h3>\n<p><b>mod_evasive<\/b>\u00a0is configured using directives in\u00a0<b>\/etc\/httpd\/conf.d\/mod_evasive.conf<\/b>. Since there are no rules to update during a package upgrade, we don\u2019t need a separate file to add customized directives, as opposed to\u00a0<b>mod_security<\/b>.<\/p>\n<p>The default\u00a0<b>mod_evasive.conf<\/b>\u00a0file has the following directives enabled (note that this file is heavily commented, so we have stripped out the comments to highlight the configuration directives below):<\/p>\n<pre>&lt;IfModule mod_evasive24.c&gt;\r\n    DOSHashTableSize    3097\r\n    DOSPageCount        2\r\n    DOSSiteCount        50\r\n    DOSPageInterval     1\r\n    DOSSiteInterval     1\r\n    DOSBlockingPeriod   10\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<p>Explanation of the directives:<\/p>\n<ol>\n<li><b>DOSHashTableSize<\/b>: This directive specifies the size of the hash table that is used to keep track of activity on a per-IP address basis. Increasing this number will provide a faster look up of the sites that the client has visited in the past, but may impact overall performance if it is set too high.<\/li>\n<li><b>DOSPageCount<\/b>: Legitimate number of identical requests to a specific URI (for example, any file that is being served by Apache) that can be made by a visitor over the DOSPageInterval interval.<\/li>\n<li><b>DOSSiteCount<\/b>: Similar to DOSPageCount, but refers to how many overall requests can be made to the entire site over the DOSSiteInterval interval.<\/li>\n<li><b>DOSBlockingPeriod<\/b>: If a visitor exceeds the limits set by DOSSPageCount or DOSSiteCount, his source IP address will be blacklisted during the DOSBlockingPeriod amount of time. During DOSBlockingPeriod, any requests coming from that IP address will encounter a 403 Forbidden error.<\/li>\n<\/ol>\n<p>Feel free to experiment with these values so that your web server will be able to handle the required amount and type of traffic.<\/p>\n<p><strong>Only a small caveat<\/strong>: if these values are not set properly, you run the risk of ending up blocking legitimate visitors.<\/p>\n<p>You may also want to consider other useful directives:<\/p>\n<h5>DOSEmailNotify<\/h5>\n<p>If you have a mail server up and running, you can send out warning messages via Apache. Note that you will need to grant the apache user SELinux permission to send emails if SELinux is set to enforcing. You can do so by running<\/p>\n<pre># setsebool -P httpd_can_sendmail 1\r\n<\/pre>\n<p>Next, add this directive in the\u00a0<b>mod_evasive.conf<\/b>\u00a0file with the rest of the other directives:<\/p>\n<pre>DOSEmailNotify you@yourdomain.com\r\n<\/pre>\n<p>If this value is set and your mail server is working properly, an email will be sent to the address specified whenever an IP address becomes blacklisted.<\/p>\n<h5>DOSSystemCommand<\/h5>\n<p>This needs a valid system command as argument,<\/p>\n<pre>DOSSystemCommand &lt;\/command&gt;\r\n<\/pre>\n<p>This directive specifies a command to be executed whenever an IP address becomes blacklisted. It is often used in conjunction with a shell script that adds a firewall rule to block further connections coming from that IP address.<\/p>\n<h6>Write a shell script that handles IP blacklisting at the firewall level<\/h6>\n<p>When an IP address becomes blacklisted, we need to block future connections coming from it. We will use the following shell script that performs this job. Create a directory named\u00a0<b>scripts-tecmint<\/b>\u00a0(or whatever name of your choice) in\u00a0<b>\/usr\/local\/bin<\/b>\u00a0and a file called\u00a0<b>ban_ip.sh<\/b>\u00a0in that directory.<\/p>\n<pre>#!\/bin\/sh\r\n# IP that will be blocked, as detected by mod_evasive\r\nIP=$1\r\n# Full path to iptables\r\nIPTABLES=\"\/sbin\/iptables\"\r\n# mod_evasive lock directory\r\nMOD_EVASIVE_LOGDIR=\/var\/log\/mod_evasive\r\n# Add the following firewall rule (block all traffic coming from $IP)\r\n$IPTABLES -I INPUT -s $IP -j DROP\r\n# Remove lock file for future checks\r\nrm -f \"$MOD_EVASIVE_LOGDIR\"\/dos-\"$IP\"\r\n<\/pre>\n<p>Our\u00a0<b>DOSSystemCommand<\/b>\u00a0directive should read as follows:<\/p>\n<pre>DOSSystemCommand \"sudo \/usr\/local\/bin\/scripts-tecmint\/ban_ip.sh %s\"\r\n<\/pre>\n<p>In the line above,\u00a0<b>%s<\/b>\u00a0represents the offending IP as detected by\u00a0<b>mod_evasive<\/b>.<\/p>\n<h6>Add the apache user to the sudoers file<\/h6>\n<p>Note that all of this just won\u2019t work unless you to give permissions to user\u00a0<b>apache<\/b>\u00a0to run our script (and that script only!) without a terminal and password. As usual, you can just type\u00a0<b>visudo<\/b>\u00a0as root to access the\u00a0<b>\/etc\/sudoers<\/b>\u00a0file and then add the following 2 lines as shown in the image below:<\/p>\n<pre>apache ALL=NOPASSWD: \/usr\/local\/bin\/scripts-tecmint\/ban_ip.sh\r\nDefaults:apache !requiretty\r\n<\/pre>\n<div id=\"attachment_11266\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Add-Apache-User-to-Sudoers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11266\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Add-Apache-User-to-Sudoers.png\" alt=\"Add Apache User to Sudoers\" width=\"517\" height=\"116\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Add Apache User to Sudoers<\/p>\n<\/div>\n<p><strong>IMPORTANT<\/strong>: As a default security policy, you can only run\u00a0<b>sudo<\/b>\u00a0in a terminal. Since in this case we need to use\u00a0<b>sudo<\/b>\u00a0without a\u00a0<b>tty<\/b>, we have to comment out the line that is highlighted in the following image:<\/p>\n<pre>#Defaults requiretty\r\n<\/pre>\n<div id=\"attachment_11267\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Disable-tty-for-Sudo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11267\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Disable-tty-for-Sudo.png\" alt=\"Disable tty for Sudo\" width=\"407\" height=\"85\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Disable tty for Sudo<\/p>\n<\/div>\n<p>Finally, restart the web server:<\/p>\n<pre># service httpd restart \t\t[On RHEL\/CentOS 6 and Fedora 20-18]\r\n# systemctl restart httpd \t\t[On RHEL\/CentOS 7 and Fedora 21]<\/pre>\n<h3>Step 4: Simulating an DDoS Attacks on Apache<\/h3>\n<p>There are several tools that you can use to simulate an external attack on your server. You can just google for \u201c<b>tools for simulating ddos attacks<\/b>\u201d to find several of them.<\/p>\n<p>Note that you, and only you, will be held responsible for the results of your simulation. Do not even think of launching a simulated attack to a server that you\u2019re not hosting within your own network.<\/p>\n<p>Should you want to do the same with a VPS that is hosted by someone else, you need to appropriately warn your hosting provider or ask permission for such a traffic flood to go through their networks.\u00a0<b>Tecmint.com<\/b>\u00a0is not, by any means, responsible for your acts!<\/p>\n<p>In addition, launching a simulated DoS attack from only one host does not represent a real life attack. To simulate such, you would need to target your server from several clients at the same time.<\/p>\n<p>Our test environment is composed of a\u00a0<b>CentOS 7<\/b>\u00a0server [<b>IP 192.168.0.17<\/b>] and a Windows host from which we will launch the attack [IP\u00a0<b>192.168.0.103<\/b>]:<\/p>\n<div id=\"attachment_11268\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Confirm-Host-IPAddress.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11268\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Confirm-Host-IPAddress-620x221.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Confirm-Host-IPAddress-620x221.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Confirm-Host-IPAddress.png 708w\" alt=\"Confirm Host IPAddress\" width=\"620\" height=\"221\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Confirm Host IPAddress<\/p>\n<\/div>\n<p>Please play the video below and follow the steps outlined in the indicated order to simulate a simple DoS attack:<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/-U_mdet06Jk\" width=\"780\" height=\"439\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Then the offending IP is blocked by iptables:<\/p>\n<div id=\"attachment_11269\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Blocked-Attacker-IP.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11269\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Blocked-Attacker-IP-620x129.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Blocked-Attacker-IP-620x129.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/06\/Blocked-Attacker-IP.png 961w\" alt=\"Blocked Attacker IP\" width=\"620\" height=\"129\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Blocked Attacker IP<\/p>\n<\/div>\n<h3>Conclusion<\/h3>\n<p>With\u00a0<b>mod_security<\/b>\u00a0and\u00a0<b>mod_evasive<\/b>\u00a0enabled, the simulated attack causes the\u00a0<b>CPU<\/b>\u00a0and\u00a0<b>RAM<\/b>\u00a0to experiment a temporary usage peak for only a couple of seconds before the source IPs are blacklisted and blocked by the firewall. Without these tools, the simulation will surely knock down the server very fast and render it unusable during the duration of the attack.<\/p>\n<p>We would love to hear if you\u2019re planning on using (or have used in the past) these tools. We always look forward to hearing from you, so don\u2019t hesitate to leave your comments and questions, if any, using the form below.<\/p>\n<h3>Reference Links<\/h3>\n<p><a href=\"https:\/\/www.modsecurity.org\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.modsecurity.org\/<\/a><br \/>\n<a href=\"http:\/\/www.zdziarski.com\/blog\/?page_id=442\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/www.zdziarski.com\/blog\/?page_id=442<\/a><\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/protect-apache-using-mod_security-and-mod_evasive-on-rhel-centos-fedora\/4\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those of you in the hosting business, or if you\u2019re hosting your own servers and exposing them to the Internet, securing your systems against attackers must be a high priority. mod_security\u00a0(an open source intrusion detection and prevention engine for web applications that integrates seamlessly with the web server) and\u00a0mod_evasive\u00a0are two very important tools that &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/21\/protect-apache-against-brute-force-or-ddos-attacks-using-mod_security-and-mod_evasive-modules\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Protect Apache Against Brute Force or DDoS Attacks Using Mod_Security and Mod_evasive Modules&#8221;<\/span><\/a><\/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":[],"class_list":["post-12034","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12034"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12034\/revisions"}],"predecessor-version":[{"id":12036,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12034\/revisions\/12036"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}