Tuesday, December 3, 2024
HomeCross site ScriptingMailcow Mail Server Vulnerability Let Attackers Execute Remote Code

Mailcow Mail Server Vulnerability Let Attackers Execute Remote Code

Published on

SIEM as a Service

Two critical vulnerabilities (CVE-2024-31204 and CVE-2024-30270) affecting Mailcow versions before 2024-04 allow attackers to execute arbitrary code on the server.

An attacker can exploit these vulnerabilities by sending a specially crafted email to an administrator. 

When the administrator views the email while logged into the admin panel, the attacker can inject malicious scripts and gain complete control of the server.

- Advertisement - SIEM as a Service

Scan Your Business Email Inbox to Find Advanced Email Threats - Try AI-Powered Free Threat Scan

Mailcow’s admin panel in PHP uses a custom exception handler to store error messages in the user session, which are then retrieved and displayed in an alert box on the next page load. 

Result

The process involves parsing the session data, injecting the error messages into a JavaScript function call within a template, and finally rendering an alert box using a JavaScript library upon receiving the message in the browser. 

It creates a vulnerability because the error messages are not sanitized before being displayed, potentially allowing attackers to inject malicious scripts. 

CVE-2024-31204 is an XSS vulnerability in MailCow’s admin panel that exists because the jQuery-based notification library doesn’t escape HTML entities properly, allowing attackers to inject malicious scripts by controlling the content of an exception being raised. 

resulting string representation

The attacker can achieve this because the exception handler uses print_r() to include function call stack arguments in the error message, which bypasses Twig’s escaping mechanism. 

By sending a malicious email with a background image that references the vulnerable API endpoint with a specially crafted URL, an attacker can exploit the explode() function in json_api.php by providing an array as input through a crafted query string. 

The email client, bypassing restrictions due to the relative URL, executes the script embedded in the query string, injecting an XSS payload into the victim’s session for exploitation upon their next visit to the admin panel.  

malicious request

SonarCloud discovered a vulnerability (CVE-2024-30270) in MailCow’s rspamd_maps function that allows an attacker to overwrite arbitrary files, stems from insufficient validation of user-supplied input, which can lead to an attacker crafting a path traversal payload to overwrite system files. 

While this vulnerability can’t be used for arbitrary file creation due to existence checks, an attacker could overwrite critical PHP files with malicious code to compromise the server.  

An attacker can exploit a writable template cache directory in Mailcow’s Twig templating engine, and by overwriting a compiled template file with malicious code, the attacker can execute arbitrary commands when the corresponding page is accessed. 

While Mailcow’s disabled PHP functions mitigate this, the mail() function remains enabled, allowing attackers to craft emails with multi-stage payloads to bypass these restrictions and execute commands on the server. 

The mailcow maintainers addressed the XSS vulnerability (CVE-2024-31204) by encoding all HTML special characters in exception details before rendering them in the template.

For the file path vulnerability (CVE-2024-30270), they strengthened the validation logic to ensure only allowed map types are used.

Additionally, they implemented new security measures to prevent similar attacks in the future by adding checks to differentiate between API requests and normal web requests by looking for specific headers sent by browsers, such as the Referer header and the Sec-Fetch-Dest header.

Free Webinar! 3 Security Trends to Maximize MSP Growth -> Register For Free

Raga Varshini
Raga Varshini
Varshini is a Cyber Security expert in Threat Analysis, Vulnerability Assessment, and Research. Passionate about staying ahead of emerging Threats and Technologies.

Latest articles

PEFT-As-An-Attack, Jailbreaking Language Models For Malicious Prompts

Federated Parameter-Efficient Fine-Tuning (FedPEFT) is a technique that combines parameter-efficient fine-tuning (PEFT) with federated...

Hackers Cloning Websites, Exploiting RCE Flaws To Gain Access To Shopping Platforms

Cybercriminals are leveraging AI-powered phishing attacks, website cloning tools, and RCE exploits to target...

Hackers Exploited Windows Event Logs Tool log Manipulation, And Data Exfiltration

wevtutil.exe, a Windows Event Log management tool, can be abused for LOLBAS attacks. By...

Threat Actors Allegedly Claims Breach of EazyDiner Reservation Platform

Reports have emerged of a potential data breach involving EazyDiner, a leading restaurant reservation...

API Security Webinar

72 Hours to Audit-Ready API Security

APIs present a unique challenge in this landscape, as risk assessment and mitigation are often hindered by incomplete API inventories and insufficient documentation.

Join Vivek Gopalan, VP of Products at Indusface, in this insightful webinar as he unveils a practical framework for discovering, assessing, and addressing open API vulnerabilities within just 72 hours.

Discussion points

API Discovery: Techniques to identify and map your public APIs comprehensively.
Vulnerability Scanning: Best practices for API vulnerability analysis and penetration testing.
Clean Reporting: Steps to generate a clean, audit-ready vulnerability report within 72 hours.

More like this

Salesforce Applications Vulnerability Could Allow Full Account Takeover

A critical vulnerability has been discovered in Salesforce applications that could potentially allow a...

TP-Link HomeShield Function Vulnerability Let Attackers Inject Malicious Commands

A significant vulnerability has been identified in TP-Link's HomeShield function, affecting a range of...

HPE IceWall Flaw Let Attackers cause Unauthorized Data Modification

Hewlett Packard Enterprise (HPE) has issued an urgent security bulletin addressing a critical vulnerability...