[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.
Originally disclosed on HackerOne
- 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:
- Install egg:
npm i egg --save - Install egg-scripts:
sudo npm i egg-scripts -g --save - Run eggctl with malicious argument:
eggctl start --daemon --stderr=/tmp/eggctl_stderr.log; touch /tmp/malicious - Check that the injected command was executed:
ls /tmp/ - 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.
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
- Install egg.
- Install egg-scripts globally.
- Run eggctl start with a malicious --stderr argument.
- Check that the injected command was executed.
- 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.