Directory Listing
Directory Listing is by default enabled in an apache server. This happens when there is no index.html file (default) available in the directory.
If there is no index file available in the directory then doesn’t understand which file to display so it displays all the files and folders in the directory.
Please see the below screenshot
The above image index file is the default file that is under the website folder. So when I will access my localhost with the following address – localhost/website1 or 192.168.1.2/website1 then it shows the following page.
It is actually showing the website because Apache knows exactly which file to display i.e. index.html
But in case I have renamed the index.html file to index1.html then let’s see what happens. So this time when I access my website1 folder again then it will show all the files and folders inside the website1 folder.
Prevention
In order to prevent this, you need to disable directory listing in httpd.conf file. Open httpd.conf file and locate <Directory “var/www/html”>
It will look like this
<Directory "R:/bitnami/apache2/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # #AllowOverride None # # Controls who can get stuff from this server. # Require all granted</Directory>
To disable the Directory listing add “-” sign
Options Indexes FollowSymLinks
Result:
Options -Indexes -FollowSymLinks
<Directory "R:/bitnami/apache2/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options -Indexes -FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # #AllowOverride None # # Controls who can get stuff from this server. # Require all granted</Directory>
Now save the file and restart the server and try to access the folder. This time you will get forbidden message with 403 that means access is denied to see this directory
Suggested Read: Server Security – Apache Web Server Hardening
Comments
Post a Comment