Command Injection vulnerability in kill-port-process package
The kill-port-process package passed a caller-supplied port value into a shell command without sanitising it, so a value containing shell syntax would run as a command. An attacker who controls the port argument could therefore execute arbitrary commands with the privileges of the process, which the report says is root.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 5 months
- Disclosed after 6 months
I would like to report a command injection vulnerability in the kill-port-process package. It allows an attacker to inject arbitrary commands.
Module
module name: kill-port-process
version: 1.1.0
npm page: https://www.npmjs.com/package/kill-port-process
Module Stats
0 downloads in the last day 138 downloads in the last week 660 downloads in the last month
Vulnerability
Vulnerability Description
The attacker can control the port number. Then He/She can insert a shell command instead of a port number. The root user is the only user execute kill command on the OS, thus root will execute an arbitrary command.
Steps To Reproduce:
Installing the module: npm install kill-port-process -E
Following the example in the npm page:
const killPortProcess = require('kill-port-process');
const PORT = "$(<Shell Command>)";
await killPortProcess(PORT);
CLI mode:
kill-port "$(<Shell Command>)"
Patch
In the file src/lib/killer.ts:
Replace: import { exec } from 'child_process'
To: import { spawn } from 'child_process'
Supporting Material/References:
- Arch Linux 5.2.1 x64
- NODEJS 11.15.0
- NPM 6.10.2
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
An attacker can execute arbitrary commands on the victim's machine.
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 port value was interpolated into a string passed to child_process exec, which runs it through a shell, instead of being passed as a separate argument.
Impact
An attacker who can influence the port argument could run arbitrary commands on the host, and the report claims this happens as root, though that depends on how the package is invoked.
What the attacker needed
Attacker controls the port value; package runs with elevated privileges
The fix
The report suggests switching from exec to spawn so the value is not interpreted by a shell; it does not say whether this was applied.
How it was found
- Install the package at the stated version.
- Call the exported function, passing a port value that contains shell syntax.
- Alternatively run the command-line tool with the same crafted value.
- The shell interprets the injected part and runs the extra command.
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 meant to stop whatever program is using a given network port. It took the port number as text and handed it to the operating system's command shell, which treats certain characters as instructions rather than plain text. Because of that, someone who can choose the port value can sneak extra commands in, and those commands run with the same power as the program using the package.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.