dissect.target 3.20.dev9__py3-none-any.whl → 3.20.dev10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,7 +180,8 @@ MacInterfaceRecord = TargetRecordDescriptor(
180
180
  [
181
181
  *COMMON_INTERFACE_ELEMENTS,
182
182
  ("varint", "vlan"),
183
- ("string", "proxy"),
183
+ ("net.ipnetwork[]", "network"),
184
184
  ("varint", "interface_service_order"),
185
+ ("boolean", "dhcp"),
185
186
  ],
186
187
  )
@@ -40,24 +40,8 @@ class MacPlugin(BsdPlugin):
40
40
  @export(property=True)
41
41
  def ips(self) -> Optional[list[str]]:
42
42
  ips = set()
43
-
44
- # Static configured IP-addresses
45
- if (preferences := self.target.fs.path(self.SYSTEM)).exists():
46
- network = plistlib.load(preferences.open()).get("NetworkServices")
47
-
48
- for interface in network.values():
49
- for addresses in [interface.get("IPv4"), interface.get("IPv6")]:
50
- ips.update(addresses.get("Addresses", []))
51
-
52
- # IP-addresses configured by DHCP
53
- if (dhcp := self.target.fs.path("/private/var/db/dhcpclient/leases")).exists():
54
- for lease in dhcp.iterdir():
55
- if lease.is_file():
56
- lease = plistlib.load(lease.open())
57
-
58
- if ip := lease.get("IPAddress"):
59
- ips.add(ip)
60
-
43
+ for ip in self.target.network.ips():
44
+ ips.add(str(ip))
61
45
  return list(ips)
62
46
 
63
47
  @export(property=True)
@@ -0,0 +1,90 @@
1
+ from __future__ import annotations
2
+
3
+ import plistlib
4
+ from functools import cache, lru_cache
5
+ from typing import Iterator
6
+
7
+ from dissect.target.helpers.record import MacInterfaceRecord
8
+ from dissect.target.plugins.general.network import NetworkPlugin
9
+ from dissect.target.target import Target
10
+
11
+
12
+ class MacNetworkPlugin(NetworkPlugin):
13
+ def __init__(self, target: Target):
14
+ super().__init__(target)
15
+ self._plistnetwork = cache(self._plistnetwork)
16
+ self._plistlease = lru_cache(32)(self._plistlease)
17
+
18
+ def _plistlease(self, devname: str) -> dict:
19
+ for lease in self.target.fs.glob_ext(f"/private/var/db/dhcpclient/leases/{devname}*"):
20
+ return plistlib.load(lease.open())
21
+ return {}
22
+
23
+ def _plistnetwork(self) -> dict:
24
+ if (preferences := self.target.fs.path("/Library/Preferences/SystemConfiguration/preferences.plist")).exists():
25
+ return plistlib.load(preferences.open())
26
+
27
+ def _interfaces(self) -> Iterator[MacInterfaceRecord]:
28
+ plistnetwork = self._plistnetwork()
29
+ current_set = plistnetwork.get("CurrentSet")
30
+ sets = plistnetwork.get("Sets", {})
31
+ for name, _set in sets.items():
32
+ if f"/Sets/{name}" == current_set:
33
+ item = _set
34
+ for key in ["Network", "Global", "IPv4", "ServiceOrder"]:
35
+ item = item.get(key, {})
36
+ service_order = item
37
+ break
38
+
39
+ network = plistnetwork.get("NetworkServices", {})
40
+ vlans = plistnetwork.get("VirtualNetworkInterfaces", {}).get("VLAN", {})
41
+
42
+ vlan_lookup = {key: vlan.get("Tag") for key, vlan in vlans.items()}
43
+
44
+ for _id, interface in network.items():
45
+ dns = set()
46
+ gateways = set()
47
+ ips = set()
48
+ device = interface.get("Interface", {})
49
+ name = device.get("DeviceName")
50
+ _type = device.get("Type")
51
+ vlan = vlan_lookup.get(name)
52
+ dhcp = False
53
+ subnetmask = []
54
+ network = []
55
+ interface_service_order = service_order.index(_id) if _id in service_order else None
56
+ try:
57
+ for addr in interface.get("DNS", {}).get("ServerAddresses", {}):
58
+ dns.add(addr)
59
+ for addresses in [interface.get("IPv4", {}), interface.get("IPv6", {})]:
60
+ subnetmask += filter(lambda mask: mask != "", addresses.get("SubnetMasks", []))
61
+ if router := addresses.get("Router"):
62
+ gateways.add(router)
63
+ if addresses.get("ConfigMethod", "") == "DHCP":
64
+ ips.add(self._plistlease(name).get("IPAddress"))
65
+ dhcp = True
66
+ else:
67
+ for addr in addresses.get("Addresses", []):
68
+ ips.add(addr)
69
+
70
+ if subnetmask:
71
+ network = self.calculate_network(ips, subnetmask)
72
+
73
+ yield MacInterfaceRecord(
74
+ name=name,
75
+ type=_type,
76
+ enabled=not interface.get("__INACTIVE__", False),
77
+ dns=list(dns),
78
+ ip=list(ips),
79
+ gateway=list(gateways),
80
+ source="NetworkServices",
81
+ vlan=vlan,
82
+ network=network,
83
+ interface_service_order=interface_service_order,
84
+ dhcp=dhcp,
85
+ _target=self.target,
86
+ )
87
+
88
+ except Exception as e:
89
+ self.target.log.warning("Error reading configuration for network device %s: %s", name, e)
90
+ continue
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.target
3
- Version: 3.20.dev9
3
+ Version: 3.20.dev10
4
4
  Summary: This module ties all other Dissect modules together, it provides a programming API and command line tools which allow easy access to various data sources inside disk images or file collections (a.k.a. targets)
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -61,7 +61,7 @@ dissect/target/helpers/mui.py,sha256=i-7XoHbu4WO2fYapK9yGAMW04rFlgRispknc1KQIS5Q
61
61
  dissect/target/helpers/network_managers.py,sha256=ByBSe2K3c8hgQC6dokcf-hHdmPcD8PmrOj0xs1C3yhs,25743
