Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in windows network plugins #955

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
11 changes: 7 additions & 4 deletions dissect/target/plugins/os/windows/network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
from enum import IntEnum
from functools import lru_cache
from typing import Iterator
Expand Down Expand Up @@ -224,11 +225,13 @@ def _try_value(subkey: RegistryKey, value: str) -> str | list | None:
return None


def _get_config_value(key: RegistryKey, name: str) -> set:
def _get_config_value(key: RegistryKey, name: str, split_char: list[str] | None = None) -> set:
wbi-ocd marked this conversation as resolved.
Show resolved Hide resolved
value = _try_value(key, name)
if not value or value in ("", "0.0.0.0", None, [], ["0.0.0.0"]):
return set()

if split_char and isinstance(value, str):
split_regexp = '|'.join(re.escape(c) for c in split_char)
value = re.split(split_regexp, value)
wbi-ocd marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(value, list):
return set(value)

Expand Down Expand Up @@ -354,11 +357,11 @@ def _extract_network_device_config(self, interface_id: str) -> list[dict[str, se
dhcp_config["ip"].update(_get_config_value(key, "DhcpIPAddress"))
dhcp_config["subnetmask"].update(_get_config_value(key, "DhcpSubnetMask"))
dhcp_config["search_domain"].update(_get_config_value(key, "DhcpDomain"))
dhcp_config["dns"].update(_get_config_value(key, "DhcpNameServer"))
dhcp_config["dns"].update(_get_config_value(key, "DhcpNameServer", [" ", ","]))
wbi-ocd marked this conversation as resolved.
Show resolved Hide resolved

# Extract static configuration from the registry
static_config["gateway"].update(_get_config_value(key, "DefaultGateway"))
static_config["dns"].update(_get_config_value(key, "NameServer"))
static_config["dns"].update(_get_config_value(key, "NameServer", [" ", ","]))
wbi-ocd marked this conversation as resolved.
Show resolved Hide resolved
static_config["search_domain"].update(_get_config_value(key, "Domain"))
static_config["ip"].update(_get_config_value(key, "IPAddress"))
static_config["subnetmask"].update(_get_config_value(key, "SubnetMask"))
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/os/windows/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_windows_network_none(
"DhcpIPAddress": "192.168.0.10",
"IPAddress": "10.0.0.10",
"DhcpNameServer": "192.168.0.2",
"NameServer": "10.0.0.2",
"NameServer": "10.0.0.2 10.0.0.3",
"SubnetMask": "255.255.255.0",
"DhcpSubnetMask": "255.255.255.0",
"VlanID": 10,
Expand Down Expand Up @@ -285,7 +285,7 @@ def test_windows_network_none(
},
{
"ip": ["10.0.0.10"],
"dns": ["10.0.0.2"],
"dns": ["10.0.0.3", "10.0.0.2"],
"gateway": ["10.0.0.1"],
"mac": "FE:EE:EE:EE:EE:ED",
"subnetmask": ["255.255.255.0"],
Expand Down