Disable directory browser listing. Disable directory listing in a browser so the visitor doesnt see what all file and folders you have under root or subdirectory. Lets test how does it look like in default settings. Go to WebServerhtdocs directory. Create a folder and few files inside that mkdir test. Now, lets try to access Apache by http localhosttest. As you could see it reveals what all filefolders you have which are certainly you dont want to expose. Implementation Go to WebServerconf directory Open httpd. Search for Directory and change Options directive to None or Indexeslt Directory optapachehtdocs. Order allow,deny. Directory orlt Directory optapachehtdocs. Options Indexes. Order allow,deny. Directory Note if you have multiple Directory directives in your environment, you should consider doing the same for all. Verification Now, lets try to access Apache by http localhosttest. As you could see, it displays forbidden error instead showing test folder listing. Etag. It allows remote attackers to obtain sensitive information like inode number, multipart MIME boundary, and child process through Etag header. To prevent this vulnerability, lets implement it as below. This is required to fix for PCI compliance. Implementation Go to WebServerconf directory. Add the following directive and save the httpd. File. ETag None. Verification Open Firefox and access your application. Check HTTP response headers in firebug, you should not see Etag at all. Authorization. 3. Run Apache from non privileged account. Default apache configuration is to run as nobody or daemon. Its good to use a separate non privileged user for Apache. The idea here is to protect other services running in case of any security hole. Implementation Create a user and group called apachegroupadd apache. G apache apache. Change apache installation directory ownership to newly created non privileged user chown R apache apache optapache Go to WebServerconf Modify httpd. Search for User Group Directive and change as non privileged account apache. User apache. Group apache Save the httpd. Restart Apache. Verification grep for running http process and ensure its running with apache user ps ef grep http. Note You could see one process is running with root. Thats because Apache is listening on port 8. We will talk about how to change port number later in this course. Protect binary and configuration directory permission. By default, permission for binary and configuration is 7. You can disallow another user to get into conf and bin folder. Implementation Go to WebServer directory. Change permission of bin and conf folder chmod R 7. Verification 3. 3 System Settings Protection. In a default installation, users can override apache configuration using. Allow. Override to None as shown below. This must be done at the root level. Implementation Go to WebServerconf directory Open httpd. Search for Directory at root levellt Directory. Options Indexes. Allow. Override Nonelt Directory Save the httpd. Restart Apache. 3. HTTP Request Methods. HTTP 1. 1 protocol support many request methods which may not be required and some of them are having potential risk. Typically you may just need GET, HEAD, POST request methods in a web application, which can be configured in the respective Directory directive. Default apache configuration support OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT method in HTTP 1. Implementation Go to WebServerconf directory Open httpd. Search for Directory and add followinglt Limit. Except GET POST HEAD deny from alllt Limit. Except 4. Web Application Security. Apache web server misconfiguration or not hardened properly can exploit web application. Its critical to harden your web server configuration. Cookies. 4. 1. 1 Disable Trace HTTP Request. By default Trace method is enabled in Apache web server. Having this enabled can allow Cross Site Tracing attack and potentially giving an option to a hacker to steal cookie information. Lets see how it looks like in default configuration. Do a telnet web server IP with listening port Make a TRACE request as shown belowtelnet localhost 8. Trying 1. 27. 0. 0. Connected to localhost. Escape character is. TRACE HTTP1. 1 Host test. HTTP1. 1 2. 00 OK. Date Sat, 3. 1 Aug 2. GMT. Transfer Encoding chunked. Content Type messagehttp 2. TRACE HTTP1. 1. Connection closed by foreign host. As you could see in above TRACE request it has responded my query. Lets disable it and test it. Implementation Go to WebServerconf directory. Add the following directive and save the httpd. Trace. Enable off. Verification Do a telnet web server IP with listen port and make a TRACE request as shown belowtelnet localhost 8. Trying 1. 27. 0. 0. Connected to localhost.