62
62
  dissect/target/helpers/polypath.py,sha256=h8p7m_OCNiQljGwoZh5Aflr9H2ot6CZr6WKq1OSw58o,2175
63
63
  dissect/target/helpers/protobuf.py,sha256=b4DsnqrRLrefcDjx7rQno-_LBcwtJXxuKf5RdOegzfE,1537
64
- dissect/target/helpers/record.py,sha256=vbsZBUQ5sxsWGaGUJk2yHV5miXvK9HfZgVarM5Cmqto,5852
64
+ dissect/target/helpers/record.py,sha256=7Se6ZV8cvwEaGSjRd9bKhVnUAn4W4KR2eqP6AbQhTH4,5892
65
65
  dissect/target/helpers/record_modifier.py,sha256=O_Jj7zOi891HIyAYjxxe6LFPYETHdMa5lNjo4NA_T_w,3969
66
66
  dissect/target/helpers/regutil.py,sha256=kX-sSZbW8Qkg29Dn_9zYbaQrwLumrr4Y8zJ1EhHXIAM,27337
67
67
  dissect/target/helpers/shell_application_ids.py,sha256=hYxrP-YtHK7ZM0ectJFHfoMB8QUXLbYNKmKXMWLZRlA,38132
@@ -210,7 +210,8 @@ dissect/target/plugins/os/unix/bsd/ios/_os.py,sha256=VlJXGxkQZ4RbGbSC-FlbR2YWOJp
210
210
  dissect/target/plugins/os/unix/bsd/openbsd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
211
211
  dissect/target/plugins/os/unix/bsd/openbsd/_os.py,sha256=9npz-osM-wHmjOACUqof5N5HJeps7J8KuyenUS5MZDs,923
212
212
  dissect/target/plugins/os/unix/bsd/osx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
213
- dissect/target/plugins/os/unix/bsd/osx/_os.py,sha256=KvP7YJ7apVwoIop7MR-8q5QbVGoB6MdR42l6ssEe6es,4081
213
+ dissect/target/plugins/os/unix/bsd/osx/_os.py,sha256=PKh8VM_O0FmmYy7UMPth6uhusCJzekla20sUPK6esRg,3416
214
+ dissect/target/plugins/os/unix/bsd/osx/network.py,sha256=j2yq2QTAmAuZBu3j0vHnHHxkUyeB4b-6WdUSWCE_QsE,3691
214
215
  dissect/target/plugins/os/unix/bsd/osx/user.py,sha256=qopB0s3n7e6Q7NjWzn8Z-dKtDtU7e6In4Vm7hIvvedo,2322
215
216
  dissect/target/plugins/os/unix/esxi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
216
217
  dissect/target/plugins/os/unix/esxi/_os.py,sha256=s6pAgUyfHh3QcY6sgvk5uVMmLvqK1tIHWR7MSbrFn8w,17789
@@ -363,10 +364,10 @@ dissect/target/volumes/luks.py,sha256=OmCMsw6rCUXG1_plnLVLTpsvE1n_6WtoRUGQbpmu1z
363
364
  dissect/target/volumes/lvm.py,sha256=wwQVR9I3G9YzmY6UxFsH2Y4MXGBcKL9aayWGCDTiWMU,2269
364
365
  dissect/target/volumes/md.py,sha256=7ShPtusuLGaIv27SvEETtgsuoQyAa4iAAeOR1NEaajI,1689
365
366
  dissect/target/volumes/vmfs.py,sha256=-LoUbn9WNwTtLi_4K34uV_-wDw2W5hgaqxZNj4UmqAQ,1730
366
- dissect.target-3.20.dev9.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
367
- dissect.target-3.20.dev9.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
368
- dissect.target-3.20.dev9.dist-info/METADATA,sha256=GtbUWaQU48N28P1Ob2MQ2AvdNbGJzwoFOBM5ml9Jk88,12896
369
- dissect.target-3.20.dev9.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
370
- dissect.target-3.20.dev9.dist-info/entry_points.txt,sha256=BWuxAb_6AvUAQpIQOQU0IMTlaF6TDht2AIZK8bHd-zE,492
371
- dissect.target-3.20.dev9.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
372
- dissect.target-3.20.dev9.dist-info/RECORD,,
367
+ dissect.target-3.20.dev10.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
368
+ dissect.target-3.20.dev10.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
369
+ dissect.target-3.20.dev10.dist-info/METADATA,sha256=5OxnXAwEsto5SeG-Tz-CR8M_5sqbSNn3Z41qo9bgFYY,12897
370
+ dissect.target-3.20.dev10.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
371
+ dissect.target-3.20.dev10.dist-info/entry_points.txt,sha256=BWuxAb_6AvUAQpIQOQU0IMTlaF6TDht2AIZK8bHd-zE,492
372
+ dissect.target-3.20.dev10.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
373
+ dissect.target-3.20.dev10.dist-info/RECORD,,