Security.com

directory traversal

By Ben Lutkevich

What is directory traversal?

Directory traversal is a type of HTTP exploit in which a hacker uses the software on a web server to access data in a directory other than the server's root directory. If the attempt is successful, the threat actor can view restricted files or execute commands on the server.

This type of attack is commonly performed using web browsers. Any server that fails to validate input data from web browsers is vulnerable to a directory traversal attack.

Directory traversal is also known as directory climbing, backtracking and file path traversal vulnerabilities. Directory traversal is similar to Structured Query Language injection and cross-site scripting in that they all involve code injection.

IT security professionals minimize the risk of a directory traversal with the following techniques:

How does directory traversal work?

Hackers use guesswork to find paths to restricted files on a web server. However, a skilled hacker can search the directory tree and easily execute this type of attack on an inadequately protected server.

Only a few resources are needed to perform a directory traversal attack, including the following ones:

What can an attacker do with directory traversal?

Once attackers access the root directory, they can enter other parts of the computer system. They may also be able to read and write arbitrary files on the server, enabling them to manipulate applications and associated data, read sensitive information like password files or take control of the server. Normally, users are unable to access any files outside of the web root folder.

Attackers can also gain control of access control lists (ACLs), which administrators use to grant various levels of file access to users. With access to ACLs, attackers can impersonate privileged users in the system to inflict damage.

How to check for directory traversal vulnerabilities

Here are two ways to manually check for directory traversal vulnerabilities:

  1. Input vector enumeration. Enumeration tells the tester which parts of a web application could be vulnerable to attempts to bypass input validation. The tester identifies parts of an application that accept user input, including POST and GET calls, file uploads and Hypertext Markup Language forms.
  2. Common patterns. Security pros can look for common patterns in the application's URL structure to identify directory traversal vulnerabilities. If an application uses a querystring parameter to specify the file path, an attacker may be able to manipulate this parameter to access files outside of the intended path. Search engines can also be used to find URLs that are likely to have file names included in them.

Automated tools are also used to check for traversal vulnerabilities. These tools perform the following testing techniques:

How to prevent directory traversal attacks

The most effective way to prevent these sorts of path traversal attacks is to avoid passing user input to file system application programming interfaces (APIs). Insufficient browser filtering and user input can leave web applications and web server files vulnerable to traversal attacks.

If passing user input to the file system APIs can't be avoided, here are other measures that can help prevent directory traversal:

Examples of directory traversal attacks

One way to perform directory traversal is to send URLs that contain the file name, plus various escape codes, to the server. This lets the attacker work around filtered characters. Using escape codes requires the attacker to guess which commands in a URL might be blocked, but that is not an impossible goal.

The following escape codes are ones that bypass URLs that block ../ commands:

%2e%2e/
%2e%2e%2f

Escape codes contain hexadecimal encodings of the blocked bits of the URL. %2f is hexadecimal for the forward slash, and %2e is hexadecimal for the period. If a website isn't configured to block the escape codes, an unauthorized user could type in this URL http://www.example.com/..%2f..%2f..%2fetc%2fpword in order to access this URL http://www.example.com/../../../etc/pword.

Another common way that hackers bypass file validation routines is by inserting null bytes into file names. For example, the phrase %00 is a null byte that can be injected to confuse a system when reading a file name. If an attacker sends the parameter ?file=protected.doc%00.pdf, a Java application sees a file name ending in .pdf, whereas an operating system sees a file ending in .doc. If the system is configured to block one but let the other through, this has a chance of bypassing validation routines.

Directory traversal attacks are among the many security risks IT professionals face. Learn how modern cloud security best practices can help defend against these and other common cyberthreats.

15 Jun 2022

All Rights Reserved, Copyright 2000 - 2024, TechTarget | Read our Privacy Statement