dissect.target 3.20.2.dev12__py3-none-any.whl → 3.20.2.dev13__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ from dissect.target.plugins.os.unix._os import UnixPlugin
8
8
  from dissect.target.plugins.os.unix.bsd.osx._os import MacPlugin
9
9
  from dissect.target.plugins.os.unix.linux.network_managers import (
10
10
  LinuxNetworkManager,
11
+ parse_unix_dhcp_leases,
11
12
  parse_unix_dhcp_log_messages,
12
13
  )
13
14
  from dissect.target.plugins.os.windows._os import WindowsPlugin
@@ -39,8 +40,11 @@ class LinuxPlugin(UnixPlugin, LinuxNetworkManager):
39
40
  for ip_set in self.network_manager.get_config_value("ips"):
40
41
  ips.update(ip_set)
41
42
 
42
- for ip in parse_unix_dhcp_log_messages(self.target, iter_all=False):
43
- ips.add(ip)
43
+ if dhcp_lease_ips := parse_unix_dhcp_leases(self.target):
44
+ ips.update(dhcp_lease_ips)
45
+
46
+ elif dhcp_log_ips := parse_unix_dhcp_log_messages(self.target, iter_all=False):
47
+ ips.update(dhcp_log_ips)
44
48
 
45
49
  return list(ips)
46
50
 
@@ -12,6 +12,7 @@ from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, Match
12
12
  from defusedxml import ElementTree
13
13
 
14
14
  from dissect.target.exceptions import PluginError
15
+ from dissect.target.helpers import configutil
15
16
 
16
17
  if TYPE_CHECKING:
17
18
  from dissect.target.helpers.fsutil import TargetPath
