15–25 min Updated

Directory Traversal

By Malcolm McDonald Founder, Editor-in-ChiefAuthor of Grokking Web Application Security

Ensure file paths are safely interpreted, or hackers can access sensitive files on your server.

Prevalence
Common
Exploitability
Moderate
Impact
Devastating

What is directory traversal?

Directory traversal, also called path traversal, is a file access attack in which an attacker manipulates a file path in a request, typically with ../ sequences, to reach files outside the intended directory. It occurs when user input is used to build file paths without validation, exposing configuration files, source code and credentials stored on the server.

What you'll learn

  • How ../ sequences in a file path escape the intended directory
  • Why passing raw file names from a request to the file system is dangerous
  • How indirection, filename sanitization and restricted permissions protect your files

Where this lesson counts

OWASP Top 10

PCI DSS v4.0.1

  • Directory Traversal lab

    A restaurant menu site downloads whatever file is named in its menu parameter. Watch Trix climb out of the menus folder with ../ and reach system files, then edit the URL yourself to download the server's private SSL key.

  • How to prevent Directory Traversal

    The prevention guide covers five approaches, including:

    • Use a Content Management System
    • Use Indirection
    • Segregate Your Documents
  • Directory Traversal quiz

    Two questions. Passing marks the lesson complete.

Sources

  • File Upload Vulnerabilities

    File uploads are an easy way for an attacker to inject malicious code into your application.

  • Broken Access Control

    All resources on your site need to have access control implemented, even if they aren't intended to be discoverable by a user.

  • Command Execution

    If your application calls out to the OS, you need to be sure command strings are securely constructed.

  • Information Leakage

    Revealing system information helps an attacker learn about your tech stack.