Skip to content
RCE Disclosed report Intermediate

Image lib - unescaped file path

The image manipulation library passed file paths to the PHP exec function without escaping them, so a filename containing shell metacharacters could inject arbitrary commands. An attacker who can control the name of an uploaded image could therefore run commands on the server.

freetom Follow

Originally disclosed on HackerOne

  • Triaged in 32 hours
  • Fixed in 40 days
  • Disclosed after 53 days

Under ./system/ee/legacy/libraries/Image_lib.php

There are function from CodeIgniter to manipulate images. The issue is that the PHP function exec is used two times in two different functions: image_process_imagemagick and image_process_netpbm

In both cases the full_src_path and full_dst_path are given unescaped to the exec function. If an attacker can control the filename of the image to give he can inject pretty much arbitrary code. I suggest to use escapeshellarg on the path arguments at rows: -590 -604 -608 -691

Furthermore, note that in CodeIgniter Github repo, the function image_process_imagemagick that already prevents this potential injection. https://github.com/bcit-ci/CodeIgniter/blob/27647c9a8b5cd5a0e1fd78123316f359fe61a672/system/libraries/Image_lib.php#L892

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

Impact

An attacker able to control the image filename could inject arbitrary commands and run code on the server, though the text does not demonstrate this end to end.

What the attacker needed

Attacker controls the image filename

The fix

The paths passed to exec should be escaped with escapeshellarg at the listed lines, as the upstream CodeIgniter function already does.

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 a program builds a command line for the operating system, any special characters in the parts it inserts can be read as extra commands. Here the image library inserted a file path into a shell command without protecting it, so a crafted filename could smuggle in its own command. This is called command injection, and it can let an attacker run their own code on the server.

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 freetom

View all

2 more disclosed reports, best first.

More from ExpressionEngine

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.