What is a Directory Traversal Vulnerability?

 

Directory Traversal Vulnerability

Directory Traversal Vulnerability: The Basics

It's a type of security hole that allows hackers to access restricted files and directories on your website.

They can do this by sending specially designed requests to an application, such as HTTP or FTP. Thus, requesting that the hacker be taken out of the current directory and into another.

This article will discuss how these vulnerabilities work and why they're so dangerous. We will also cover what you should do if you think that your site might have been compromised.

So whenever you're ready to learn more about this critical security topic, keep reading.

Directory Traversal Vulnerability: The Basics

A directory traversal vulnerability occurs when a user can exploit a weakness in how your site handles path information. This allows them to bypass access restrictions and move outside of the intended web root folder. This is where they can do further damage with another attack or gain more data from other systems on your network.

These vulnerabilities are most common in web applications written assuming that all data stays within a specific directory on your server. If they allow for unrestricted access to their contents, hackers can exploit them by changing the path portion of URLs appearing in any security-related files or software.

This allows them to gain unauthorized access and bypass certain restrictions set up as part of your website's authentication system. It may also give them direct read/write privileges over content stored elsewhere on the site, allowing for greater control during an attack.

Attackers will often use directory traversal vulnerabilities alongside other attacks like CSRF (cross-site request forgery). By exploiting one vulnerability, they can cause damage via another method without knowing sensitive information like a password.

Directory Traversal Examples

Here we will go over a few different methods attackers can use to exploit directory traversal vulnerabilities.

These examples assume that your website runs on a Unix-like web server and has the root directory set to "/var/HTML."

The first attack, using double dot DOS (../), can be performed by entering this in the URL bar of any page: "../../etc/passwd".

This code will access files outside of your intended folder structure, bypassing restrictions put in place for only certain pages. It also shows how easily an attacker could gain access to system administrator commands without knowing these types of vulnerabilities.

For instance, if they were able to get into /etc/, they would have complete control over all user accounts along with their passwords or other login information stored there.

2nd & 3rd Attacks

The second attack, using the "../" code (../), can be performed by entering this in the URL bar of any page: "/var/html/.htaccess.php."

This would allow attackers to access restricted information that appears only on a file called .htaccess within your root directory. It could also give them control over who has access to specific files and directories through other security features set up for PHP-based sites like WordPress or Joomla!

If they can modify web server configuration files, it may even help them delete entire portions of your site without being detected.

The last method we will show is not often used because it requires a little more work from an attacker.

