AI pentesting guides / Vulnerability classes

Directory traversal

Path traversal testing

Path traversal testing checks whether an attacker can manipulate a file path parameter to read or write files outside the directory the application intended, typically by inserting ../ sequences. It is CWE-22 (Improper Limitation of a Pathname to a Restricted Directory) and, in the OWASP Top 10 2021, falls under A01: Broken Access Control.

Local file inclusion (LFI) is a related case where the traversed file is included or executed by the application rather than just returned. Both can expose configuration files, credentials and source code.

Classification

  • CWE-22 Path Traversal; related CWE-23 (relative path traversal) and CWE-98 (PHP file inclusion).
  • OWASP Top 10 2021: A01 Broken Access Control.
  • No dedicated OWASP API Security Top 10 2023 category.

How it is found

Look for parameters that name files or paths: file, path, page, doc, template, download, lang. Replace the value with a traversal to a well-known file, the textbook example being ../../../../etc/passwd on Linux. If simple traversal is filtered, try variants: URL encoding and double encoding, absolute paths, mixed separators on Windows, and sequences that survive a single pass of ../ stripping. Archive extraction (Zip Slip) and file upload names are write-side variants.

What counts as proof

Proof is content that could only come from the target file: for /etc/passwd, a line beginning root: that is absent when the parameter holds a normal value. Comparing an attack response with a control response rules out a page that always contains similar text. Read only well-known, non-sensitive files to prove the issue; do not exfiltrate secrets.

Remediation

Do not build file paths from user input. Map user-supplied keys to files through an allow-list or a database ID. If paths are unavoidable, canonicalise the full path and confirm it starts with the intended base directory after resolution. Run the service with minimal file-system permissions, and validate archive entry names before extraction.

With Pentest-Swarm

How Pentest-Swarm tests for path traversal

Path traversal and LFI are among the classes Pentest-Swarm proves with a differential oracle.

  • An adaptive sweep finds file-like parameters (file, path, page, doc and similar) and traverses them to /etc/passwd.
  • The root: signature present in the attack response but absent in the control response is the proof, badged VERIFIED.
  • dotdotpwn is in the arsenal for broader traversal fuzzing.
  • Findings include the request pair, severity and CVSS.

Where it falls short

The oracle's signature targets Unix-like systems; Windows targets and traversal that only writes files (Zip Slip, upload names) are less well covered and should be checked manually. Traversal that reads application-specific files rather than system files needs a tester who knows what to look for. Source review is the surest way to find every file-path sink.

Questions

What is the difference between path traversal and LFI?

Path traversal reads or writes files outside the intended directory. LFI includes or executes the file in the application, which can lead to code execution.

Does stripping ../ fix path traversal?

No. Encodings and nested sequences such as ....// often survive a single strip. Canonicalise and check the resolved path instead.

Why is path traversal under Broken Access Control?

Because the flaw is the application granting access to files outside what the user is permitted to reach.

Sources

  1. CWE-22
  2. OWASP Path Traversal