Just like you have directories on your PC, laptop, and mobile phones, web servers also have directories.
For example, if you were to purchase web hosting for your new website, the hosting provider would go out to their servers that have capacity, and then create a directory for your files to reside in.
As you create your website, you upload files to your reserved directory. Again, this is just like if you were to create a new directory on your PC right now, and moved files in it.
Except in the case of the webserver, that usually then becomes public so that your customers can visit your website.
If a malicious actor were to visit your website and find what’s called a directory or path traversal vulnerability, then they could potentially navigate beyond the public files and directories stored on the webserver in order to access restricted areas.
This is a really bad situation to be in because it often means that they can access configuration files, and those configuration files can either reveal credentials, or provide the attacker with additional ammunition.
Or, in the worst-case scenario, they may be able to access administrative files and directories which contain system passwords.
They could then use those credentials to login as administrators and take over the server.
Demo of path traversal
Let’s take a quick look at a demo of how this works and how it could be abused. I’m running a vulnerable web application called the DVWA. I show you how to set this up quickly and easily in this blog post if you’d like to try it yourself.
Once the application is up and running, go to File Inclusion. Once on this page, we can see that the URL is:
There’s a query parameter
?page= that takes a file name and uses that input to display the contents of the file on the page. In fact, if we click on any of the file names on this page:
We can see that it changes both the URL and what’s displayed.
An attacker might see this and try to traverse through directories in order to see if they can navigate beyond just these files. While this would normally take a little bit of trial and error to get right, I happen to know that this payload will work so we’ll save some time:
Instead of loading file1, 2, 3…, I’m telling the application and webserver to get me the
/etc/passwd file, and to display its contents on the page. Because this application is vulnerable, it will do just that:
/etc/passwd is a text-based database that has information for all user accounts on a Linux-based system. This is absolutely not a file that any unauthorized visitor of your application should be able to access, and so this basic exploit could cause serious damage.
How do you prevent Directory/Path traversals?
Because directory traversals can be exploited through vulnerable web applications, one place we need to look is in the application’s code. An attacker will submit inputs to try and find path traversal vulnerabilities, so it’s important that we verify all user input before processing it — especially if that user input will be used in code that pulls files directly from the webserver (just like we saw with the DVWA example)
A second place we need to look for directory traversal vulnerability is with the web server itself. Web servers running older versions of software may be vulnerable to this attack, so it’s important that you ensure you are running patched versions.
The way that your webserver is configured can also make a big difference. If it’s not properly configured, it may give too much flexibility that, again, enables this vulnerability.
Studying for the Security+?
We have free performance-based questions to help you practice, and we also offer paid upgrades for additional PBQs and for multiple-choice practice exams that mimic the real exam to help you prepare.