CVE-2020-7778 (published 2020-11-26T11:15Z)

This affects the package systeminformation before 4.30.2. The attacker can overwrite the properties and functions of an object, which can lead to executing OS commands.

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

Weakness information:
cwe_id: CWE-78
cwe_name: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
extended_description: 
		   This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
            There are at least two subtypes of OS command injection:
               
				 The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
				 The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
               
            From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
         
         

Fix information:
repo_url: https://github.com/sebhildebrandt/systeminformation
commit_details: repo_url: https://github.com/sebhildebrandt/systeminformation
author: Sebastian Hildebrandt
author_date: 2020-11-25 06:58:06+01:00
msg: security update (prototype pollution prevention)
repository: repo_url: https://github.com/sebhildebrandt/systeminformation
repo_name: sebhildebrandt/systeminformation
description: System Information Library for Node.JS
repo_language: JavaScript
owner: sebhildebrandt
file_changes: filename: internet.js
change_type: ModificationType.MODIFY
diff: @@ -35,14 +35,14 @@ function inetChecksite(url, callback) {
     process.nextTick(() => {
       let urlSanitized = '';
       const s = util.sanitizeShellString(url);
-      for (i = 0; i <= 2000; i++) {
+      for (let i = 0; i <= 2000; i++) {
         if (!(s[i] === undefined ||
           s[i] === ' ' ||
           s[i] === '{' ||
           s[i] === '}')) {
           const sl = s[i].toLowerCase();
           if (sl[0] && !sl[1]) {
-            urlSanitized = urlSanitized + sl[i];
+            urlSanitized = urlSanitized + sl[0];
           }
         }
       }

programming_language: JavaScript
filename: network.js
change_type: ModificationType.MODIFY
diff: @@ -1134,13 +1134,13 @@ function networkStatsSingle(iface) {
                   // skip header line
                   // use the second line because it is tied to the NIC instead of the ipv4 or ipv6 address
                   stats = lines[1].replace(/ +/g, ' ').split(' ');
-                  rx_bytes = parseInt(stats[6]);
-                  rx_dropped = parseInt(stats[11]);
-                  rx_errors = parseInt(stats[5]);
-                  tx_bytes = parseInt(stats[9]);
-                  tx_dropped = parseInt(stats[11]);
-                  tx_errors = parseInt(stats[8]);
-
+                  const offset = stats.length > 11 ? 1 : 0;
+                  rx_bytes = parseInt(stats[offset + 5]);
+                  rx_dropped = parseInt(stats[offset + 10]);
+                  rx_errors = parseInt(stats[offset + 4]);
+                  tx_bytes = parseInt(stats[offset + 8]);
+                  tx_dropped = parseInt(stats[offset + 10]);
+                  tx_errors = parseInt(stats[offset + 7]);
                   result = calcNetworkSpeed(ifaceSanitized, rx_bytes, tx_bytes, result.operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
                 }
               }

programming_language: TypeScript
filename: util.js
change_type: ModificationType.MODIFY
diff: @@ -492,7 +492,7 @@ function countLines(lines, startingWith) {
 function sanitizeShellString(str) {
   const s = str || '';
   let result = '';
-  for (i = 0; i <= 2000; i++) {
+  for (let i = 0; i <= 2000; i++) {
     if (!(s[i] === undefined ||
       s[i] === '>' ||
       s[i] === '<' ||
@@ -520,7 +520,7 @@ function sanitizeShellString(str) {
 }
 
 function isPrototypePolluted() {
-  s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  const s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
   let notPolluted = true;
   let st = '';
   notPolluted = notPolluted || !(s.length === 62)
@@ -528,7 +528,7 @@ function isPrototypePolluted() {
   if (typeof ms === 'number' && ms > 1600000000000) {
     const l = ms % 100 + 15;
     let c = 0;
-    for (i = 0; i < l; i++) {
+    for (let i = 0; i < l; i++) {
       const r = Math.random() * 61.99999999 + 1;
       const rs = parseInt(Math.floor(r).toString(), 10)
       const rs2 = parseInt(r.toString().split('.')[0], 10);
@@ -561,7 +561,7 @@ function isPrototypePolluted() {
     // lower
     const stl = st.toLowerCase();
     notPolluted = notPolluted && (stl.length === l) && stl[l - 1] && !(stl[l])
-    for (i = 0; i < l; i++) {
+    for (let i = 0; i < l; i++) {
       const s1 = st[i];
       const s2 = stl[i];
       const s1l = s1.toLowerCase();

programming_language: JavaScript
repo_url: https://github.com/sebhildebrandt/systeminformation
commit_details: repo_url: https://github.com/sebhildebrandt/systeminformation
author: Sebastian Hildebrandt
author_date: 2020-11-25 04:41:31+01:00
msg: security update (prototype pollution prevention)
repository: repo_url: https://github.com/sebhildebrandt/systeminformation
repo_name: sebhildebrandt/systeminformation
description: System Information Library for Node.JS
repo_language: JavaScript
owner: sebhildebrandt
file_changes: filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -30,6 +30,8 @@ For major (breaking) changes - version 3 and 2 see end of page.
 
 | Version        | Date           | Comment  |
 | -------------- | -------------- | -------- |
+| 4.30.2         | 2020-11-25     | security update (prototype pollution prevention) |
+| 4.30.1         | 2020-11-12     | updated docs |
 | 4.30.0         | 2020-11-12     | `get()` possibility to provide params |
 | 4.29.3         | 2020-11-09     | `blockdevices()` catch errors adapted for just one line |
 | 4.29.2         | 2020-11-09     | `blockdevices()` catch errors |

programming_language: Markdown
filename: history.html
change_type: ModificationType.MODIFY
diff: @@ -83,6 +83,16 @@
                   </tr>
                 </thead>
                 <tbody>
+                  <tr>
+                    <th scope="row">4.30.2</th>
+                    <td>2020-11-25</td>
+                    <td>security update (prototype pollution prevention)</td>
+                  </tr>
+                  <tr>
+                    <th scope="row">4.30.1</th>
+                    <td>2020-11-12</td>
+                    <td>updated docs</td>
+                  </tr>
                   <tr>
                     <th scope="row">4.30.0</th>
                     <td>2020-11-11</td>

programming_language: HTML
filename: index.html
change_type: ModificationType.MODIFY
diff: @@ -168,7 +168,7 @@
       <img class="logo" src="assets/logo.png">
       <div class="title">systeminformation</div>
       <div class="subtitle"><span id="typed"></span></div>
-      <div class="version">Current Version: <span id="version">4.30.0</span></div>
+      <div class="version">Current Version: <span id="version">4.30.2</span></div>
       <button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
     </div>
     <div class="down">

programming_language: HTML
filename: internet.js
change_type: ModificationType.MODIFY
diff: @@ -33,21 +33,26 @@ function inetChecksite(url, callback) {
 
   return new Promise((resolve) => {
     process.nextTick(() => {
-
-      let urlSanitized = util.sanitizeShellString(url).toLowerCase();
-      urlSanitized = urlSanitized.replace(/ /g, '');
-      urlSanitized = urlSanitized.replace(/\$/g, '');
-      urlSanitized = urlSanitized.replace(/\(/g, '');
-      urlSanitized = urlSanitized.replace(/\)/g, '');
-      urlSanitized = urlSanitized.replace(/{/g, '');
-      urlSanitized = urlSanitized.replace(/}/g, '');
+      let urlSanitized = '';
+      const s = util.sanitizeShellString(url);
+      for (i = 0; i <= 2000; i++) {
+        if (!(s[i] === undefined ||
+          s[i] === ' ' ||
+          s[i] === '{' ||
+          s[i] === '}')) {
+          const sl = s[i].toLowerCase();
+          if (sl[0] && !sl[1]) {
+            urlSanitized = urlSanitized + sl[i];
+          }
+        }
+      }
       let result = {
         url: urlSanitized,
         ok: false,
         status: 404,
         ms: -1
       };
-      if (urlSanitized) {
+      if (urlSanitized && !util.isPrototypePolluted()) {
         let t = Date.now();
         if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
           let args = ' -I --connect-timeout 5 -m 5 ' + urlSanitized + ' 2>/dev/null | head -n 1 | cut -d " " -f2';
@@ -114,7 +119,7 @@ function inetLatency(host, callback) {
   }
 
   host = host || '8.8.8.8';
-  const hostSanitized = util.sanitizeShellString(host);
+  const hostSanitized = util.isPrototypePolluted() ? '8.8.8.8' : util.sanitizeShellString(host);
 
   return new Promise((resolve) => {
     process.nextTick(() => {

programming_language: JavaScript
filename: network.js
change_type: ModificationType.MODIFY
diff: @@ -1041,7 +1041,7 @@ function networkStatsSingle(iface) {
   return new Promise((resolve) => {
     process.nextTick(() => {
 
-      const ifaceSanitized = util.sanitizeShellString(iface);
+      const ifaceSanitized = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
 
       let result = {
         iface: ifaceSanitized,

programming_language: TypeScript
filename: processes.js
change_type: ModificationType.MODIFY
diff: @@ -103,6 +103,9 @@ function services(srv, callback) {
         if (srvString === '') {
           srvString = '*';
         }
+        if (util.isPrototypePolluted() && srvString !== '*') {
+          srvString = '------';
+        }
         let srvs = srvString.split('|');
         let result = [];
         let dataSrv = [];
@@ -837,7 +840,7 @@ function processLoad(proc, callback) {
 
   return new Promise((resolve) => {
     process.nextTick(() => {
-      const procSanitized = util.sanitizeShellString(proc);
+      const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc);
 
       let result = {
         'proc': procSanitized,

programming_language: JavaScript
filename: util.js
change_type: ModificationType.MODIFY
diff: @@ -490,29 +490,87 @@ function countLines(lines, startingWith) {
 }
 
 function sanitizeShellString(str) {
-  let result = str || '';
-  result = result.replace(/>/g, '');
-  result = result.replace(/</g, '');
-  result = result.replace(/\*/g, '');
-  result = result.replace(/\?/g, '');
-  result = result.replace(/\[/g, '');
-  result = result.replace(/\]/g, '');
-  result = result.replace(/\|/g, '');
-  result = result.replace(/\`/g, '');
-  result = result.replace(/\$/g, '');
-  result = result.replace(/;/g, '');
-  result = result.replace(/&/g, '');
-  result = result.replace(/\)/g, '');
-  result = result.replace(/\(/g, '');
-  result = result.replace(/\$/g, '');
-  result = result.replace(/#/g, '');
-  result = result.replace(/\\/g, '');
-  result = result.replace(/\t/g, '');
-  result = result.replace(/\n/g, '');
-  result = result.replace(/\"/g, '');
+  const s = str || '';
+  let result = '';
+  for (i = 0; i <= 2000; i++) {
+    if (!(s[i] === undefined ||
+      s[i] === '>' ||
+      s[i] === '<' ||
+      s[i] === '*' ||
+      s[i] === '?' ||
+      s[i] === '[' ||
+      s[i] === ']' ||
+      s[i] === '|' ||
+      s[i] === '˚' ||
+      s[i] === '$' ||
+      s[i] === ';' ||
+      s[i] === '&' ||
+      s[i] === '(' ||
+      s[i] === ')' ||
+      s[i] === ']' ||
+      s[i] === '#' ||
+      s[i] === '\\' ||
+      s[i] === '\t' ||
+      s[i] === '\n' ||
+      s[i] === '"')) {
+      result = result + s[i];
+    }
+  }
   return result;
 }
 
+function isPrototypePolluted() {
+  s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  let notPolluted = true;
+  let st = '';
+  notPolluted = notPolluted || !(s.length === 62)
+  const ms = Date.now();
+  if (typeof ms === 'number' && ms > 1600000000000) {
+    const l = ms % 100 + 15;
+    let c = 0;
+    for (i = 0; i < l; i++) {
+      const r = Math.random() * 61.99999999 + 1;
+      const rs = parseInt(Math.floor(r).toString(), 10)
+      const rs2 = parseInt(r.toString().split('.')[0], 10);
+      const q = Math.random() * 61.99999999 + 1;
+      const qs = parseInt(Math.floor(q).toString(), 10)
+      const qs2 = parseInt(q.toString().split('.')[0], 10);
+      notPolluted = notPolluted && !(r === q);
+      notPolluted = notPolluted && rs === rs2 && qs === qs2;
+      st += s[rs - 1];
+    }
+    notPolluted = notPolluted && st.length === l;
+    // string manipulation
+    let p = Math.random() * l * 0.9999999999;
+    let stm = st.substr(0, p) + ' ' + st.substr(p, 2000);
+    let sto = stm.replace(/ /g, '');
+    notPolluted = notPolluted && st === sto;
+    p = Math.random() * l * 0.9999999999;
+    stm = st.substr(0, p) + '{' + st.substr(p, 2000);
+    sto = stm.replace(/{/g, '');
+    notPolluted = notPolluted && st === sto;
+    p = Math.random() * l * 0.9999999999;
+    stm = st.substr(0, p) + '*' + st.substr(p, 2000);
+    sto = stm.replace(/\*/g, '');
+    notPolluted = notPolluted && st === sto;
+    p = Math.random() * l * 0.9999999999;
+    stm = st.substr(0, p) + '$' + st.substr(p, 2000);
+    sto = stm.replace(/\$/g, '');
+    notPolluted = notPolluted && st === sto;
+
+    // lower
+    const stl = st.toLowerCase();
+    notPolluted = notPolluted && (stl.length === l) && stl[l - 1] && !(stl[l])
+    for (i = 0; i < l; i++) {
+      const s1 = st[i];
+      const s2 = stl[i];
+      const s1l = s1.toLowerCase();
+      notPolluted = notPolluted && s1l[0] === s2 && s1l[0] && !(s1l[1]);
+    }
+  }
+  return !notPolluted;
+}
+
 function hex2bin(hex) {
   return ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8);
 }
@@ -747,4 +805,5 @@ exports.noop = noop;
 exports.isRaspberry = isRaspberry;
 exports.isRaspbian = isRaspbian;
 exports.sanitizeShellString = sanitizeShellString;
+exports.isPrototypePolluted = isPrototypePolluted;
 exports.decodePiCpuinfo = decodePiCpuinfo;

programming_language: JavaScript