[imagickal] Remote Code Execution
The imagickal npm module passed user-supplied input into ImageMagick shell commands without sanitisation, so a crafted filename could inject extra shell commands. An attacker who controls the input could run arbitrary commands on the victim's machine.
- Fixed in 3 months
- Disclosed after 4 months
I would like to report RCE in imagickal
It allows to execute arbitrary commands on the victim's PC
Module
module name: imagickal
version: 4.2.0
npm page: https://www.npmjs.com/package/imagickal
Module Description
node wrapper for ImageMagick commands
Module Stats
[42] weekly downloads
Vulnerability
Vulnerability Description
Code injection while processing a photo
Steps To Reproduce:
- Run
npm i imagickal - Create and run the following POC index.js:
var im = require('imagickal');
im.identify('image.jpg;touch HACKED;').then(function (data) {
console.log(data);
});
- The exploit worked and created the file -
HACKED
Patch
Check input before command
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Impact
Command Injection on imagickal module via insecure command
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 module concatenated user input into a shell command string without escaping or validation, allowing shell metacharacters to break out of the intended command.
Impact
An attacker could execute arbitrary commands on the victim's PC when a crafted filename is processed.
What the attacker needed
Victim processes attacker-supplied filename
How it was found
- Install the imagickal package with npm.
- Write a small script that calls the identify function with a crafted filename.
- Run the script and observe that an extra file was created.
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.
This module is a small helper that runs the ImageMagick program to inspect photos. It built a command line by gluing the filename straight into it, so a filename containing shell punctuation could add a second command. That let the author of the filename run their own programs on the computer doing the processing.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.