Pre-Auth Path traversal in pimcore_log, leading potential DOS in pimcore/pimcore

Valid

Reported on

Apr 30th 2023


Description

A path traversal vulnerability exists in the CMS, which allows an attacker to overwrite or modify sensitive files by manipulating the pimcore_log parameter.

This can lead to potential denial of service---key file overwrite.

Proof of Concept

  • As a prequisition, pimcore must be installed in a Windows environment
  • Another preq: self::inDebugMode()==true
  1. The CMS fails to sanitize the input properly and creates a file outside the intended log directory, resulting in a path traversal vulnerability.
  2. An attacker can send a request with the pimcore_log parameter set to a value that starts with a valid log file name, followed by a series of ..\ to traverse directories.

code

The vulnerability is present in the initLogger() function of the CMS:

public static function initLogger(): void
{
    // special request log -> if parameter pimcore_log is set
    if (array_key_exists('pimcore_log', $_REQUEST) && self::inDebugMode()) {
        $requestLogName = date('Y-m-d_H-i-s');
        if (!empty($_REQUEST['pimcore_log'])) {
            // slashed are not allowed, replace them with hyphens
            $requestLogName = str_replace('/', '-', $_REQUEST['pimcore_log']); // here 
        }

        $requestLogFile = resolvePath(PIMCORE_LOG_DIRECTORY . '/request-' . $requestLogName . '.log');
        if (strpos($requestLogFile, PIMCORE_LOG_DIRECTORY) !== 0) {
            throw new \Exception('Not allowed');
        }

        // ... rest of the function remains unchanged ...
    }
}

1. /admin/?pimcore_log=foo


2. /admin/?pimcore_log=foo.log\..\..\..\..\..\..\Windows\System32\drivers\etc\hosts

In this case, the etc\hosts file will be overwrite(need system privledge to the running pimcore)

Remediation

To address this issue, you can update the initLogger() function to sanitize the input properly. Modify the function by adding input validation and sanitization:

public static function initLogger(): void
{
    // special request log -> if parameter pimcore_log is set
    if (array_key_exists('pimcore_log', $_REQUEST) && self::inDebugMode()) {
        $requestLogName = date('Y-m-d_H-i-s');
        if (!empty($_REQUEST['pimcore_log'])) {
            // Slashes and backslashes are not allowed, replace them with hyphens
            $sanitizedInput = str_replace(['/', '\\'], '-', $_REQUEST['pimcore_log']);
            $requestLogName = resolvePath($sanitizedInput);
        }

        $requestLogFile = PIMCORE_LOG_DIRECTORY . '/request-' . $requestLogName . '.log';
        if (strpos($requestLogFile, PIMCORE_LOG_DIRECTORY) !== 0) {
            throw new \Exception('Not allowed');
        }

        // ... rest of the function remains unchanged ...
    }
}

Impact

The impact of this vulnerability could be severe, as it allows attackers to:

  • Overwrite or modify sensitive files, potentially leading to unauthorized access, privilege escalation, or disclosure of confidential information.

  • Tamper with system settings by modifying key files, such as the hosts file in Windows or configuration files for other services.

  • Cause a denial of service (DoS) if critical system files are overwritten or deleted.

  • The consequences of exploiting this vulnerability can be detrimental to the confidentiality, integrity, and availability of the affected system. It's crucial to address this vulnerability to protect sensitive data and ensure the proper functioning of the system.

  • I don't have a windows real env, so i add linux screenshot to prove that the CMS fails to satinize the [..] pattern image
We are processing your report and will contact the pimcore team within 24 hours. 5 months ago
hi-unc1e modified the report
5 months ago
hi-unc1e submitted a
5 months ago
We have contacted a member of the pimcore team and are waiting to hear back 5 months ago
Christian F. modified the Severity from High (7.3) to Medium (6.3) 5 months ago
The researcher has received a minor penalty to their credibility for miscalculating the severity: -1
Christian F. validated this vulnerability 5 months ago
hi-unc1e has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Divesh Pahuja
4 months ago

Maintainer


@hi-unc1e the correct affected version is 10.5.21. could you please fix it? thanks!

hi-unc1e
4 months ago

Researcher


@admin, can you change the affected version to 10.5.21,thanks

Ben Harvie
4 months ago

Admin


On it:)

Divesh Pahuja
4 months ago

Maintainer


@admin can you please also update the repository to pimcore/pimcore? thanks!

Ben Harvie
4 months ago

Admin


Hey Divesh, the repository has been updated as requested.

Divesh Pahuja
4 months ago

Maintainer


Thanks Ben!!

Divesh Pahuja marked this as fixed in 10.5.22 with commit e8dbc4 4 months ago
The fix bounty has been dropped
This vulnerability has been assigned a CVE
Divesh Pahuja published this vulnerability 4 months ago
to join this conversation