[wireguard-wrapper] Command Injection via insecure command concatenation
The wireguard-wrapper module passes user input directly into a shell command without sanitisation, allowing an attacker to execute arbitrary commands on the victim's machine. By supplying a crafted device name, an attacker can run any command with the privileges of the Node.js process.
- Triaged in 42 hours
- Fixed in 11 months
- Disclosed after 12 months
I would like to report a Command Injection issue in the wireguard-wrapper module.
It allows to execute arbitrary commands on the victim's PC.
Module
module name: wireguard-wrapper
version: 1.0.2
npm page: https://www.npmjs.com/package/wireguard-wrapper
Module Description
This project is a nodejs wrapper for the wireguard commands wg and wg-quick.
Features:
- No dependencies
- Uses promises
Limitations:
- So far it can only read but not write anything
- missing wg set, wg setconf, wg addconf, wg syncconf
Module Stats
[0] 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 wg showconf functionality.
Here's the code which causes the issue:
// https://github.com/rostwolke/node-wireguard-wrapper/blob/master/src/command/Wg.js#L58
'use strict';
const {exec} = require('child_process');
...
static showconf(device){
return new Promise(function(resolve, reject){
if(!device){
return reject('No device/interface specified');
}
exec(`wg showconf ${device}`, function(error, stdout, stderr){
if(error){
return reject(`Exec error: ${error}`);
}
if(stderr){
return reject(`StdErr: ${stderr}`);
}
....
As we can see the device parameter is passed as input to the exec function.
The function exec is the build-in function child_process.exec() taking in input the device variable build with the unsecure user's input.
Steps To Reproduce:
-
create a directory for testing
mkdir poccd poc/
-
install
wireguardtool (even though it is not needed to show the vulnerability) -
install
wireguard-wrappermodule:npm i --save wireguard-wrapper
-
create the following PoC JavaScript file (
poc.js):
const { Wg } = require('wireguard-wrapper');
Wg.showconf('; touch HACKED').then(function(config){
console.log('wg0 configuration:', config);
console.log('generated configuration file:', config.toString());
});
- 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 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: v13.13.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 wireguard-wrapper 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
The module uses child_process.exec with a string built from unsanitised user input, allowing shell metacharacters to inject additional commands.
Impact
An attacker could execute arbitrary commands on the victim's PC with the privileges of the Node.js process.
What the attacker needed
Victim uses wireguard-wrapper; attacker controls device parameter
How it was found
- Create a test directory and install the wireguard-wrapper module.
- Write a JavaScript file that calls Wg.showconf with a malicious device string.
- Run the file with Node.js.
- Observe that the injected command creates a file named HACKED.
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 is a command injection bug. The module takes a device name from the user and puts it directly into a system command without checking it. An attacker can add extra commands to the device name, and the computer will run them, letting the attacker do anything on the victim's machine.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.