Lucene search

K
githubGitHub Advisory DatabaseGHSA-PWH2-FPFR-X5GF
HistoryMar 25, 2024 - 7:46 p.m.

phpMyFAQ's File Upload Bypass at Category Image Leads to RCE

2024-03-2519:46:11
CWE-434
GitHub Advisory Database
github.com
10
phpmyfaq
category image upload
content-type manipulation
lang parameter
rce
gifsicle
getfileextension
getfileextension vulnerability
file upload bypass

7.2 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

HIGH

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

8.5 High

AI Score

Confidence

High

0.0004 Low

EPSS

Percentile

9.1%

Summary

The category image upload function in phpmyfaq is vulnerable to manipulation of the Content-type and lang parameters, allowing attackers to upload malicious files with a .php extension, potentially leading to remote code execution (RCE) on the system.

Details

In the file upload function of the category image, the Content-type can be manipulated to return an empty string for the extension and the lang parameter can be set to .php. to allow an attacker to save a file as .PHP. This allows the uploading of web shells which could lead to RCE on phpmyfaq.

PoC

  1. Generate a fake .GIF file that contains a php command using the tool gifsicle
    a. Cmd: gifsicle < test1.gif --comment "<?php system('whoami'); ?>" > output.php.gif

    image

    b. The contents of the file should look like this:
    image

  2. Browse to β€œβ€¦/phpmyfaq/admin/?action=addcategory” and upload the fake .GIF file
    image

  3. Intercept the upload request and modify the params below and forward it:
    3a. lang parameter to .php.
    3b. Content-Type parameter from image/gif to image/gif2

    image

  4. Browse to the β€œ/phpmyfaq/images” directory and notice that our fake .GIF file has been uploaded as a PHP file with the category number as its filename.
    image

  5. Now we just need to browse to β€œβ€¦/phpmyfaq/images/category-<ID>-.php” and see the results of our whoami command. Hence, verifying that RCE is achieved.
    image

Impact

Attackers can upload malicious files containing executable code, allowing them to take control of the vulnerable system. This enables them to execute arbitrary commands, steal sensitive data, disrupt services, and potentially escalate their privileges, posing significant risks to the security and integrity of the system and its data.

Occurrences

In CategoryImage.php line 124, the getimagesize and isValidMimeType functions can be bypassed by uploading a fake .GIF file generated by gifsicle.
image

In CategoryImage.php line 85, the getFileExtension function returns an empty string when the content type doesnt match any of the following 3 mappings. Hence, its possible to just supply an invalid content type such as image/gif2 in step 3 of the PoC to make the function return an empty string.
image

In CategoryImage.php line 66, the getFileName function generate the filename by concatenating the categoryId, categoryName and fileExtension together. This allows us to save the file with a .PHP extension. (It should be possible to just set the payload in step 3 above to just .php but it doesnt work and im not sure why…)
image

Suggested Fix

I believe one of the ways to solve this vulnerability is by forcing the getFileExtension function to return one of the 3 mimetype instead of an empty string. This ensures that the uploaded file will have an image extension and will not execute as a PHP file.

Affected configurations

Vulners
Node
phpmyfaqphpmyfaqMatch3.2.5
CPENameOperatorVersion
phpmyfaq/phpmyfaqeq3.2.5

7.2 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

HIGH

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

8.5 High

AI Score

Confidence

High

0.0004 Low

EPSS

Percentile

9.1%

Related for GHSA-PWH2-FPFR-X5GF