CVE-2018-21268 (published 2020-06-25T17:15Z)

The traceroute (aka node-traceroute) package through 1.0.0 for Node.js allows remote command injection via the host parameter. This occurs because the Child.exec() method, which is considered to be not entirely safe, is used. In particular, an OS command can be placed after a newline character.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed.
         

Fix information:
repo_url: https://github.com/jaw187/node-traceroute
commit_details: repo_url: https://github.com/jaw187/node-traceroute
author: James Weston
author_date: 2016-03-10 21:42:39-05:00
msg: conversion to spawn and stream
repository: repo_url: https://github.com/jaw187/node-traceroute
repo_name: jaw187/node-traceroute
description: Wrapper around native traceroute command
repo_language: JavaScript
owner: jaw187
file_changes: filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -10,10 +10,9 @@
   "engines": {
     "node": ">=4.0.0"
   },
-  "dependencies": {},
   "devDependencies": {
     "code": "2.x.x",
-    "lab": "9.x.x"
+    "lab": "10.x.x"
   },
   "bugs": {
     "url": "https://github.com/jaw187/node-traceroute/issues"

programming_language: JavaScript
filename: traceroute.js
change_type: ModificationType.MODIFY
diff: @@ -18,23 +18,43 @@ module.exports = internals.Traceroute = {};
 
 internals.Traceroute.trace = function (host, callback) {
 
-
     Dns.lookup(host.toUpperCase(), (err) => {
 
         if (err && Net.isIP(host) === 0) {
             return callback(new Error('Invalid host'));
         }
 
-        const command = (internals.isWin ? 'tracert -d ' : 'traceroute -q 1 -n ') + host;
-        Child.exec(command, (err, stdout, stderr) => {
+        const command = (internals.isWin ? 'tracert' : 'traceroute');
+        const args = internals.isWin ? ['-d', host] : ['-q', 1, '-n', host];
+
+        const traceroute = Child.spawn(command, args);
+
+        const hops = [];
+        let counter = 0;
+        traceroute.stdout.on('data', (data) => {
 
-            if (err) {
-                return callback(err);
+            ++counter;
+            if ((!internals.isWin && counter < 2) || (internals.isWin && counter < 5)) {
+                return null;
             }
 
-            const results = internals.parseOutput(stdout);
-            return callback(null, results);
+            const result = data.toString().replace(/\n$/,'');
+            if (!result) {
+                return null;
+            }
+
+            const hop = internals.parseHop(result);
+            hops.push(hop);
         });
+
+        traceroute.on('close', (code) => {
+
+            if (callback) {
+                return callback(null, hops);
+            }
+        });
+
+        return traceroute;
     });
 };
 
@@ -96,29 +116,3 @@ internals.parseHopNix = function (line) {
 
     return hop;
 };
-
-internals.parseOutput = function (output) {
-
-    const lines = output.split('\n');
-    const hops = [];
-
-    lines.shift();
-    lines.pop();
-
-    if (internals.isWin) {
-        for (let i = 0; i < lines.length; ++i) {
-            if (/^\s+1/.test(lines[i])) {
-                break;
-            }
-        }
-        lines.splice(0,i);
-        lines.pop();
-        lines.pop();
-    }
-
-    for (let i = 0; i < lines.length; ++i) {
-        hops.push(internals.parseHop(lines[i]));
-    }
-
-    return hops;
-};

programming_language: JavaScript