Directory listing: disabling directory browsing

The video is hosted by YouTube (Google). When played, YouTube may set cookies.

Web servers are often configured to list the contents of directories that have no index page automatically. This can help an attacker, letting them quickly identify the resources in a given folder and move straight to analysing and exploiting them. In particular, it increases the exposure of sensitive files in the directory that are not meant to be accessible to users, such as temporary files, error logs, changelogs, readme files and so on.

Directory listing is not a security breach in itself. In any case, every sensitive resource should be properly access-controlled and should not be reachable by an unauthorised party who knows or guesses its URL. Even with directory listing disabled, an attacker can guess the location of sensitive files using automated tools.

Remediation:

Apache2
  1. Edit the configuration file of the relevant VirtualHost
  2. In the <Directory> section, change

    <Directory /var/www/> <br> Options Indexes FollowSymLinks <br> AllowOverride None <br> Require all granted <br> </Directory>

    to

    <Directory /var/www/> <br> Options FollowSymLinks <br> AllowOverride None <br> Require all granted <br> </Directory>

  3. Restart the web server

Nginx

  1. Edit the Nginx configuration file of the site where you want to disable directory listing
  2. In the server { } section, add the following line:

    autoindex off;

    Example:

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name _;
    location / {
    autoindex off;
    try_files $uri $uri/ =404;
    }
    }
  3. Restart the web server

IIS (option 1)

  1. Open IIS Manager and select the site you want to change
  2. On the right you will see a "Directory Browsing" option - click it
  3. In the "Actions" panel that opens on the right of the screen, click the "Disable" button.
  4. Restart the web server

IIS (option 2)

  1. Open cmd
  2. cd %systemroot%\system32\inetsrv\
  3. appcmd.exe set config "Default Web Site" -section:system.webServer/directoryBrowse /enabled:"False" /showFlags:"Date, Time, Size, Extension"
  4. Restart the web server
  • directory listing
  • attacks
  • security
  • cybersecurity
Iulian Băncău

Security Engineer · All Safe

More than CyberSecurity

We offer a variety of services to help companies be prepared for real cyber attacks.