The third attack, using the "//" code (///), can be performed by entering this in the URL bar of any page: "/var/html//etc/.htaccess.php."

This will allow them to access restricted system administrator commands like creating new users or deleting files on your server if they can modify .htaccess through another vulnerability first.

They would also have complete control over who has access to specific directories and their contents within that file unless you set up other security measures for it separately from the PHP-based sites mentioned above.

These examples show just how easy directory traversal vulnerabilities can be exploited even when put behind restrictions meant only for specific pages on a site. That makes it essential to stay informed about the vulnerabilities your site may be susceptible to and how you can prevent them from being exploited.

What Can A Hacker Do After A Directory Traversal Attack?

A successful attack through directory traversal vulnerabilities could allow attackers to modify, delete or view restricted files.

These changes can give them complete control over your website's security settings. This is until they are reversed by a web developer with the help of our recommended tools for scanning and fixing these types of issues. This also increases their ability to do further damage if malicious code is stored on your server that they have access to in this way.

They could then use it as part of various hacker attacks, including:

  • spamming other users
  • sending out phishing emails with links leading back to infected sites 
  • performing DDoS (distributed denial-of-service) attacks where multiple computers send requests at the same time to flood your server
  • attempt identity theft by trying out stolen payment information on other sites

Suppose they managed to get into the webroot directory and therefore had access to all of these files. In that case, this could give them complete control over your website's security settings. This is along with any unique configurations explicitly made on your site.

To prevent such attacks from occurring, we recommend using two different types of internet hosting accounts:

  • one dedicated solely for uploading and testing new code before moving it live
  • another with an unprivileged user account for uploading full website content.

This would allow you to prevent malicious code from being executed through directory traversal vulnerabilities if they were exploited before going live.

Attacks could also use these types of exploits as a stepping stone to carry out more advanced attacks like SQL injection or cross-site scripting (XSS), giving them even greater control over your web server's security settings by modifying configuration files that would typically require administrative privileges.

Preventing Attacks on Your Site

To avoid this vulnerability, developers must always assume that data can be accessed from anywhere and design their software accordingly. This means removing any access restrictions outside of the webroot folder and storing all files in there directly (i.e., not passing them through to another directory first).

You should also ensure that security-related software is free of such vulnerabilities before putting it into production use on your site.

Any detected flaws will need to be patched immediately, or you could expose yourself to more severe problems down the line when hackers begin using them against you in combination with other attacks.

Avoid using user input when making calls to the filesystem. If you can't avoid relying on it, normalize any information or path before utilizing it. Ensure that its prefix matches with directory users are permitted access to; otherwise known as permission checking!

It is essential to keep your web server and any sensitive application files separate. It's also critical that you do not store these types of things in the exact location, as this could lead to a severe security risk if something were ever to happen to one or both parts.

For instance: don't use an administrator account when running apps with limited permissions; instead, create superuser accounts so they can only read from where their data needs come from rather than edit other people's information - this will help lower risks. Significantly!

What to Do After An Attack

The next step for website owners who have already been hacked through a directory traversal vulnerability is to consider the best way to recover.

You may need a complete site rebuild if too much data was stolen or one compromised your security measures entirely. Still, you could also use it as an opportunity for improvement by finding ways to protect yourself in the future better.

Furthermore, it would help if you looked into options for keeping track of your users' activities. This can help you keep an eye out for any unusual activity that may indicate another type of attack, as well as find more hidden vulnerabilities in case one used them to get to your site in the first place.

How to Check for Vulnerabilities

An excellent way to check for directory traversal vulnerabilities in your website is to run it through a unique scanner. It can test its coding and look for that type of problem.

There are many types of vulnerability scanners you could use, but make sure they're one hundred percent up-to-date. Otherwise, you may not be able to get accurate results.

These scanners will help you find any vulnerabilities in your coding that may have led to the exploitation of directory traversal attacks so you can fix them before they are exploited by hackers again.

This will help prevent issues like these before they become problems later on down the line!

Input Vectors Enumeration

Input Vectors Enumeration is the act of discovering the possible sources, forms, and points within an application that one can use to inject user-supplied data.

This is typically carried out during a black box test against any web app or software with known vulnerabilities to determine if holes need patching up.

Input Vectors Enumeration would entail finding areas where user input could potentially come from (e.g., URL query string parameters, POST form fields) than validating them manually by entering special characters into critical locations that may produce unexpected results - e.g., adding "%20" between usernames & passwords when testing for SQL injection vulnerabilities.

Input Vectors Enumeration can be carried out manually or through automated tools that may already exist within your toolbox. Automated tools typically scan the source code of an application to find input vectors, while manual testing is done by people (i.e., web app pentesters) locating them themselves.

Manual Enumeration

Manual Input Vectors Enumeration should be conducted after you have identified points for user-supplied data entry and any potential sources, forms & locations where they could come from - e.g., URL query string parameters, POST form fields).

It's worth noting here that if there are no prominent places for users to enter their data, then it cannot happen, so these needn't necessarily be tested either! Once this is done, one should then list these points and the following tests conducted on each one.

  • Different types of input (e.g., upper case, lower case).
  • A single quote character ('), also known as an apostrophe or straight single quotation mark.
  • Single quotes within double quotes - e.g., 'I said "Hello!"'.
  • Double quotes within single quotes - e.g., I said "hello."

In addition to this, you could look out for file paths being parsed by your web application too!

These might not always work, but if they do, it's worth a go!.

For example: ../../passwd%507 would show all the passwords of your users!.

This is because it's telling the application to look at a file called 'passwd in the root directory, then take its 5072nd line and display it!.

Your Security Done Right

As you can see, a few different parts of your site need to be tested for potential directory traversal vulnerabilities. It's always best practice to do this kind of testing from an attacker's perspective.

They're the ones who will ultimately be trying out these attacks against real people on your website! If you test URL query string parameters and POST form fields for input vectors, then it should help prevent future attacks.

Remember not to forget about file paths as well. Sometimes hackers may try looking through some obscure locations on their web servers just in case something pops up!.

In closing, remember that all websites have security flaws whether or not anyone has ever heard about them before.

If you're interested in full-scale vulnerability scanning, get in touch with us, and we will happily accommodate your needs.