Cover Image

CVE-2023-50917

Introduction

MajorDoMo is a beacon in Russian home automation, particularly favored by Raspberry Pi aficionados, and has been a trusted name for over a decade. With over 380 stars on its official GitHub repository at the time of writing, its popularity is evident.

However, lurking within its thumb.php module is a severe unauthenticated Remote Code Execution (RCE) vulnerability designated as CVE-2023-50917. This article intricately explores this critical flaw, detailing its roots, distinct exploitation methods, and possible ramifications.

Key Information:

  • Affected Software: MajorDoMo
  • CVE ID: CVE-2023-50917
  • Vulnerability Type: Remote Command Execution (RCE)
  • Severity: Critical
  • Authentication: Not required (Unauthenticated)
  • Affected Component: /modules/thumb/thumb.php
  • Impact: Full server compromise possible

Vulnerability Summary

Field Details
CVE ID CVE-2023-50917
Affected Component /modules/thumb/thumb.php
Type Remote Command Execution (RCE)
Authentication Not required (Unauthenticated)
Attack Vector transport GET parameter
Impact Arbitrary command execution on the server
Severity Critical

Key Statistics:

  • Repository: sergejey/majordomo (380+ stars)
  • Use Case: Home automation system, popular with Raspberry Pi users
  • Vulnerability Exposure: Since before October 2023

Disclosure Timeline

Date Event
October 28, 2023 Initial discovery of the vulnerability (CVE-2023-50917)
October 29, 2023 Contacted MajorDoMo team detailing the vulnerability
November 6, 2023 After no response for over a week, submitted CVE request to appropriate CNA
November 14, 2023 New attempt to contact MajorDoMo team. Received response within a few hours. Patch applied
December 15, 2023 Public disclosure of CVE-2023-50917

Response Time

The MajorDoMo development team responded promptly after the second contact attempt, applying a patch within hours. The initial delay highlights the importance of multiple communication attempts in responsible disclosure.

Technical Background: The Vulnerable Code

The script /modules/thumb/thumb.php is primarily designed for thumbnail generation in MajorDoMo. It serves to facilitate the creation of thumbnails from various media sources. But within this benign purpose lies a significant vulnerability.

Vulnerability Analysis

The vulnerability stems from multiple security flaws in the code:

1. URL Decoding Without Validation:

$url = base64_decode($url);  // ⚠️ Decodes without validation

The script takes a base64 encoded url parameter and decodes it. This decoding process is pivotal, as it allows attackers to obfuscate their payloads, skirting around simple checks.

2. Weak Pattern Checks:

if (preg_match('/^rtsp:/is', $url) || preg_match('/\/dev/', $url)) {
    ...
}

The script then checks if the decoded url adheres to specific patterns (rtsp: or /dev). This is a rudimentary check to decide whether to process the URL. With the help of base64 encoding, it becomes trivial for attackers to bypass this verification.

3. Direct Command Construction (The Core Vulnerability):

if ($_GET['transport']) {
    $stream_options = '-rtsp_transport ' . $_GET['transport'] . ' ' . $stream_options;  // ⚠️ Direct injection
}

Impact:

Here lies the crux of the vulnerability. The transport parameter is taken directly and embedded within a system command without adequate sanitization. This glaring oversight allows for:

  • Arbitrary command injections
  • Full command execution via the exec function
  • Complete server compromise

Exploitation

Exploitation Avenues

The vulnerability can be exploited through multiple attack vectors:

1. Bypassing URL Validation:

The script’s initial validation checks for patterns such as rtsp: or /dev. By using base64 encoded strings, these checks can be easily bypassed:

url: cnRzcDovL2EK  (base64 for "rtsp://a")

2. Command Injection via the transport Parameter:

The transport parameter is used directly within a system command. With no sanitization in place, this can be exploited for command injections, leading to RCE.

Example Payload:

transport: ||echo; echo $(id)

Explanation:

  • The || operator allows command chaining
  • The echo command breaks out of the intended command context
  • The $(id) executes the id command, demonstrating RCE

