Skip to content

Commit

Permalink
networkInterfaces() sanitizing device names
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Jan 24, 2023
1 parent b9abbbd commit f997fb2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 34 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.

| Version | Date | Comment |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
| 5.17.3 | 2023-01-10 | `processes` fix elapsed time parsing (linux) |
| 5.17.4 | 2023-01-24 | `networkInterfaces()` sanitizing networkInterfaces device names |
| 5.17.3 | 2023-01-10 | `processes()` fix elapsed time parsing (linux) |
| 5.17.2 | 2023-01-10 | `utils` fix killing powershell (windows) |
| 5.17.1 | 2023-01-06 | `graphics()` positionX, positionY Ventura fix (max OS) |
| 5.17.0 | 2023-01-06 | `graphics()` added positionX, positionY (max OS) |
Expand Down
5 changes: 5 additions & 0 deletions docs/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ <h3>Full version history</h3>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.17.4</th>
<td>2023-01-24</td>
<td><span class="code">networkInterfaces()</span> sanitizing interface names</td>
</tr>
<tr>
<th scope="row">5.17.3</th>
<td>2023-01-10</td>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png" alt="logo">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.17.3</span></div>
<div class="version">New Version: <span id="version">5.17.4</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">
Expand Down
88 changes: 56 additions & 32 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,14 @@ function networkInterfaces(callback, rescan, defaultString) {
});
}

let ifaceSanitized = '';
const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(nic.iface);
for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
if (s[i] !== undefined) {
ifaceSanitized = ifaceSanitized + s[i];
}
}

result.push({
iface: nic.iface,
ifaceName: nic.iface,
Expand All @@ -759,7 +767,7 @@ function networkInterfaces(callback, rescan, defaultString) {
duplex: nic.duplex,
mtu: nic.mtu,
speed: nic.speed,
dhcp: getDarwinIfaceDHCPstatus(nic.iface),
dhcp: getDarwinIfaceDHCPstatus(ifaceSanitized),
dnsSuffix: '',
ieee8021xAuth: '',
ieee8021xState: '',
Expand Down Expand Up @@ -830,37 +838,44 @@ function networkInterfaces(callback, rescan, defaultString) {
}
});
let iface = dev.split(':')[0].trim().toLowerCase();
const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${iface}/addr_assign_type 2>/dev/null; echo;
echo -n "address: "; cat /sys/class/net/${iface}/address 2>/dev/null; echo;
echo -n "addr_len: "; cat /sys/class/net/${iface}/addr_len 2>/dev/null; echo;
echo -n "broadcast: "; cat /sys/class/net/${iface}/broadcast 2>/dev/null; echo;
echo -n "carrier: "; cat /sys/class/net/${iface}/carrier 2>/dev/null; echo;
echo -n "carrier_changes: "; cat /sys/class/net/${iface}/carrier_changes 2>/dev/null; echo;
echo -n "dev_id: "; cat /sys/class/net/${iface}/dev_id 2>/dev/null; echo;
echo -n "dev_port: "; cat /sys/class/net/${iface}/dev_port 2>/dev/null; echo;
echo -n "dormant: "; cat /sys/class/net/${iface}/dormant 2>/dev/null; echo;
echo -n "duplex: "; cat /sys/class/net/${iface}/duplex 2>/dev/null; echo;
echo -n "flags: "; cat /sys/class/net/${iface}/flags 2>/dev/null; echo;
echo -n "gro_flush_timeout: "; cat /sys/class/net/${iface}/gro_flush_timeout 2>/dev/null; echo;
echo -n "ifalias: "; cat /sys/class/net/${iface}/ifalias 2>/dev/null; echo;
echo -n "ifindex: "; cat /sys/class/net/${iface}/ifindex 2>/dev/null; echo;
echo -n "iflink: "; cat /sys/class/net/${iface}/iflink 2>/dev/null; echo;
echo -n "link_mode: "; cat /sys/class/net/${iface}/link_mode 2>/dev/null; echo;
echo -n "mtu: "; cat /sys/class/net/${iface}/mtu 2>/dev/null; echo;
echo -n "netdev_group: "; cat /sys/class/net/${iface}/netdev_group 2>/dev/null; echo;
echo -n "operstate: "; cat /sys/class/net/${iface}/operstate 2>/dev/null; echo;
echo -n "proto_down: "; cat /sys/class/net/${iface}/proto_down 2>/dev/null; echo;
echo -n "speed: "; cat /sys/class/net/${iface}/speed 2>/dev/null; echo;
echo -n "tx_queue_len: "; cat /sys/class/net/${iface}/tx_queue_len 2>/dev/null; echo;
echo -n "type: "; cat /sys/class/net/${iface}/type 2>/dev/null; echo;
echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${iface}; echo;
echo -n "wirelessspeed: "; iw dev ${iface} link 2>&1 | grep bitrate; echo;`;
let ifaceSanitized = '';
const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
if (s[i] !== undefined) {
ifaceSanitized = ifaceSanitized + s[i];
}
}
const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo;
echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo;
echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo;
echo -n "broadcast: "; cat /sys/class/net/${ifaceSanitized}/broadcast 2>/dev/null; echo;
echo -n "carrier: "; cat /sys/class/net/${ifaceSanitized}/carrier 2>/dev/null; echo;
echo -n "carrier_changes: "; cat /sys/class/net/${ifaceSanitized}/carrier_changes 2>/dev/null; echo;
echo -n "dev_id: "; cat /sys/class/net/${ifaceSanitized}/dev_id 2>/dev/null; echo;
echo -n "dev_port: "; cat /sys/class/net/${ifaceSanitized}/dev_port 2>/dev/null; echo;
echo -n "dormant: "; cat /sys/class/net/${ifaceSanitized}/dormant 2>/dev/null; echo;
echo -n "duplex: "; cat /sys/class/net/${ifaceSanitized}/duplex 2>/dev/null; echo;
echo -n "flags: "; cat /sys/class/net/${ifaceSanitized}/flags 2>/dev/null; echo;
echo -n "gro_flush_timeout: "; cat /sys/class/net/${ifaceSanitized}/gro_flush_timeout 2>/dev/null; echo;
echo -n "ifalias: "; cat /sys/class/net/${ifaceSanitized}/ifalias 2>/dev/null; echo;
echo -n "ifindex: "; cat /sys/class/net/${ifaceSanitized}/ifindex 2>/dev/null; echo;
echo -n "iflink: "; cat /sys/class/net/${ifaceSanitized}/iflink 2>/dev/null; echo;
echo -n "link_mode: "; cat /sys/class/net/${ifaceSanitized}/link_mode 2>/dev/null; echo;
echo -n "mtu: "; cat /sys/class/net/${ifaceSanitized}/mtu 2>/dev/null; echo;
echo -n "netdev_group: "; cat /sys/class/net/${ifaceSanitized}/netdev_group 2>/dev/null; echo;
echo -n "operstate: "; cat /sys/class/net/${ifaceSanitized}/operstate 2>/dev/null; echo;
echo -n "proto_down: "; cat /sys/class/net/${ifaceSanitized}/proto_down 2>/dev/null; echo;
echo -n "speed: "; cat /sys/class/net/${ifaceSanitized}/speed 2>/dev/null; echo;
echo -n "tx_queue_len: "; cat /sys/class/net/${ifaceSanitized}/tx_queue_len 2>/dev/null; echo;
echo -n "type: "; cat /sys/class/net/${ifaceSanitized}/type 2>/dev/null; echo;
echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${ifaceSanitized}; echo;
echo -n "wirelessspeed: "; iw dev ${ifaceSanitized} link 2>&1 | grep bitrate; echo;`;

let lines = [];
try {
lines = execSync(cmd).toString().split('\n');
const connectionName = getLinuxIfaceConnectionName(iface);
dhcp = getLinuxIfaceDHCPstatus(iface, connectionName, _dhcpNics);
const connectionName = getLinuxIfaceConnectionName(ifaceSanitized);
dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics);
dnsSuffix = getLinuxIfaceDNSsuffix(connectionName);
ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(connectionName);
ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth);
Expand All @@ -880,15 +895,15 @@ function networkInterfaces(callback, rescan, defaultString) {
carrierChanges = parseInt(util.getValue(lines, 'carrier_changes'), 10);
const operstate = util.getValue(lines, 'operstate');
type = operstate === 'up' ? (util.getValue(lines, 'wireless').trim() ? 'wireless' : 'wired') : 'unknown';
if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; }
if (ifaceSanitized === 'lo' || ifaceSanitized.startsWith('bond')) { type = 'virtual'; }

