bg_image
header

Directory Traversal

What is Directory Traversal?

Directory Traversal (also known as Path Traversal) is a security vulnerability in web applications that allows an attacker to access files or directories outside the intended directory. The attacker manipulates file paths to navigate through the server’s filesystem.

How Does a Directory Traversal Attack Work?

A vulnerable web application often processes file paths directly from user input, such as an URL:

https://example.com/getFile?file=report.pdf

If the server does not properly validate the input, an attacker could modify it like this:

https://example.com/getFile?file=../../../../etc/passwd

Here, the attacker uses ../ (parent directory notation) to move up the directory structure and access system files like /etc/passwd (on Linux).

Risks of a Successful Attack

  • Exposure of sensitive data (configuration files, source code, user lists)
  • Server compromise (stealing SSH keys or password hashes)
  • Code execution, if the attacker can modify or execute files

Prevention Measures

  • Input validation: Sanitize user input and allow only safe characters
  • Use secure file paths: Avoid directly using user input in file operations
  • Least privilege principle: Restrict the web server’s file access permissions
  • Whitelist file paths: Allow access only to predefined files