@@ -601,6 +602,40 @@ def parse_unix_dhcp_log_messages(target: Target, iter_all: bool = False) -> set[
601
602
  return ips
602
603
 
603
604
 
605
+ def parse_unix_dhcp_leases(target: Target) -> set[str]:
606
+ """Parse NetworkManager and dhclient DHCP ``.lease`` files.
607
+
608
+ Resources:
609
+ - https://linux.die.net/man/5/dhclient.conf
610
+
611
+ Args:
612
+ target: Target to discover and obtain network information from.
613
+
614
+ Returns:
615
+ A set of found DHCP IP addresses.
616
+ """
617
+ ips = set()
618
+
619
+ for lease_file in chain(
620
+ target.fs.path("/var/lib/NetworkManager").glob("*.lease*"),
621
+ target.fs.path("/var/lib/dhcp").glob("*.lease*"),
622
+ target.fs.path("/var/lib/dhclient").glob("*.lease*"),
623
+ ):
624
+ lease_text = lease_file.read_text()
625
+
626
+ if "lease {" in lease_text:
627
+ for line in lease_text.split("\n"):
628
+ if "fixed-address" in line:
629
+ ips.add(line.split(" ")[-1].strip(";"))
630
+
631
+ elif "ADDRESS=" in lease_text:
632
+ lease = configutil.parse(lease_file, hint="env")
633
+ if ip := lease.get("ADDRESS"):
634
+ ips.add(ip)
635
+
636
+ return ips
637
+
638
+
604
639
  def should_ignore_ip(ip: str) -> bool:
605
640
  for i in IGNORED_IPS:
606
641
  if ip.startswith(i):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.target
3
- Version: 3.20.2.dev12
3
+ Version: 3.20.2.dev13
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
@@ -227,14 +227,14 @@ dissect/target/plugins/os/unix/esxi/_os.py,sha256=eTI6zVubEmdx02mMDyTpmf2J53IzhW
227
227
  dissect/target/plugins/os/unix/etc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
228
228
  dissect/target/plugins/os/unix/etc/etc.py,sha256=YSCRZZfQvmzaR5VWhTJhB8pIGliL6Nw5ruhdfvYKYaM,2783
229
229
  dissect/target/plugins/os/unix/linux/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
230
- dissect/target/plugins/os/unix/linux/_os.py,sha256=k1aHhWqocSHMVbF54VDw9wqwa0QSToOa69TMKAyQcxw,2979
230
+ dissect/target/plugins/os/unix/linux/_os.py,sha256=C3IM_6dSixt_9Tsjjy6-LaT4IIkl3hiBuoo8LXTW4Dg,3137
231
231
  dissect/target/plugins/os/unix/linux/cmdline.py,sha256=n_Uetoplx33XpIY27oPtMaw1E2AbAEeGLCSkxHshWgY,1673
232
232
  dissect/target/plugins/os/unix/linux/environ.py,sha256=n7KttVzUtBHTIXQuS1DI5Azv6tM__d9gGqhPR_3ArIE,1932
233
233
  dissect/target/plugins/os/unix/linux/iptables.py,sha256=qTzY5PHHXA33WnPYb5NESgoSwI7ECZ8YPoEe_Fmln-8,6045
234
234
  dissect/target/plugins/os/unix/linux/modules.py,sha256=-LThb5mcKtngVfIICpdOGLtgJPc99WQ8Qufwddt8YgQ,2500
235
235
  dissect/target/plugins/os/unix/linux/netstat.py,sha256=EBpbK4BD3pZ0fKCR3ZMmVip4eQ0f6x_9yumA8vsUKPw,1691
236
236
  dissect/target/plugins/os/unix/linux/network.py,sha256=KfGfYhtrzpHHefaHjTpdbGSLu6IN4anweYt3V02D9zU,14392
237
- dissect/target/plugins/os/unix/linux/network_managers.py,sha256=atvcHPXFHVeCD5ipygqpR8pOgSexCGKIvVZz3Z8ITLA,25770
237
+ dissect/target/plugins/os/unix/linux/network_managers.py,sha256=h5kOQe8yAYx18kGD_0zc6Mda5PK-MuQQI34MlNkUXKw,26815
238
238
  dissect/target/plugins/os/unix/linux/proc.py,sha256=jm35fAasnNbObN2tpflwQuCfVYLDkTP2EDrzYG42ZSk,23354
239
239
  dissect/target/plugins/os/unix/linux/processes.py,sha256=xAJswf06HZsY8JhQ11xfJw1OLTZ1q9XZbu7_a7k2UpY,2019
240
240
  dissect/target/plugins/os/unix/linux/services.py,sha256=cZWmoVImbl7foKQfBpiKjeC2kjvfRUpM-ympFQorwHI,4128
@@ -383,10 +383,10 @@ dissect/target/volumes/luks.py,sha256=OmCMsw6rCUXG1_plnLVLTpsvE1n_6WtoRUGQbpmu1z
383
383
  dissect/target/volumes/lvm.py,sha256=wwQVR9I3G9YzmY6UxFsH2Y4MXGBcKL9aayWGCDTiWMU,2269
384
384
  dissect/target/volumes/md.py,sha256=7ShPtusuLGaIv27SvEETtgsuoQyAa4iAAeOR1NEaajI,1689
385
385
  dissect/target/volumes/vmfs.py,sha256=-LoUbn9WNwTtLi_4K34uV_-wDw2W5hgaqxZNj4UmqAQ,1730
386
- dissect.target-3.20.2.dev12.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
387
- dissect.target-3.20.2.dev12.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
388
- dissect.target-3.20.2.dev12.dist-info/METADATA,sha256=au0kJQvTe9SWFe37c1WTFl7D7EqigPuUR1X7vtXQLK4,13184
389
- dissect.target-3.20.2.dev12.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
390
- dissect.target-3.20.2.dev12.dist-info/entry_points.txt,sha256=yQwLCWUuzHgS6-sfCcRk66gAfoCfqXdCjqKjvhnQW8o,537
391
- dissect.target-3.20.2.dev12.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
392
- dissect.target-3.20.2.dev12.dist-info/RECORD,,
386
+ dissect.target-3.20.2.dev13.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
387
+ dissect.target-3.20.2.dev13.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
388
+ dissect.target-3.20.2.dev13.dist-info/METADATA,sha256=9Lzw8f76ZYkGqAxYcbnxFjZx1JDFuQk_GTqfbStg8q0,13184
389
+ dissect.target-3.20.2.dev13.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
390
+ dissect.target-3.20.2.dev13.dist-info/entry_points.txt,sha256=yQwLCWUuzHgS6-sfCcRk66gAfoCfqXdCjqKjvhnQW8o,537
391
+ dissect.target-3.20.2.dev13.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
392
+ dissect.target-3.20.2.dev13.dist-info/RECORD,,