let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : false;
if (dev.toLowerCase().indexOf('loopback') > -1 || ifaceName.toLowerCase().indexOf('loopback') > -1) {
internal = true;
}
const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
result.push({
iface,
iface: ifaceSanitized,
ifaceName,
default: iface === defaultInterface,
ip4,
Expand Down Expand Up @@ -955,6 +970,15 @@ function networkInterfaces(callback, rescan, defaultString) {
nics8021xInfo = getWindowsWiredProfilesInformation();
dnsSuffixes = getWindowsDNSsuffixes();
for (let dev in ifaces) {

let ifaceSanitized = '';
const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(dev);
for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
if (s[i] !== undefined) {
ifaceSanitized = ifaceSanitized + s[i];
}
}

let iface = dev;
let ip4 = '';
let ip4subnet = '';
Expand Down Expand Up @@ -998,7 +1022,7 @@ function networkInterfaces(callback, rescan, defaultString) {



dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev);
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, ifaceSanitized);
let foundFirst = false;
nics.forEach(detail => {
if (detail.mac === mac && !foundFirst) {
Expand All @@ -1016,7 +1040,7 @@ function networkInterfaces(callback, rescan, defaultString) {
type = 'wireless';
}

const IEEE8021x = getWindowsIEEE8021x(type, dev, nics8021xInfo);
const IEEE8021x = getWindowsIEEE8021x(type, ifaceSanitized, nics8021xInfo);
ieee8021xAuth = IEEE8021x.protocol;
ieee8021xState = IEEE8021x.state;
let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : false;
Expand Down

0 comments on commit f997fb2

Please sign in to comment.