Skip to content
RCE Disclosed report Beginner CVE-2018-16461

Command Injection Vulnerability in libnmap Package

The libnmap package passed the user-supplied scan range directly into a shell command, so an attacker who controls the range could run arbitrary operating system commands. The report demonstrates this by injecting a command that creates a file.

cris_semmle Follow

Originally disclosed on HackerOne

Medium 6.8 View original
  • Triaged in 25 days
  • Fixed in 39 days
  • Disclosed after 2 months

Summary by the program

vulnerable_versions: <0.4.16 patched_versions: >=0.4.16

The report

I would like to report a command injection vulnerability in libnmap. It allows an attacker to inject arbitrary OS commands instead of a valid network range to be scanned.

Module

module name: libnmap version: 0.4.11 npm page: https://www.npmjs.com/package/libnmap

Module Description

API to access nmap from node.js

Module Stats

101 downloads in the last week

Vulnerability

Vulnerability Description

If the attacker is allowed to provide the "range" field for the network scan, she can inject arbitrary OS commands instead of a valid IP range.

Steps To Reproduce:

JavaScript
const nmap = require('libnmap');
const opts = {
    range: [
        'scanme.nmap.org',
        "x.x.$(touch success.txt)"
    ]
};
nmap.scan(opts, function(err, report) {
    if (err) throw new Error(err);

    for (let item in report) {
        console.log(JSON.stringify(report[item]));
    }
});

Patch

N/A use spawn instead of exec

Wrap up

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

Impact

The attacker can run arbitrary OS commands using this module.

The original report as published on HackerOne, by cris_semmle. 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 a shell-based execution function (exec) with the user-controlled range string, allowing shell metacharacters to be interpreted as commands.

Impact

An attacker who can control the scan range can run arbitrary OS commands on the machine running the library.

What the attacker needed

Attacker controls the range field; application uses libnmap to scan

How it was found

  1. Require the libnmap module in a Node.js script.
  2. Create an options object with a range array containing a normal host and a malicious entry with a shell command.
  3. Call nmap.scan with those options and a callback.
  4. The injected command is intended to create a file as proof.

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 library builds a system command from a value the user provides, and because it does not separate the value from the command, an attacker can add extra commands that the computer will run. In this case, the scan range is used unsafely, so a malicious range can make the server run anything.

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 cris_semmle

View all

8 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.