ArticleslgStudy

science

Path traversal attack

Path traversal attack is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Path traversal attack rather than just read about it. In short: A directory traversal, path traversal, or dot-dot-slash attack exploits insufficient security validation or sanitization of user-supplied file names, such that characters representing "traverse to parent directory" are passed through to the operating system's file system API. An affected application can be exploited to gain unauthorized access to the file system.

Key takeaways

  • Path traversal attack belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Path traversal attack to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Path traversal attack from memory before moving on to harder problems.

Reference excerpt

A directory traversal, path traversal, or dot-dot-slash attack exploits insufficient security validation or sanitization of user-supplied file names, such that characters representing "traverse to parent directory" are passed through to the operating system's file system API. An affected application can be exploited to gain unauthorized access to the file system.

Examples

In PHP A typical example of a vulnerable application in PHP code is:

An attack against this system could be to send the following HTTP request:

The server would then generate a response such as:

The repeated ../ characters after /home/users/phpguru/templates/ have caused include() to traverse to the root directory, and then include the Unix password file /etc/passwd. Unix /etc/passwd is a common file used to demonstrate directory traversal, as it is often used by crackers to try cracking the passwords. However, in more recent Unix systems, the /etc/passwd file does not contain the hashed passwords, and they are instead located in the /etc/shadow file, which cannot be read by unprivileged users on the machine. Even in that case, though, reading /etc/passwd does still show a list of user accounts, which could then become a starting point for further attacks.

Zip Slip vulnerability Another example is the "Zip Slip" vulnerability that affects several archive file formats like ZIP.

Variations Directory traversal in its simplest form uses the ../ pattern. Some common variations are listed below:

Windows Windows directory traversal uses the ..\ or ../ patterns. Each partition has a separate root directory (labeled C:\ where C could be any partition), and there is no common root directory above that. This means that for most directory vulnerabilities on Windows, attacks are limited to a single partition. Directory traversal has been the cause of numerous Microsoft vulnerabilities.

Percent encoding in URIs Some web applications attempt to prevent directory traversal by scanning the path of a request URI for patterns such as ../. This check is sometimes mistakenly performed before percent-decoding, causing URIs containing patterns like %2e%2e/ to be accepted despite being decoded into ../ before actual use.

Double encoding Percent decoding may accidentally be performed multiple times; once before validation, but again afterwards, making the application vulnerable to Double percent-encoding attacks in which illegal characters are replaced by their double-percent-encoded form in order to bypass security countermeasures. For example, in a double percent-encoding attack, ../ may be replaced by its double-percent-encoded form %252E%252E%252F. This kind of vulnerability notably affected versions 5.0 and earlier of Microsoft's IIS web server software.

UTF-8 A badly implemented UTF-8 decoder may accept characters encoded using more bytes than necessary, leading to overlong encodings, such as %c0%ae instead of %2e to represent .. This is specifically forbidden by the UTF-8 standard, but has still led to directory traversal vulnerabilities in software such as the IIS web server.

Archives Some archive formats like zip allow for directory traversal attacks: files in the archive can be written such that they overwrite files on the filesystem by backtracking. Code that extracts archive files can be written to check that the paths of the files in the archive do not engage in path traversal.

Prevention A possible algorithm for preventing directory traversal would be to:

Process URI requests that do not result in a file request, e.g., executing a hook into user code, before continuing below. When a URI request for a file/directory is to be made, build a full path to the file/directory if it exists, and normalize all characters (e.g., %20 converted to spaces). It is assumed that a 'Document Root' fully qualified, normalized, path is known, and this string has a length N. Assume that no files outside this directory can be served. Ensure that the first N characters of the fully qualified path to the requested file is exactly the same as the 'Document Root'. If so, allow the file to be returned. If not, return an error, since the request is clearly out of bounds from what the web-server should be allowed to serve. Using a hard-coded predefined file extension to suffix the path does not necessarily limit the scope of the attack to files of that file extension.

The user can use the NULL character (indicating the end of the string) in order to bypass everything after the $_GET. (This is PHP-specific.)

See also Chroot jails may be subject to directory traversal if incorrectly created. Possible directory traversal attack vectors are open file descriptors to directories outside the jail. The working directory is another possible attack vector. Insecure direct object reference

References

Resources Open Web Application Security Project The WASC Threat Classification – Path Traversal Path Traversal Vulnerability Exploitation and Remediation CWE Common Weakness Enumeration - Path Traversal

External links DotDotPwn – The Directory Traversal Fuzzer Conviction for using directory traversal. "Only bad guys benefit from bad law". comment.zdnet.co.uk. October 7, 2005. Archived from the original on 2006-10-08. Bugtraq: IIS %c1%1c remote command execution Cryptogram Newsletter July 2001.

Worked examples

Example 1 — a first encounter with Path traversal attack

Start with the simplest possible case. Write down what Path traversal attack claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Path traversal attack before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Path traversal attack ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Path traversal attack

In research
Path traversal attack appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Path traversal attack in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Path traversal attack is common in secondary-school and first-year university syllabi. It links to neighbouring topics Web security exploits, so understanding it makes those chapters shorter.
In everyday life
Look for Path traversal attack outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Path traversal attack” →

How to study Path traversal attack in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Path traversal attack means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Path traversal attack out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Path traversal attack in simple terms?

A directory traversal, path traversal, or dot-dot-slash attack exploits insufficient security validation or sanitization of user-supplied file names, such that characters representing "traverse to parent directory" are passed through to the operating system's file system API. An affected applicatio…

Why does Path traversal attack matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Path traversal attack?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Path traversal attack.

Tags

  • Web security exploits

Keep exploring