Directory Listing
- CAPEC 127
- WASC 16
- OWASP PC-C6
- OWASP 2013-A5
Directory Listing occurs when a web server is configured to expose the contents of directories instead of serving a default page. This allows attackers to browse files and folders on the server, gaining insight into the application’s structure, exposed scripts, configuration files, or sensitive data. While directory listing itself may not directly allow code execution, it can facilitate reconnaissance and the discovery of other vulnerabilities, such as backup files, exposed credentials, or outdated scripts.
Common patterns leading to directory listing:
- Web servers misconfigured to allow directory browsing (e.g., Apache
Options Indexesenabled, IIS directory browsing enabled). - Absence of default index files (
index.html,index.php) in directories. - Publicly accessible directories containing sensitive files, logs, scripts, or configuration files.
- Lack of
.htaccessrules or equivalent access restrictions to disable directory listing.
Impacts:
- Information Disclosure: Reveals sensitive files, source code, or backup files.
- Facilitates Other Attacks: Attackers can identify vulnerable scripts, outdated software, or files to exploit (LFI, RFI, SQLi, XSS, etc.).
- Exposure of Sensitive Configuration: Critical configuration files or directories may be enumerated and misused.
Detection indicators:
- Navigating to a directory URL returns an HTML page listing files instead of a default index.
- Automated scanning tools detect directories returning full file listings.
- Presence of unprotected folders containing sensitive file types.
Remediation
Preventing directory listing involves proper server configuration, access control, and file management:
Disable Directory Indexing/Browsing
Configure the web server to prevent directory listing (e.g., Apache:Options -Indexes, IIS: disable directory browsing).Ensure Default Index Pages Exist
Provideindex.html,index.php, or equivalent in every directory to prevent automatic listing.Restrict Access to Sensitive Directories
Use authentication or IP restrictions to protect administrative, configuration, and backup directories.Move Sensitive Files Outside Web Root
Files not intended for public access should be stored outside of the web-accessible directory structure.Use
.htaccessor Server Configuration Rules
Apply deny rules to prevent access to specific directories or file types.Regular Auditing
Perform regular security reviews and automated scans to detect directories exposing file listings.Principle of Least Privilege
Ensure the web server has minimal read permissions only for required files and directories.Monitoring and Logging
Log access attempts to directories and alert on unusual or suspicious browsing activity.Remove Unnecessary Files
Eliminate test files, temporary files, or developer artifacts that could be exposed via directory listing.