Skip to content

Commit 4260348

Browse files
committed
fix inconsistent duplicate field mappings in various plugins
1 parent a8a085c commit 4260348

File tree

9 files changed

+50
-27
lines changed

9 files changed

+50
-27
lines changed

dissect/target/plugins/apps/vpn/wireguard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
("string", "name"), # basename of .conf file if unset
1616
("net.ipaddress", "address"),
1717
("string", "private_key"),
18-
("string", "listen_port"),
18+
("varint", "listen_port"),
1919
("string", "fw_mark"),
2020
("string", "dns"),
2121
("varint", "table"),

dissect/target/plugins/os/unix/linux/sockets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
("string", "protocol"),
1717
("uint32", "rx_queue"),
1818
("uint32", "tx_queue"),
19-
("string", "local_ip"),
19+
("net.ipaddress", "local_ip"),
2020
("uint16", "local_port"),
21-
("string", "remote_ip"),
21+
("net.ipaddress", "remote_ip"),
2222
("uint16", "remote_port"),
2323
("string", "state"),
2424
("string", "owner"),

dissect/target/plugins/os/unix/shadow.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timedelta, timezone
12
from typing import Iterator
23

34
from dissect.target.exceptions import UnsupportedPluginError
@@ -13,12 +14,12 @@
1314
("string", "hash"),
1415
("string", "algorithm"),
1516
("string", "crypt_param"),
16-
("string", "last_change"),
17-
("varint", "min_age"),
18-
("varint", "max_age"),
17+
("datetime", "last_change"),
18+
("datetime", "min_age"),
19+
("datetime", "max_age"),
1920
("varint", "warning_period"),
20-
("string", "inactivity_period"),
21-
("string", "expiration_date"),
21+
("varint", "inactivity_period"),
22+
("datetime", "expiration_date"),
2223
("string", "unused_field"),
2324
],
2425
)
@@ -39,6 +40,7 @@ def passwords(self) -> Iterator[UnixShadowRecord]:
3940
4041
Resources:
4142
- https://manpages.ubuntu.com/manpages/oracular/en/man5/passwd.5.html
43+
- https://linux.die.net/man/5/shadow
4244
"""
4345

4446
seen_hashes = set()
@@ -64,19 +66,29 @@ def passwords(self) -> Iterator[UnixShadowRecord]:
6466

6567
seen_hashes.add(current_hash)
6668

69+
# improve readability
70+
last_change = shent.get(2)
71+
min_age = shent.get(3)
72+
max_age = shent.get(4)
73+
expiration_date = shent.get(7)
74+
6775
yield UnixShadowRecord(
6876
name=shent.get(0),
6977
crypt=shent.get(1),
7078
algorithm=crypt.get("algo"),
7179
crypt_param=crypt.get("param"),
7280
salt=crypt.get("salt"),
7381
hash=crypt.get("hash"),
74-
last_change=shent.get(2),
75-
min_age=shent.get(3),
76-
max_age=shent.get(4),
77-
warning_period=shent.get(5),
78-
inactivity_period=shent.get(6),
79-
expiration_date=shent.get(7),
82+
last_change=epoch_days_to_datetime(int(last_change)) if last_change else None,
83+
min_age=epoch_days_to_datetime(int(last_change) + int(min_age))
84+
if last_change and isinstance(min_age, int) and min_age > 0
85+
else None,
86+
max_age=epoch_days_to_datetime(int(last_change) + int(max_age))
87+
if last_change and max_age
88+
else None,
89+
warning_period=shent.get(5) if shent.get(5) else None,
90+
inactivity_period=shent.get(6) if shent.get(6) else None,
91+
expiration_date=epoch_days_to_datetime(int(expiration_date)) if expiration_date else None,
8092
unused_field=shent.get(8),
8193
_target=self.target,
8294
)
@@ -128,3 +140,11 @@ def extract_crypt_details(shent: dict) -> dict:
128140
crypt["algo"] = algos[crypt["algo"]]
129141

130142
return crypt
143+
144+
145+
def epoch_days_to_datetime(days: int) -> datetime:
146+
"""Convert a number representing the days since 1 January 1970 to a datetime object."""
147+
if not isinstance(days, int):
148+
raise ValueError("days argument should be an integer")
149+
150+
return datetime(1970, 1, 1, 0, 0, tzinfo=timezone.utc) + timedelta(days)

dissect/target/plugins/os/windows/generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"filesystem/registry/ndis",
6161
[
6262
("datetime", "ts"),
63-
("string", "network"),
63+
("string", "network_name"),
6464
("string", "name"),
6565
("string", "pnpinstanceid"),
6666
],
@@ -113,7 +113,7 @@
113113
("path", "librarypath"),
114114
("string", "displaystring"),
115115
("bytes", "providerid"),
116-
("string", "enabled"),
116+
("boolean", "enabled"),
117117
("string", "version"),
118118
],
119119
)
@@ -408,7 +408,7 @@ def ndis(self) -> Iterator[NdisRecord]:
408408

409409
yield NdisRecord(
410410
ts=network.ts,
411-
network=sub.name,
411+
network_name=sub.name,
412412
name=name,
413413
pnpinstanceid=pnpinstanceid,
414414
_target=self.target,

dissect/target/plugins/os/windows/log/amcache.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
("string", "pe_image"),
4343
("string", "pe_subsystem"),
4444
("string", "crc_checksum"),
45-
("string", "filesize"),
45+
("filesize", "filesize"),
4646
("wstring", "longname"),
4747
("string", "msi"),
4848
]
@@ -69,6 +69,7 @@ def create_record(
6969
create: str,
7070
target: Target,
7171
) -> TargetRecordDescriptor:
72+
7273
return description(
7374
start_time=_to_log_timestamp(install_properties.get("starttime")),
7475
stop_time=_to_log_timestamp(install_properties.get("stoptime")),
@@ -91,7 +92,7 @@ def create_record(
9192
binary_type=install_properties.get("binarytype"),
9293
bin_product_version=install_properties.get("binproductversion"),
9394
bin_file_version=install_properties.get("binfileversion"),
94-
filesize=install_properties.get("filesize"),
95+
filesize=int(install_properties.get("filesize", "0"), 16),
9596
pe_image=install_properties.get("peimagetype"),
9697
product_version=install_properties.get("productversion"),
9798
crc_checksum=install_properties.get("crcchecksum"),

dissect/target/plugins/os/windows/sru.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@
176176
("path", "app"),
177177
("string", "user"),
178178
("varint", "flags"),
179-
("varint", "start_time"),
180-
("varint", "end_time"),
179+
("datetime", "start_time"),
180+
("datetime", "end_time"),
181181
("bytes", "usage"),
182182
],
183183
)

tests/plugins/apps/vpn/test_wireguard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_wireguard_plugin_global_log(target_unix_users, fs_unix):
1515
assert record.name == "wg0"
1616
assert str(record.address) == "10.13.37.1"
1717
assert record.private_key == "UHJpdmF0ZUtleQ=="
18-
assert record.listen_port == "12345"
18+
assert record.listen_port == 12345
1919
assert record.source == "etc/wireguard/wg0.conf"
2020
assert record.dns is None
2121

tests/plugins/os/unix/test_shadow.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timezone
12
from io import BytesIO
23
from pathlib import Path
34

@@ -25,12 +26,12 @@ def test_unix_shadow(target_unix_users: Target, fs_unix: VirtualFilesystem) -> N
2526
) # noqa E501
2627
assert results[0].algorithm == "sha512"
2728
assert results[0].crypt_param is None
28-
assert results[0].last_change == "18963"
29-
assert results[0].min_age == 0
30-
assert results[0].max_age == 99999
29+
assert results[0].last_change == datetime(2021, 12, 2, 0, 0, 0, tzinfo=timezone.utc) # 18963
30+
assert results[0].min_age is None
31+
assert results[0].max_age == datetime(2295, 9, 16, 0, 0, 0, tzinfo=timezone.utc) # 99999
3132
assert results[0].warning_period == 7
32-
assert results[0].inactivity_period == ""
33-
assert results[0].expiration_date == ""
33+
assert results[0].inactivity_period is None
34+
assert results[0].expiration_date is None
3435
assert results[0].unused_field == ""
3536

3637

tests/plugins/os/windows/test_amcache.py renamed to tests/plugins/os/windows/log/test_amcache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,4 @@ def test_amcache_install_entry(target_win: Target):
159159
assert str(entry.create) == create
160160
assert str(entry.path) == r"C:\Users\JohnCena"
161161
assert str(entry.longname) == r"7z2201-x64.exe"
162+
assert entry.filesize == 1575742

0 commit comments

Comments
 (0)