Definition
Directory Traversal, also known as Path Traversal, is a web security vulnerability that allows attackers to access directories and files stored outside the web root folder. This is achieved by manipulating variables referencing files with "../" sequences or through URL encoding.How It Works
- 1Attackers input "../" sequences in URLs or input fields to traverse directories.
- 2They may use URL encoding techniques like "..%2f" or "..%2e%2e/" to bypass filters.
- 3Older systems might be vulnerable to null byte injections, where a %00 character terminates a string early, bypassing security checks.
- 4Successful traversal can expose sensitive files like '/etc/passwd', application configuration files, or source code.
Key Characteristics
- Exploits lack of input validation or improper file path sanitization.
- Often targets web servers but can affect any file-handling application.
- Can be used in conjunction with other attacks, like Local File Inclusion (LFI).
Comparison
| Concept | Description |
|---|---|
| Directory Traversal | Accesses files outside intended directories |
| Local File Inclusion (LFI) | Executes or displays files on the server |
| Remote File Inclusion (RFI) | Executes scripts from remote servers |
Real-World Example
CVE-2021-41773 in Apache HTTP Server allowed attackers to perform a path traversal attack to map URLs to files outside the document root.Detection & Prevention
- Use tools like Burp Suite or ffuf to scan for traversal vulnerabilities.
- Implement input validation and sanitize file paths.
- Configure servers to deny access to sensitive files and directories.
- Regularly update server software to patch known vulnerabilities.
Common Misconceptions
- Myth: Directory Traversal only affects web servers. Truth: It can affect any application that improperly handles file paths.
- Myth: Encoding will always prevent detection. Truth: Modern scanners and filters often detect encoded traversal attempts.
- Myth: It's a minor issue. Truth: It can lead to severe breaches, exposing critical data and system functionality.