Command Injection is ps Package
The ps Node.js package passed a caller-supplied PID value into a shell command without validation, so a value containing shell syntax was executed as an operating system command. An attacker who could control the PID argument could run arbitrary commands on the host.
Originally disclosed on HackerOne
- Triaged in 26 days
- Fixed in 32 days
- Disclosed after 32 days
Summary by the program
vulnerable_versions: < 1.0.0 patched_version: >= 1.0.0
The report
I would like to report a command injection in ps package. It allows attacker to inject arbitrary OS commands instead of PID numbers.
Module
module name: ps
version: 0.0.2
npm page: https://www.npmjs.com/package/ps
Module Description
A Node.js module for looking up running processes.
Module Stats
39 downloads in the last week
Vulnerability
Vulnerability Description
The ps package expects a valid PID number, but an attacker can inject arbitrary commands instead.
Steps To Reproduce:
var ps = require('ps');
ps.lookup({ pid: "$(touch success.txt)" }, function(err, proc) { // this method is vulnerable to command injection
if (err) {throw err;}
if (proc) {
console.log(proc); // Process name, something like "node" or "bash"
} else {
console.log('No such process');
}
});
Patch
N/A replace exec with spawn
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
If the attacker can control the PID, she can inject arbitrary OS commands.
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 PID was concatenated into a shell command string executed via exec, so shell metacharacters in the value were interpreted rather than treated as data.
Impact
If the attacker can control the PID, she can inject arbitrary OS commands.
What the attacker needed
Attacker controls the PID argument
The fix
The report suggests replacing exec with spawn so the PID is passed as an argument rather than interpreted by a shell.
How it was found
- Call the package's lookup function with a PID value that contains shell syntax instead of a number.
- The package runs the resulting command through the shell, executing the injected 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 looks up running processes on a computer. It built a command line by pasting in whatever value the caller gave as the process ID, and the shell then treated parts of that value as extra commands. So a value that should be a number could instead make the machine run something else.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.