The web server has a crucial role in web-based applications. Since most of us leave it to the default configuration, it can leak sensitive data regarding the web server.
There are numerous web servers in the market. Apache is one of the most popular and widely used out of all of them. Because of this popularity, it is also most vulnerable to cyber-attacks.
By applying numerous configuration tweaks we can make Apache withstand malicious attacks up to a limit. Following are some Apache web server hardening tips that you can incorporate to improve security.
One of the first things to be taken care of is hiding the server version banner.
The default apache configuration will expose the server version. This information might help an attacker gain a greater understanding of the systems in use and potentially develop further attacks targeted at the specific version of the server.
We can easily fix server version disclosure by following the below steps:
Open apache.conf
Add the following directives to configuration
Save the configuration and restart Apache
Even better, we can change the server name to anything else in the server header. In order to achieve this, you need to enable the mod_security module. Then add the following directives to the configuration.
Save the configuration and restart Apache
By Apache’s default configuration, If your web server root directory doesn’t contain index.html, the user can see all files and subdirectories listed in the web root.
To disable directory listing we need to set the Option
directive value as None
or -Indexes
in the apache configuration file.
Example
Restart apache2
mod_security works as a firewall for web applications.
It can also be used for real-time web application monitoring and logging. You can install mod_security from your default package installer.
mod_evasive provides effective actions against Distributed Denial of Service (DDoS/DoS) attack or brute force attack
Its capabilities also extend to work with ipchains, firewalls, routers, and more. mod_evasive reports events via email and syslog facilities.
mod_evasive has a prerequisite. Install the prerequisite by running the following command.
Debian/Ubuntu
RHEL/CentOS/Fedora
Debian/Ubuntu
RHEL/CentOS/Fedora
Configuring mod_evasive
Open mod_evasive configuration file in any text editor. you can find the configuration file in the following path:
Debian/Ubuntu
RHEL/CentOS/Fedora
Find the following lines and uncomment them.
Replace DOSEmailNotify mail@yourdomain.com
with your email address to get a notification on events. Email notifications only work if there’s a functional mail server running on the server.
Save the configuration and restart apache. Now, mod_evasive is in effect.
The ETag header involves quite a significant number of sensitive details regarding your server. It’s interesting that for PCI-compliance it is required to hide the Etag header.
To achieve this, add the following directive to apache configuration.
SSIs are directives present on web applications used to feed an HTML page with dynamic contents.
They are also capable of opening your website up to a certain number of security issues if left unchecked. The same case happens for the CGI scripts. So as to prevent hackers from injecting malicious scripts in your code. Restrict CGI and SSI by adding the following directives to apache configuration:
Setting up some HTTP limits can defend against DDoS (Distributed denial of service) attack, it is really easy if you know the sort of actions to look out for.
DDoS always tends to happen by hitting repeatedly on your server with very large requests.
The following include some limits you make need to configure:
Cross-site scripting (XSS) is a common vulnerability found in web applications. X-XSS-Protection header can prevent some level of XSS (cross-site-scripting) attacks.
The parameters are:
Add the following entry to your Apache configuration to enable XSS Protection Header.
Restart apache.
Last but not the least, always keep your web server updated.