Skip to content
RCE Disclosed report Beginner

`macaddress` concatenates unsanitized input into exec() command

The macaddress npm module concatenates the iface argument directly into shell commands passed to exec without sanitisation. An attacker who can control the iface argument could inject arbitrary shell commands.

chalker Follow

Originally disclosed on HackerOne

Critical 10.0 View original
  • Triaged in 18 days
  • Fixed in 2 months
  • Disclosed after 2 months

NOTE! Thanks for submitting a report! Please replace all the [square] sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!

I would like to report code injection in macaddress It allows to inject arbitrary shell commands if the user input can influence the iface argument.

Module

module name: macaddress version: 0.2.8 npm page: https://www.npmjs.com/package/macaddress

Module Description

Retrieve MAC addresses in Linux, OS X, and Windows.

Module Stats

81 238 downloads in the last day 1 632 083 downloads in the last week 7 031 342 downloads in the last month

~84376104 estimated downloads per year [JUST FOR REFERENCE, ~DOWNLOADS PER MONTH*12]

Vulnerability

Vulnerability Description

(async) .one(iface, callback) → string API does not escape or sanitize iface argument, and concatenates it to a shell command, passing it to exec.

Exact lines:

lib/linux.js:4:    exec("cat /sys/class/net/" + iface + "/address", function (err, out) {
lib/macosx.js:4:    exec("networksetup -getmacaddress " + iface, function (err, out) {
lib/unix.js:4:    exec("ifconfig " + iface, function (err, out) {

Steps To Reproduce:

For Linux, use the following example:

JavaScript
let iface = '../../../etc/passwd; touch /tmp/poof; echo ';
require('macaddress').one(iface, function (err, mac) {
  console.log("Mac address for this host: %s", mac);  
});

Observe /etc/passwd printed into the console, /tmp/poof file created.

For other OS, the testcase is similar.

Supporting Material/References:

State all technical information about the stack where the vulnerability was found

  • Arch Linux Current
  • Node.js 9.5.0
  • npm 5.6.0

Wrap up

  • I contacted the maintainer to let him know: N
  • I opened an issue in the related repository: N

Impact

Execute arbitrary shell commands if that parameter is user-controlled.

The original report as published on HackerOne, by chalker. 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

The iface argument is concatenated into a shell command string without escaping or validation before being passed to exec.

Impact

An attacker could execute arbitrary shell commands if the iface parameter is user-controlled.

What the attacker needed

Attacker controls the iface argument

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.

The library builds a command for the operating system by gluing together a fixed string and whatever value you give it. If that value contains special characters, the operating system runs extra commands. This lets an attacker run their own commands on the server.

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 chalker

View all

36 more disclosed reports, 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.