Skip to content
RCE Disclosed report Beginner

`command-exists` concatenates unsanitized input into exec()/execSync() commands

The command-exists module concatenated its command name argument into a shell command without escaping it, so shell metacharacters in that argument were interpreted by the shell. An attacker who could influence the argument could run arbitrary shell commands on the host.

chalker Follow

Originally disclosed on HackerOne

Critical 10.0 View original
  • Triaged in 14 hours
  • Fixed in 2 months
  • Disclosed after 2 months

I would like to report command injection in command-exists. It allows to inject and execute arbitrary shell commands while trying to determine if a crafted command exists.

Module

module name: command-exists version: 1.2.2 npm page: https://www.npmjs.com/package/command-exists

Module Description

node module to check if a command-line command exists

Module Stats

5 480 downloads in the last day 74 405 downloads in the last week 294 869 downloads in the last month

Vulnerability

Vulnerability Description

commandName argument is not properly escaped before being concatenated into the command that is passed to exec()/execSync().

See https://github.com/mathisonian/command-exists/blob/v1.2.2/lib/command-exists.js#L49-L94

Steps To Reproduce:

JavaScript
const commandExists = require('command-exists');
commandExists.sync('ls; touch /tmp/foo0');
commandExists('ls; touch /tmp/foo1');

Observe /tmp/foo0 and /tmp/foo1 being created.

Supporting Material/References:

  • Arch Linux current
  • Node.js 9.7.1
  • npm 5.7.1

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Impact

For setups where unsanitized user input could end up in command-exists argument, users would be able to execute arbitrary shell commands.

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

Where unsanitised user input reaches the library's argument, an attacker could execute arbitrary shell commands on the host.

What the attacker needed

Attacker controls the command name argument

How it was found

  1. Call the library's sync function with a command name containing a shell separator and a second command.
  2. Call the async function the same way.
  3. Observe that the extra commands ran, creating the files.

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 checks whether a program is installed on the machine. It built the check by gluing the name you give it onto a shell command, and a shell treats characters like semicolons as 'now run another command'. So a name containing such characters made the shell run extra commands chosen by the attacker.

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 chalker

View all

36 more disclosed reports, best first.

More from Node.js third-party modules

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.