`whereis` concatenates unsanitized input into exec() command
The whereis npm module builds a shell command by joining the caller's filename argument into a string passed to exec() without escaping it. An attacker who can control that argument could run arbitrary shell commands on the host.
- Triaged in 13 days
- Fixed in 30 days
- Disclosed after 31 days
I would like to report command injection in whereis
It allows to inject arbitrary shell commands by trying to locate crafted filenames.
Module
module name: whereis
version: 0.4.0
npm page: https://www.npmjs.com/package/whereis
Module Description
Simply get the first path to a bin on any system.
Module Stats
Stats 101 downloads in the last day 5 403 downloads in the last week 18 945 downloads in the last month
~227 340 estimated downloads per year [JUST FOR REFERENCE, ~DOWNLOADS PER MONTH*12]
Vulnerability
Vulnerability Description
File name argument is not properly escaped before being concatenated into the command that is passed to exec().
See lines https://github.com/vvo/node-whereis/blob/master/index.js#L4-L12
Steps To Reproduce:
var whereis = require('whereis');
var filename = 'wget; touch /tmp/tada';
whereis(filename, function(err, path) {
console.log(path);
});
Observe file /tmp/tada created.
Supporting Material/References:
- Arch Linux Current
- Node.js 9.5.0
- npm 5.6.0
- bash 4.4.012
Wrap up
- I contacted the maintainer to let him know: N
- I opened an issue in the related repository: N
Impact
For setups where unsanitized user input could end up in whereis argument, users would be able to execute arbitrary shell commands.
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
Where unsanitised user input reaches the whereis argument, an attacker could execute arbitrary shell commands on the host.
What the attacker needed
Attacker controls the filename argument; app runs whereis on a shell-backed system
How it was found
- Load the whereis module in a Node.js script.
- Pass a filename containing shell metacharacters to whereis().
- Run the script and observe that an extra file was created, showing the injected command executed.
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 small library looks up where a program lives on the system. It does this by handing a text command to the operating system's shell, and it pastes the caller's file name straight into that command. Because the shell treats certain characters as instructions rather than plain text, a crafted name can make the shell run extra commands chosen by an attacker.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.