[vboxmanage.js] Command Injection via insecure command concatenation
The vboxmanage.js npm module builds a shell command by joining user-supplied arguments and passes it to child_process.exec, so a crafted virtual machine name is interpreted by the shell. An attacker who can control that name can run arbitrary commands on the machine running the module.
- Triaged in 9 hours
- Fixed in 3 months
- Disclosed after 4 months
I would like to report a Command Injection issue in the vboxmanage.js module.
It allows to execute arbitrary commands on the victim's PC.
Module
module name: vboxmanage.js
version: 1.0.6
npm page: https://www.npmjs.com/package/vboxmanage.js
Module Description
A wrapper for VirtualBox CLI with Promises,
Module Stats
[2] weekly downloads
Vulnerability
Vulnerability Description
The issue occurs because a user input parameter is used inside a command that is executed without any check.
I tested the start function.
Here's the code which causes the issue:
// https://github.com/danielgindi/node-vboxmanage/blob/master/index.js#L76
...
var
child_process = require('child_process'),
...
VBoxManage.manage = function (command, options) {
command = command || [];
if (!(command instanceof Array)) {
command = [command];
}
options = options || {};
for (var i = 0; i < command.length; i++) {
command[i] = escapeArg(command[i]);
}
Object.keys(options).forEach(function (option) {
command.push('--' + option);
var value = options[option];
if (value !== true) {
command.push(escapeArg(value));
}
});
if (VBoxManage.debug) {
console.warn("$ VBoxManage " + command.join(" "));
}
return new Promise(function (resolve, reject) {
child_process.exec(vBoxManageBinary + ' ' + command.join(' '), {}, function (err, stdout, stderr) { // <-- injection
if (err) {
err.stderr = stderr;
return reject(err);
}
return resolve({ stdout: stdout, stderr: stderr });
});
});
};
...
VBoxManage.start = function (vmname, gui, options) {
options = options || {};
options['type'] = gui ? 'gui' : 'headless';
return this.manage(['-nologo', 'startvm', vmname], options); // <-- user input
};
...
The vmname parameter is used to build the command that is passed to the child_process.exec function without any check.
Steps To Reproduce:
-
create a directory for testing
mkdir poccd poc/
-
install
vboxmanage.jsmodule:npm i vboxmanage.js
-
create the following PoC JavaScript file (
poc.js):
var VBox = require('vboxmanage.js');
VBox.start(';touch HACKED;').then(function () {}).catch(function (err) {});
- make sure that the
HACKEDfile does not exist:ls
- execute the
poc.jsfile:node poc.js
- the
HACKEDfile is created:ls
Patch
Do not concatenate/format commands using insecure user's input. Always check and sanitize it.
In my opinion, it's better to use child_process.execFile or child_process.spawn functions instead of child_process.exec.
Supporting Material/References:
- OPERATING SYSTEM VERSION: Ubuntu 18.04.4 LTS
- NODEJS VERSION: v14.1.0
- NPM VERSION: 6.14.4
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Thank you for your time.
best regards,
d3lla
Impact
Command Injection on vboxmanage.js module via insecure command concatenation.
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
User input is concatenated into a command string passed to child_process.exec, which invokes a shell, instead of being passed as a separate argument to a non-shell execution function.
Impact
An attacker who can influence the virtual machine name passed to the module could execute arbitrary commands on the victim's PC.
What the attacker needed
The module is used by an application; attacker controls the vmname value
The fix
The module should stop concatenating user input into a shell command and instead use child_process.execFile or child_process.spawn with arguments passed separately.
How it was found
- Create a test directory and install the vboxmanage.js module.
- Write a small script that calls the start function with a virtual machine name containing shell metacharacters.
- Confirm the marker file does not exist yet.
- Run the script with node.
- Observe that the marker file has been 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 package is a small helper that runs the VirtualBox command-line tool for you. It glues the virtual machine name into a single text command and hands that text to the operating system shell, which treats characters like semicolons as 'run another command next'. So a name containing such characters makes the computer run whatever the attacker wrote.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.