Skip to content
RCE Disclosed report Advanced CVE-2021-36766

Phar Deserialization Vulnerability via Logging Settings

The logging settings page passed the user-supplied log file path into a file_exists call without sanitising it, so a phar:// path could trigger PHP object deserialisation. An attacker with admin rights could use this to run arbitrary PHP code on the server.

egix Follow

Originally disclosed on HackerOne

Medium 6.4 View original
  • Triaged in 2 days
  • Fixed in 9 months
  • Disclosed after 9 months

Vulnerability Description:

The vulnerable code is located within the concrete/controllers/single_page/dashboard/system/environment/logging.php script. Specifically, into the Logging::update_logging() method:

    public function update_logging()
    {
        $config = $this->app->make('config');
        $request = $this->request;

        if (!$this->token->validate('update_logging')) {
            return $this->showError($this->token->getErrorMessage());
        }

        // Load in variables from the request
        $mode = (string) $request->request->get('logging_mode') === 'advanced' ? 'advanced' : 'simple';
        $handler = $mode === 'simple' ? (string) $request->request->get('handler', 'database') : null;
        $logFile = $handler === 'file' ? (string) $request->request->get('logFile') : null;
        $enableDashboardReport = $request->request->get('enable_dashboard_report') ? true : false;
        $loggingLevel = strtoupper((string) $request->request->get('logging_level'));
        $intLogErrorsPost = $request->request->get('ENABLE_LOG_ERRORS') === 1 ? 1 : 0;
        $intLogEmailsPost = $request->request->get('ENABLE_LOG_EMAILS') === 1 ? 1 : 0;
        $intLogApiPost = $request->request->get('ENABLE_LOG_API') === 1 ? 1 : 0;


        // Handle 'file' based logging
        if ($handler === 'file') {
            $directory = dirname($logFile);

            // Validate the file name
            if (pathinfo($logFile, PATHINFO_EXTENSION) !== 'log') {
                return $this->showError(t('The filename provided must be a valid filename and end with .log'));
            }

            // Validate the file path, create the log file if needed
            if (!file_exists($logFile)) {
                // If the file doesn't exist, make sure we can create one
                if (!is_writable($directory) || !is_dir($directory)) {
                    return $this->showError(t('Log file does not exist on the server. The directory of the file provided must exist and be writable on the web server.'));
                }

User input passed through the “logFile” request parameter is not properly sanitized before being used in a call to the file_exists function. This can be exploited by malicious users to inject arbitrary PHP objects into the application scope (PHP Object Injection via phar:// stream wrapper), allowing them to carry out a variety of attacks, such as executing arbitrary PHP code.

Reproduction Steps:

  1. Login to the Concrete5 instance as an admin user
  2. Go to "System & Settings" -> "Files" -> "Allowed File Types" and add log to File Extensions to Accept
  3. Use the attached Proof of Concept (PoC) script to create a sample Phar file to upload (just run php phar-generator.php from the CLI)
  4. Go to "Files" and upload the phar.log file
  5. Take note of the path where the file has been uploaded (e.g. application/files/4916/0848/5009/phar.log)
  6. Go to "System & Settings" -> "Environment" -> "Logging Settings" and select File as Handler
  7. Put the following string into the File text box: phar://./application/files/4916/0848/5009/phar.log
  8. Click the Save button, go to http://[host]/[concrete5]/application/files/tmp/test.php and you will see a "phpinfo" page

Notes:

The vulnerability has been successfully tested on Concrete5 versions 8.5.4 and 8.5.5 RC1.

Impact

This vulnerability might be abused by malicious users to inject and execute arbitrary PHP code on the web server. However, successful exploitation requires an admin account, and this partially mitigates the issue.

The original report as published on HackerOne, by egix. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker with an admin account could inject and execute arbitrary PHP code on the web server, though the admin requirement limits who can exploit it.

What the attacker needed

An admin account; ability to upload a .log file; logging handler set to file

How it was found

  1. Log in to the Concrete5 instance as an admin user.
  2. Allow the log file extension under the allowed file types settings.
  3. Generate a sample phar file with the provided script.
  4. Upload the phar file through the Files section and note its path.
  5. Open the logging settings, choose File as the handler and enter a phar:// path to the uploaded file.
  6. Save the settings and visit the generated test script to see the phpinfo page.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

PHP can treat a file path starting with phar:// as a special archive, and simply checking whether that file exists can make PHP unpack it and rebuild saved objects. If an attacker can upload a crafted archive and then point the app at it, those objects can run code. Here the logging settings page let an admin type such a path, so the check itself triggered the attack.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by egix

View all

13 more disclosed reports, best first.

More from Concrete CMS

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.