
RCE 익스플로잇 및 연구
Clinic's Patient Management System v 1.0의 무제한 파일 업로드 취약점을 통한 원격 코드 실행

Clinic's Patient Management System v 1.0의 원격 코드 실행 취약점으로 인해 공격자는 users.php의 프로필 사진 업로드 기능을 통해 임의의 PHP 웹쉘을 업로드할 수 있습니다.
다음 소스 코드에서 개발자가 특정 확장자를 제한하지 않고 모든 미디어 파일을 직접 업로드하도록 허용하는 것을 볼 수 있습니다. 즉, 보안상 바람직하지 않은 임의의 확장자 파일을 업로드할 수 있으며, 이 기능 결함을 이용하면 공격자는 악성 웹쉘을 업로드하여 루트 권한으로 서버 전체에 대한 액세스 권한을 얻을 수 있습니다.
취약한 페이지 - users.php
// users.php
$status = move_uploaded_file(
$_FILES["profile_picture"]["tmp_name"],
'user_images/' . $targetFile
);
if ($status) {
try {
$con->beginTransaction();
$query = "INSERT INTO `users`(`display_name`,
`user_name`, `password`, `profile_picture`)
VALUES('$displayName', '$userName', '$encryptedPassword', '$targetFile');";
$stmtUser = $con->prepare($query);
$stmtUser->execute();
$con->commit();
$message = 'user registered successfully';
} catch (PDOException $ex) {
$con->rollback();
echo $ex->getTraceAsString();
echo $ex->getMessage();
exit;
}
} else {
$message = 'a problem occured in image uploading.';
}
header("location:congratulation.php?goto_page=users.php&message=$message");
exit;
}
# Upload a simple webshell to the target machine -
python3 CVE-2022-40471.py <target_ip> <target_port> <target_uri> <username> <password>
python CVE-2022-40471.py 127.0.0.1 80 /pms/ UserName Password

https://drive.google.com/file/d/1m-wTfOL5gY3huaSEM3YPSf98qIrkl-TW/view?usp=sharing
https://www.sourcecodester.com/php-clinics-patient-management-system-source-code
https://www.sourcecodester.com/sites/default/files/download/oretnom23/php-cpms.zip
RashidKhan Pathan (iHexCoder), 2022년 9월 9일. Twitter: @itRashid