A Practical Guide To Secure and Harden Apache HTTP Server
A Practical Guide To Secure and Harden Apache HTTP Server
HTTP Server.
Audience
This is designed for Middleware Administrator, Application
Support, System Analyst, or anyone working or eager to learn
Hardening & Security guidelines.
Notes
Go to $Web_Server/conf folder
Modify httpd.conf by using the vi editor
Add the following directive and save the httpd.conf
ServerTokens Prod
ServerSignature Off
Restart apache
Go to $Web_Server/htdocs directory
Create a folder and few files inside that
# mkdir test
# touch hi
# touch hello
Go to $Web_Server/conf directory
Open httpd.conf using vi
Search for Directory and change Options directive to None
or –Indexes
<Directory /opt/apache/htdocs>
Options -Indexes
</Directory>
(or)
<Directory /opt/apache/htdocs>
Options None
</Directory>
Restart Apache
Etag
It allows remote attackers to obtain sensitive information like
inode number, multipart MIME boundary, and child process
through Etag header.
Go to $Web_Server/conf directory
Add the following directive and save the httpd.conf
FileETag None
Restart apache
Go to $Web_Server/conf
Modify httpd.conf using vi
Search for User & Group Directive and change as non-
privileged account apache
User apache
Group apache
grep for running http process and ensure it’s running with
apache user
You should see one process is running with root. That’s because
Apache is listening on port 80 and it has to be started with root.
Go to $Web_Server directory
Change permission of bin and conf folder
# chmod –R 750 bin conf
Go to $Web_Server/conf directory
Open httpd.conf using vi
Search for Directory and add the following
<LimitExcept GET POST HEAD>
deny from all
</LimitExcept>
Restart Apache
Go to $Web_Server/conf directory
Add the following directive and save the httpd.conf
TraceEnable off
Restart apache
#telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
TRACE / HTTP/1.1 Host: test
HTTP/1.1 405 Method Not Allowed
Date: Sat, 31 Aug 2013 02:18:27 GMT
Server: Apache Allow:Content-Length: 223Content-Type: text/html; charset=iso-8859-
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head>
<title>405 Method Not Allowed</title> </head><body>
<h1>Method Not Allowed</h1>
<p>The requested method TRACE is not allowed for the URL /.</p> </body></html>
Connection closed by foreign host.
#
Now, this web server doesn’t allow TRACE request and help in
blocking Cross Site Tracing attack.
Restart apache
Clickjacking Attack
Clickjacking is a well-known web application vulnerabilities.
Restart apache
Go to $Web_Server/conf directory
Open httpd.conf using vi
Search for Directory and add Includes in Options directive
<Directory /opt/apache/htdocs>
Options –Indexes -Includes
Order allow,denyAllow from all
</Directory>
Restart Apache
Go to $Web_Server/conf directory
Open httpd.conf using vi and add following Header
directive
Header set X-XSS-Protection "1; mode=block"
Restart Apache
Go to $Web_Server/conf directory
Open httpd.conf using vi
Add the following in httpd.conf
Timeout 60
SSL
Having SSL is an additional layer of security you are adding
into Web Application. However, default SSL configuration leads
to certain vulnerabilities, and you should consider tweaking
those configurations.
SSL Key
Breaching SSL key is hard, but not impossible. It’s just a matter
of computational power and time.
Outlook.com
Microsoft.com
Live.com
Skype.com
Apple.com
Yahoo.com
Bing.com
Hotmail.com
Twitter.com
You can use OpenSSL to generate CSR with 2048 bit as below.
Restart Apache web server and try to access the URL with
https
SSL Cipher
SSL Cipher is an encryption algorithm, which is used as a key
between two computers over the Internet. Data encryption is
the process of converting plain text into secret ciphered codes.
It’s based on your web server SSL Cipher configuration the data
encryption will take place. So it’s important to configure SSL
Cipher, which is stronger and not vulnerable.
Go to $Web_Server/conf/extra folder
Modify SSLCipherSuite directive in httpd-ssl.conf as below
to accept only higher encryption algorithms
SSLCipherSuite HIGH:!MEDIUM:!aNULL:!MD5:!RC4
Go to $Web_Server/conf/extra folder
Modify SSLProtocol directive in httpd-ssl.conf as below to
accept only TLS 1.2+
SSLProtocol –ALL +TLSv1.2
Once you are done with SSL configuration, it’s a good idea to
test your web application with online SSL/TLS Certificate
tool to find any configuration error.
Mod Security
Mod Security is an open-source Web Application Firewall,
which you can use with Apache.
It comes as a module which you have to compile and install. If
you can’t afford a commercial web application firewall, this
would be an excellent choice to go for it.
Configuration
To use Mod security feature with Apache, we have to load mod
security module in httpd.conf. The mod_unique_id module is
pre-requisite for Mod Security.
This module provides an environment variable with a unique
identifier for each request, which is tracked and used by Mod
Security.
Now, let’s enable these rules to get it working with Apache web
server.
Getting Started
Let’s get it started with some of the critical configurations in
Mod Security to harden & secure web applications.
We will refer
/opt/apache/conf/crs/modsecurity_crs_10_setup.conf as
setup.conf in this section for example purpose.
Base Rules – these rules are heavily tested, and probably false
alarm ratio is less.
Logging
Logging is one of the first things to configure so you can have
logs created for what Mod Security is doing. There are two types
of logging available; Debug & Audit log.
Audit Log: this is to write the transaction logs that are marked
by Mod Security rule Mod Security gives you the flexibility to
configure Audit, Debug or both logging.
SecDefaultAction “phase:1,deny,log”
To log Debug, Audit log – use “log” To log only audit log – use
“nolog,auditlog” To log only debug log – use “log,noauditlog”
You can specify the Audit Log location to be stored which is
controlled by SecAuditLog directive.
Ex:
General Configuration
Let’s check out some of the general configurations as best
practice.
Configure Listen
When you have multiple interfaces and IP’s on a single server,
it’s recommended to have Listen directive configured with
absolute IP and Port number.
Access Logging
It’s essential to configure access log properly in your web
server. Some of the important parameter to capture in the log
would be the time taken to serve the request, SESSION ID.
By default, Apache is not configured to capture these data. You
got to configure them manually as follows.
You can
refer http://httpd.apache.org/docs/2.2/mod/mod_log_config.
html for a complete list of parameter supported in LogFormat
directive in Apache Web Server.
http://httpd.apache.org/docs/2.4/
http://www.modsecurity.org/documentation/
https://www.owasp.org/index.php/Category:OWASP_Mod
Security_Core_Rule_Set_Project
So that was some of the best practices you can use to secure
your Apache web server.