Skip to content
RCE Disclosed report Beginner CVE-2018-3786

[egg-scripts] Command injection

The egg-scripts tool does not sanitise the --stderr command line argument and passes it to child_process.exec(), allowing an attacker to inject arbitrary shell commands. An attacker who can control the --stderr argument can execute commands on the host.

pontus_johnson Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 6 hours
  • Fixed in 19 days
  • Disclosed after 19 days

I would like to report a command injection vulnerability in egg-scripts. It allows arbitrary shell command execution through a maliciously crafted command line argument.

Module

module name: [egg-scripts] version: [2.6.0] npm page: https://www.npmjs.com/package/egg-scripts

Module Description

"deploy tool for egg project."

Module Stats

Replace stats below with numbers from npm’s module page:

209 downloads in the last day 1,958 downloads in the last week 8,333 downloads in the last month

Vulnerability

Vulnerability Description

egg-script does not sanitize the --stderr command line argument, and subsequently passes it to child_process.exec(), thus allowing arbitrary shell command injection.

Steps To Reproduce:

  1. Install egg: npm i egg --save
  2. Install egg-scripts: sudo npm i egg-scripts -g --save
  3. Run eggctl with malicious argument: eggctl start --daemon --stderr=/tmp/eggctl_stderr.log; touch /tmp/malicious
  4. Check that the injected command was executed: ls /tmp/
  5. Stop eggctl: eggctl stop

Patch

Command execution happens here:

const [ stdout ] = yield exec('tail -n 100 ' + stderr);

exec could be replaced by execFile, which would force developers to separate the command and its arguments.

Supporting Material/References:

  • Operating system: Debian GNU/Linux 9.5 (stretch)
  • Node.js v8.11.3
  • npm v5.6.0

Wrap up

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

Impact

Arbitrary shell command execution.

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

The --stderr argument is concatenated into a shell command string passed to child_process.exec() without sanitisation.

Impact

Arbitrary shell command execution.

What the attacker needed

Ability to control the --stderr argument

The fix

The exec call should be replaced with execFile to separate the command and its arguments.

How it was found

  1. Install egg.
  2. Install egg-scripts globally.
  3. Run eggctl start with a malicious --stderr argument.
  4. Check that the injected command was executed.
  5. Stop eggctl.

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 tool takes a file path from the command line and runs a shell command to read that file. Because it does not check the path, someone can add extra shell commands after the path, and those commands will run with the same permissions as the tool.

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 pontus_johnson

View all

2 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.