Lucene search

K
huntrXanhacksB5F31D5E-EC54-438D-903E-7656666881C8
HistoryNov 15, 2022 - 10:54 a.m.

Path Traversal that leads to Remote Code Execution via PHP file upload

2022-11-1510:54:35
xanhacks
www.huntr.dev
10
path traversal
remote code execution
php
file upload
owasp
portswigger
mitigations
whitelist
extension parameter

📜 Description

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.

A classic example of path traversal attack to retrieve system files is : https://insecure-website.com/loadImage?filename=../../../etc/passwd.

In your application, path traversal occurs in the extension GET parameter of the ajax/putfile.php file.

🕵️ Proof of Concept

Abuse path traversal vulnerability to upload PHP file into the base root of GLPI

> The base64 content of PD9waHAgc3lzdGVtKCRfUkVRVUVTVFsnY21kJ10pOyA/Pg== is equals to <?php system($_REQUEST['cmd']); ?>.

Get remote code execution

🔐 Mitigations

In PHP, you can use the basename function to extracts the last element of a path.

Add a whitelist to the extension parameter to disable PHP file upload.

📚 References