Path Traversal that leads to Remote Code Execution via PHP file upload in ericferon/glpi-archimap
Reported on
Nov 15th 2022
📜 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
Impact
🚧 Impacts
An attacker could perform actions not intended by application like read, update or delete arbitrary files and directories stored on file system including application source code or configuration and critical system files. For example, an attacker can upload PHP file and obtain remote code execution on the system.