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

Linux network plugin: NetworkManager & systemd-networkd #932

Merged
merged 9 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dissect/target/helpers/configutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def create_parser(self, options: Optional[ParserOptions] = None) -> Configuratio
}


def parse(path: Union[FilesystemEntry, TargetPath], hint: Optional[str] = None, *args, **kwargs) -> ConfigParser:
def parse(path: Union[FilesystemEntry, TargetPath], hint: Optional[str] = None, *args, **kwargs) -> ConfigurationParser:
"""Parses the content of an ``path`` or ``entry`` to a dictionary.

Args:
Expand Down Expand Up @@ -922,7 +922,7 @@ def parse_config(
entry: FilesystemEntry,
hint: Optional[str] = None,
options: Optional[ParserOptions] = None,
) -> ConfigParser:
) -> ConfigurationParser:
parser_type = _select_parser(entry, hint)

parser = parser_type.create_parser(options)
Expand Down
18 changes: 12 additions & 6 deletions dissect/target/helpers/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,44 +145,50 @@ def DynamicDescriptor(types): # noqa

COMMON_INTERFACE_ELEMENTS = [
("string", "name"),
("string[]", "mac"),
("string", "type"),
("boolean", "enabled"),
("string", "mac"),
("net.ipaddress[]", "dns"),
("net.ipaddress[]", "ip"),
("net.ipaddress[]", "gateway"),
("net.ipnetwork[]", "network"),
("string", "source"),
]


UnixInterfaceRecord = TargetRecordDescriptor(
"unix/network/interface",
COMMON_INTERFACE_ELEMENTS,
[
*COMMON_INTERFACE_ELEMENTS,
("boolean", "dhcp_ipv4"), # NetworkManager allows for dual-stack configurations.
("boolean", "dhcp_ipv6"),
("datetime", "last_connected"),
("varint[]", "vlan"),
("string", "configurator"),
],
)

WindowsInterfaceRecord = TargetRecordDescriptor(
"windows/network/interface",
[
*COMMON_INTERFACE_ELEMENTS,
("varint", "vlan"),
("net.ipnetwork[]", "network"),
("varint", "metric"),
("stringlist", "search_domain"),
("datetime", "first_connected"),
("datetime", "last_connected"),
("net.ipaddress[]", "subnetmask"),
("boolean", "dhcp"),
("varint", "vlan"),
],
)

MacInterfaceRecord = TargetRecordDescriptor(
"macos/network/interface",
[
*COMMON_INTERFACE_ELEMENTS,
("varint", "vlan"),
("net.ipnetwork[]", "network"),
("varint", "interface_service_order"),
("boolean", "dhcp"),
("varint", "vlan"),
],
)

Expand Down
21 changes: 20 additions & 1 deletion dissect/target/helpers/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import logging
import re
import urllib.parse
from datetime import datetime, timezone, tzinfo
from enum import Enum
from pathlib import Path
from typing import BinaryIO, Callable, Iterator, Optional, Union
from typing import BinaryIO, Callable, Iterator, Optional, TypeVar, Union

from dissect.util.ts import from_unix

Expand All @@ -24,6 +26,23 @@ def findall(buf: bytes, needle: bytes) -> Iterator[int]:
offset += 1


T = TypeVar("T")


def to_list(value: T | list[T]) -> list[T]:
"""Convert a single value or a list of values to a list.

Args:
value: The value to convert.

Returns:
A list of values.
"""
if not isinstance(value, list):
return [value]
return value


Comment on lines +29 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bit overkill to put here as no other class uses it yet, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the method is too general to put anywhere else, although the module names helpers and utils are a bit nondescript.

Besides, if we keep it in for example the SystemdNetworkConfigParser, then it is likely that no one is going to use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until we find everyone is making it again and move it then :P but i get your point

class StrEnum(str, Enum):
"""Sortable and serializible string-based enum"""

Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/general/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def with_ip(self, ip_addr: str) -> Iterator[InterfaceRecord]:
@internal
def with_mac(self, mac: str) -> Iterator[InterfaceRecord]:
for interface in self.interfaces():
if interface.mac == mac:
if mac in interface.mac:
yield interface

@internal
Expand Down
3 changes: 2 additions & 1 deletion dissect/target/plugins/os/unix/bsd/osx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
network=network,
interface_service_order=interface_service_order,
dhcp=dhcp,
mac=[],
_target=self.target,
)

except Exception as e:
self.target.log.warning("Error reading configuration for network device %s: %s", name, e)
self.target.log.warning("Error reading configuration for network device %s", name, exc_info=e)

Check warning on line 92 in dissect/target/plugins/os/unix/bsd/osx/network.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/bsd/osx/network.py#L92

Added line #L92 was not covered by tests
continue
Loading
Loading