Skip to content

Basic path traversal payloads (../ directory traversal)

Basic path traversal payloads abuse a parameter that is concatenated into a file path so that ../ (or ..\ on Windows) sequences walk up out of the intended directory and read arbitrary files such as /etc/passwd. This is the root of every Local File Inclusion bug: the application trusts attacker input to build a path.

Linux / UnixWindowsArbitrary file readInformation disclosureNo filter

How it works

A vulnerable endpoint takes a filename from the request (for example ?page=home or ?file=report.pdf) and joins it onto a base directory before opening it. If the value is used without resolving and validating the final path, an attacker can prepend ../ segments to climb above the base directory.

Each ../ (dot-dot-slash) moves one level up the tree. Enough of them reach the filesystem root, after which an absolute-looking suffix selects any readable file. On Windows the separator is a backslash, so ..\ is equivalent, and most Windows APIs accept forward slashes too.

Because the climb stops at the root — extra ../ sequences past / are harmless — attackers usually over-count (../../../../../../) to avoid having to know the exact depth of the base directory.

When it works and when it fails

Works when

  • User input is concatenated into a path and the result is never canonicalized or checked against an allowlist.
  • The process has read permission on the target file (web-server user can usually read /etc/passwd, app config, source).
  • No WAF or input filter strips or rejects ../ sequences.

Fails when

  • The app resolves the path (realpath/normalize) and verifies it stays within the base directory.
  • Input is mapped through an allowlist of known keys instead of used as a path.
  • A forced extension is appended and not truncated (see extension-filter-bypass), so only a fixed file type can be opened.

Representative payloads

Adapt these to your authorized target; they are shown in canonical form. Payloads are never translated.

  • ../../../../../../etc/passwd
    Linux / UnixNo filter

    Classic Unix proof of concept. Over-counts ../ to reach the root regardless of base-directory depth, then reads the world-readable account list.

  • ..\..\..\..\..\..\windows\system32\drivers\etc\hosts
    WindowsNo filter

    Windows equivalent using backslashes to reach a world-readable file that confirms traversal on Windows hosts.

  • ../../../../../../windows/win.ini
    WindowsNo filter

    Windows accepts forward slashes in most path APIs, so Unix-style ../ often works against Windows targets too.

  • ../../config/database.php
    Any OSNo filter

    Shallow traversal to an application config one or two directories above the web root — often higher value than /etc/passwd.

    Note: Use php://filter to read PHP source without execution — see the PHP filter wrapper technique.

Detection

In logs

  • Request paths or query strings containing ../, ..%2f, or ..\ — grep access logs for the literal and encoded forms.
  • Requests that reference sensitive filenames (passwd, shadow, web.config, .env, id_rsa) in any parameter.
  • A spike of 200/403 responses on a single file parameter from one source — bracketing the base-directory depth.

In code

  • File APIs (fopen, file_get_contents, open, fs.readFile, include/require) whose path argument derives from request data.
  • Path building with string concatenation or join() where one component is user-controlled.
  • Absence of a realpath/normalize call followed by a prefix check before the file is opened.

Detection rule: A Sigma/WAF rule matching (\.\./){2,} or its URL-encoded variants in request parameters catches the naive form; pair it with canonicalization server-side rather than relying on the rule alone.

Remediation

  • Do not build file paths from user input. Map a request key to a fixed path through a server-side allowlist (e.g. {"home": "home.html"}) and reject anything not in the map.
  • If a path component is unavoidable, resolve the final path (realpath in PHP, Path.resolve/normalize in Node, os.path.realpath in Python) and verify it starts with the intended base directory before opening it.
  • Reject input containing path separators or .. outright when the parameter should be a bare filename; validate against a strict pattern such as ^[A-Za-z0-9_-]+$.
  • Run the application as a low-privilege user and use filesystem permissions / chroot / containers so even a successful traversal reaches nothing sensitive.

Vulnerable (php)

$base = '/var/www/pages/';
$file = $base . $_GET['page'];
readfile($file); // ?page=../../../../etc/passwd

Fixed

$base = '/var/www/pages/';
$path = realpath($base . $_GET['page']);
if ($path === false || !str_starts_with($path, $base)) {
    http_response_code(400);
    exit('Invalid path');
}
readfile($path);

Resolve the final path and confirm it stays inside the base directory before reading.

FAQ

Why do payloads use so many ../ sequences?
Climbing stops at the filesystem root, so extra ../ past the root are ignored. Over-counting means the attacker does not need to know the exact depth of the base directory for the payload to reach /.
Is path traversal the same as Local File Inclusion?
Traversal is the mechanism that selects a file outside the intended directory. When the selected file is then included/executed (as with PHP include), traversal becomes Local File Inclusion, which can escalate to code execution.

References