# CVE-2022-40471

Remote code execution via unrestricted file upload vulnerability in the Clinic's Patient Management System v 1.0


# Technical description:

Remote Code Execution in Clinic's Patient Management System v 1.0 allows Attacker to Upload arbitrary php webshell via profile picture upload functionality in users.php

## Affected components - Source Code

in following Source Code we can see that developer directly allows to upload any media files without restricting an a specific extenstion which means we can upload any extensions file there which is not okay for security reasons and using this functionality flaw, attacker could upload malicious webshell to gain access complete server with root privileges

###### Mitigations: Please Restrict other extenstions while uploading an image file for profile picture upload functionality and allow only .jpg .png extensions which are only image related

Vulnerable Page - users.php

  // users.php
  $status = move_uploaded_file(
    'user_images/' . $targetFile

  if ($status) {
    try {

      $query = "INSERT INTO `users`(`display_name`,
`user_name`, `password`, `profile_picture`)
VALUES('$displayName', '$userName', '$encryptedPassword', '$targetFile');";

      $stmtUser = $con->prepare($query);


      $message = 'user registered successfully';
    } catch (PDOException $ex) {
      echo $ex->getTraceAsString();
      echo $ex->getMessage();
  } else {
    $message = 'a problem occured in image uploading.';


<!-- ![image](../CVE-2022-40471/Screenshot%202022-10-15%20103606.png) -->

# usage -

# Upload a simple webshell to the target machine -
python3 <target_ip> <target_port> <target_uri> <username> <password>

## Example -

python 80 /pms/ UserName Password

# Proof of concept (Poc) -

![Screenshot 2022-10-13 053055](

# References -

# Discovered & Developed by -

RashidKhan Pathan (iHexCoder), 9 September 2022.
Twitter: @itRashid