Details
Run it:
node poc.js
Verbatim captured output (against [email protected]):
PRE marker_exists=false
returned=[]
POST marker_exists=true
marker_contents=uid=501(rick) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),701(com.apple.sharepoint.group.1),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae)
NEG pre marker_exists=false
NEG returned=["eth0"]
NEG post marker_exists=false
The malicious source path caused the injected id command to run (marker created, contents = the calling process identity), while the benign source path parsed normally (["eth0"]) and produced no marker. The injected command runs with the privileges of the Node.js process that called networkInterfaces().
End-to-end reproduction
The transcript above is the end-to-end run against the pinned published artifact [email protected], loading the shipped lib/network.js and lib/util.js from node_modules. Exact commands:
mkdir si-poc && cd si-poc
npm init -y >/dev/null
npm install [email protected]
# place poc.js (from the Reproduction section) in this directory
node poc.js
The marker file PWNED is created only by the injected command path; the negative-control marker PWNED_NEG is never created. The verbatim captured stdout is shown in the Reproduction section above.
Suggested fix
Stop building a shell string from a path that comes out of file content. Read the file with fs (no shell), or use argument-array execution, and never interpolate a parsed source path into a shell command. For example:
function checkLinuxDCHPInterfaces(file) {
let result = [];
try {
// No shell: read the file directly and filter in JS.
const content = require('fs').readFileSync(file, { encoding: 'utf8' });
const lines = content.split('\n').filter((l) => /iface|source/.test(l));
lines.forEach((line) => {
const parts = line.replace(/\s+/g, ' ').trim().split(' ');
if (parts.length >= 4 &&
line.toLowerCase().indexOf(' inet ') >= 0 &&
line.toLowerCase().indexOf('dhcp') >= 0) {
result.push(parts[1]);
}
if (line.toLowerCase().includes('source')) {
const sourced = line.split(' ')[1];
result = result.concat(checkLinuxDCHPInterfaces(sourced));
}
});
} catch {
require('./util').noop();
}
return result;
}
If shelling out is preferred, replace the cat/grep shell string with argument-array execution as shown below, so the path is passed as a single argv element and the shell never re-parses it:
const { execFileSync } = require('child_process');
const content = execFileSync('cat', [file], util.execOptsLinux).toString();
Quoting alone is insufficient. Treat every value parsed from interfaces(5) files as untrusted even though it originates from local system state, consistent with the defensive util.sanitizeString pattern already applied to the interface name and NetworkManager connection name on the sibling paths.
Fix PR
A fix is provided on a private temporary fork (not pushed to any public fork during the embargo). The branch replaces the cat ${file} shell string in checkLinuxDCHPInterfaces() with a non-shell fs.readFileSync read and adds a Linux regression test that points the function at an interfaces file containing a source directive with shell metacharacters and asserts that no side-effect command runs (no marker file is produced) while a benign sourced DHCP interface is still parsed.
Credit
Reported by tonghuaroot.