Attack Flow:

  1. Encode a valid RTSP URL in base64 to bypass initial validation
  2. Inject malicious commands via the transport parameter
  3. Execute arbitrary commands on the server
  4. Gain full control of the MajorDoMo instance

Impact & Mitigation

Potential Impact

The severity of this RCE vulnerability is critical. Given MajorDoMo’s integral role in home automation, successful exploitation can result in:

  • Physical Security Compromise: Attackers can compromise physical security systems
  • Surveillance Access: Unauthorized access to surveillance cameras and monitoring systems
  • IoT Device Control: Taking control of other connected IoT devices
  • Data Theft: Access to sensitive home automation data and configurations
  • Server Compromise: Full control over the MajorDoMo server instance

Affected Systems

  • MajorDoMo installations: All versions prior to the patch (November 14, 2023)
  • Deployment: Primarily Raspberry Pi-based home automation systems
  • Exposure: Systems exposed to the internet are at highest risk

Mitigation

Users are strongly advised to:

  1. Update immediately to the latest version of MajorDoMo (post-November 14, 2023)
  2. Review any suspicious activity on affected systems
  3. Monitor server logs for exploitation attempts
  4. Restrict network access to MajorDoMo instances (use VPN or firewall rules)
  5. Apply security best practices, including input validation and command sanitization

Exploitation Tools

For those interested in further technical exploration, exploitation tools are available:

Metasploit Module

A Metasploit module provides an automated way to exploit the vulnerability within a framework familiar to security professionals:

  • Path: modules/exploits/linux/http/majordomo_cmd_inject_cve_2023_50917.rb
  • Repository: rapid7/metasploit-framework
  • Usage: Automated exploitation within the Metasploit framework

Recommendations for Mitigation

Security Best Practices

To prevent similar vulnerabilities in the future, implement the following security measures:

  1. Thorough Input Validation:

    • Rigorously validate all inputs before processing
    • Use whitelist approach for expected values
    • Validate base64 encoded inputs before decoding
    • Check against expected patterns and formats
  2. Sanitize Before Execution:

    • Sanitize all inputs before incorporating them into system commands
    • Use escapeshellarg() or similar functions for command parameters
    • Avoid string concatenation for command construction
  3. Limit Direct Command Execution:

    • Prefer using built-in PHP functions or secure APIs
    • Use array-based command execution instead of shell command strings
    • Implement proper error handling and logging
  4. Security Audit and Testing:

    • Conduct regular security code reviews
    • Perform penetration testing
    • Implement automated security scanning

Code Fix Example

Before (vulnerable):

if ($_GET['transport']) {
    $stream_options = '-rtsp_transport ' . $_GET['transport'] . ' ' . $stream_options;  // ⚠️ Direct injection
}

After (fixed):

if ($_GET['transport']) {
    $transport = escapeshellarg($_GET['transport']);  // Sanitize input
    $stream_options = '-rtsp_transport ' . $transport . ' ' . $stream_options;
}

Or better yet, use array-based command execution:

$process = new Process([
    'ffmpeg',
    '-rtsp_transport', $transport,  // Safe: array prevents injection
    $url
]);

Acknowledgments

I sincerely thank the MajorDoMo development team for their:

  • Response to the vulnerability report (after second contact attempt)
  • Patch release (November 14, 2023)
  • Recognition of the importance of this security issue

Conclusion

This vulnerability underscores the importance of:

  • Thorough code reviews: Regular security audits can identify vulnerabilities early
  • Robust input validation: All user inputs must be validated and sanitized
  • Secure coding practices: Avoid direct command execution with user input
  • Proactive security approach: Security should be considered at all development stages

Even established software projects like MajorDoMo are not immune to critical vulnerabilities. The discovery serves as a reminder of the ever-present need for diligence and a proactive approach to security in all software development stages.

This incident also highlights the importance of:

  • Multiple communication attempts in responsible disclosure
  • Persistence when reporting security issues
  • Collaboration between security researchers and software maintainers