dissect.target 3.18.dev16__py3-none-any.whl → 3.19__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dissect/target/filesystem.py +44 -25
- dissect/target/filesystems/config.py +32 -21
- dissect/target/filesystems/extfs.py +4 -0
- dissect/target/filesystems/itunes.py +1 -1
- dissect/target/filesystems/tar.py +1 -1
- dissect/target/filesystems/zip.py +81 -46
- dissect/target/helpers/config.py +22 -7
- dissect/target/helpers/configutil.py +69 -5
- dissect/target/helpers/cyber.py +4 -2
- dissect/target/helpers/fsutil.py +32 -4
- dissect/target/helpers/loaderutil.py +26 -7
- dissect/target/helpers/network_managers.py +22 -7
- dissect/target/helpers/record.py +37 -0
- dissect/target/helpers/record_modifier.py +23 -4
- dissect/target/helpers/shell_application_ids.py +732 -0
- dissect/target/helpers/utils.py +11 -0
- dissect/target/loader.py +1 -0
- dissect/target/loaders/ab.py +285 -0
- dissect/target/loaders/libvirt.py +40 -0
- dissect/target/loaders/mqtt.py +14 -1
- dissect/target/loaders/tar.py +8 -4
- dissect/target/loaders/utm.py +3 -0
- dissect/target/loaders/velociraptor.py +6 -6
- dissect/target/plugin.py +60 -3
- dissect/target/plugins/apps/browser/chrome.py +1 -0
- dissect/target/plugins/apps/browser/chromium.py +7 -5
- dissect/target/plugins/apps/browser/edge.py +1 -0
- dissect/target/plugins/apps/browser/firefox.py +82 -36
- dissect/target/plugins/apps/remoteaccess/anydesk.py +70 -50
- dissect/target/plugins/apps/remoteaccess/remoteaccess.py +8 -8
- dissect/target/plugins/apps/remoteaccess/teamviewer.py +46 -31
- dissect/target/plugins/apps/ssh/openssh.py +1 -1
- dissect/target/plugins/apps/ssh/ssh.py +177 -0
- dissect/target/plugins/apps/texteditor/__init__.py +0 -0
- dissect/target/plugins/apps/texteditor/texteditor.py +13 -0
- dissect/target/plugins/apps/texteditor/windowsnotepad.py +340 -0
- dissect/target/plugins/child/qemu.py +21 -0
- dissect/target/plugins/filesystem/ntfs/mft.py +132 -45
- dissect/target/plugins/filesystem/unix/capability.py +102 -87
- dissect/target/plugins/filesystem/walkfs.py +32 -21
- dissect/target/plugins/filesystem/yara.py +144 -23
- dissect/target/plugins/general/network.py +82 -0
- dissect/target/plugins/general/users.py +14 -10
- dissect/target/plugins/os/unix/_os.py +19 -5
- dissect/target/plugins/os/unix/bsd/freebsd/_os.py +3 -5
- dissect/target/plugins/os/unix/esxi/_os.py +29 -23
- dissect/target/plugins/os/unix/etc/etc.py +5 -8
- dissect/target/plugins/os/unix/history.py +3 -7
- dissect/target/plugins/os/unix/linux/_os.py +15 -14
- dissect/target/plugins/os/unix/linux/android/_os.py +15 -24
- dissect/target/plugins/os/unix/linux/redhat/_os.py +1 -1
- dissect/target/plugins/os/unix/locale.py +17 -6
- dissect/target/plugins/os/unix/shadow.py +47 -31
- dissect/target/plugins/os/windows/_os.py +4 -4
- dissect/target/plugins/os/windows/adpolicy.py +4 -1
- dissect/target/plugins/os/windows/catroot.py +1 -11
- dissect/target/plugins/os/windows/credential/__init__.py +0 -0
- dissect/target/plugins/os/windows/credential/lsa.py +174 -0
- dissect/target/plugins/os/windows/{sam.py → credential/sam.py} +5 -2
- dissect/target/plugins/os/windows/defender.py +6 -3
- dissect/target/plugins/os/windows/dpapi/blob.py +3 -0
- dissect/target/plugins/os/windows/dpapi/crypto.py +61 -23
- dissect/target/plugins/os/windows/dpapi/dpapi.py +127 -133
- dissect/target/plugins/os/windows/dpapi/keyprovider/__init__.py +0 -0
- dissect/target/plugins/os/windows/dpapi/keyprovider/credhist.py +21 -0
- dissect/target/plugins/os/windows/dpapi/keyprovider/empty.py +17 -0
- dissect/target/plugins/os/windows/dpapi/keyprovider/keychain.py +20 -0
- dissect/target/plugins/os/windows/dpapi/keyprovider/keyprovider.py +8 -0
- dissect/target/plugins/os/windows/dpapi/keyprovider/lsa.py +38 -0
- dissect/target/plugins/os/windows/dpapi/master_key.py +3 -0
- dissect/target/plugins/os/windows/jumplist.py +292 -0
- dissect/target/plugins/os/windows/lnk.py +96 -93
- dissect/target/plugins/os/windows/regf/shimcache.py +2 -2
- dissect/target/plugins/os/windows/regf/usb.py +179 -114
- dissect/target/plugins/os/windows/task_helpers/tasks_xml.py +1 -1
- dissect/target/plugins/os/windows/wua_history.py +1073 -0
- dissect/target/target.py +4 -3
- dissect/target/tools/fs.py +53 -15
- dissect/target/tools/fsutils.py +243 -0
- dissect/target/tools/info.py +11 -4
- dissect/target/tools/query.py +2 -2
- dissect/target/tools/shell.py +505 -333
- dissect/target/tools/utils.py +23 -2
- dissect/target/tools/yara.py +65 -0
- dissect/target/volumes/md.py +2 -2
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/METADATA +11 -7
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/RECORD +93 -74
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/WHEEL +1 -1
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/entry_points.txt +1 -0
- dissect/target/helpers/ssh.py +0 -177
- /dissect/target/plugins/os/windows/{credhist.py → credential/credhist.py} +0 -0
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/COPYRIGHT +0 -0
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/LICENSE +0 -0
- {dissect.target-3.18.dev16.dist-info → dissect.target-3.19.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,55 @@
|
|
1
1
|
import base64
|
2
|
+
import binascii
|
2
3
|
from hashlib import md5, sha1, sha256
|
3
4
|
|
5
|
+
from dissect.cstruct import cstruct
|
6
|
+
|
4
7
|
from dissect.target.helpers.descriptor_extensions import UserRecordDescriptorExtension
|
5
8
|
from dissect.target.helpers.record import create_extended_descriptor
|
6
9
|
from dissect.target.plugin import NamespacePlugin
|
7
10
|
|
11
|
+
rfc4716_def = """
|
12
|
+
struct ssh_string {
|
13
|
+
uint32 length;
|
14
|
+
char value[length];
|
15
|
+
}
|
16
|
+
|
17
|
+
struct ssh_private_key {
|
18
|
+
char magic[15];
|
19
|
+
|
20
|
+
ssh_string cipher;
|
21
|
+
ssh_string kdf_name;
|
22
|
+
ssh_string kdf_options;
|
23
|
+
|
24
|
+
uint32 number_of_keys;
|
25
|
+
|
26
|
+
ssh_string public;
|
27
|
+
ssh_string private;
|
28
|
+
}
|
29
|
+
"""
|
30
|
+
|
31
|
+
c_rfc4716 = cstruct(endian=">").load(rfc4716_def)
|
32
|
+
|
33
|
+
RFC4716_MARKER_START = b"-----BEGIN OPENSSH PRIVATE KEY-----"
|
34
|
+
RFC4716_MARKER_END = b"-----END OPENSSH PRIVATE KEY-----"
|
35
|
+
RFC4716_MAGIC = b"openssh-key-v1\x00"
|
36
|
+
RFC4716_PADDING = b"\x01\x02\x03\x04\x05\x06\x07"
|
37
|
+
RFC4716_NONE = b"none"
|
38
|
+
|
39
|
+
PKCS8_MARKER_START = b"-----BEGIN PRIVATE KEY-----"
|
40
|
+
PKCS8_MARKER_END = b"-----END PRIVATE KEY-----"
|
41
|
+
PKCS8_MARKER_START_ENCRYPTED = b"-----BEGIN ENCRYPTED PRIVATE KEY-----"
|
42
|
+
PKCS8_MARKER_END_ENCRYPTED = b"-----END ENCRYPTED PRIVATE KEY-----"
|
43
|
+
|
44
|
+
PEM_MARKER_START_RSA = b"-----BEGIN RSA PRIVATE KEY-----"
|
45
|
+
PEM_MARKER_END_RSA = b"-----END RSA PRIVATE KEY-----"
|
46
|
+
PEM_MARKER_START_DSA = b"-----BEGIN DSA PRIVATE KEY-----"
|
47
|
+
PEM_MARKER_END_DSA = b"-----END DSA PRIVATE KEY-----"
|
48
|
+
PEM_MARKER_START_EC = b"-----BEGIN EC PRIVATE KEY-----"
|
49
|
+
PEM_MARKER_END_EC = b"-----END EC PRIVATE KEY-----"
|
50
|
+
PEM_ENCRYPTED = b"ENCRYPTED"
|
51
|
+
|
52
|
+
|
8
53
|
OpenSSHUserRecordDescriptor = create_extended_descriptor([UserRecordDescriptorExtension])
|
9
54
|
|
10
55
|
COMMON_ELLEMENTS = [
|
@@ -96,3 +141,135 @@ def calculate_fingerprints(public_key_decoded: bytes, ssh_keygen_format: bool =
|
|
96
141
|
fingerprint_sha256 = digest_sha256.hex()
|
97
142
|
|
98
143
|
return digest_md5.hex(), fingerprint_sha1, fingerprint_sha256
|
144
|
+
|
145
|
+
|
146
|
+
def is_rfc4716(data: bytes) -> bool:
|
147
|
+
"""Validate data is a valid looking SSH private key in the OpenSSH format."""
|
148
|
+
return data.startswith(RFC4716_MARKER_START) and data.endswith(RFC4716_MARKER_END)
|
149
|
+
|
150
|
+
|
151
|
+
def decode_rfc4716(data: bytes) -> bytes:
|
152
|
+
"""Base64 decode the private key data."""
|
153
|
+
encoded_key_data = data.removeprefix(RFC4716_MARKER_START).removesuffix(RFC4716_MARKER_END)
|
154
|
+
try:
|
155
|
+
return base64.b64decode(encoded_key_data)
|
156
|
+
except binascii.Error:
|
157
|
+
raise ValueError("Error decoding RFC4716 key data")
|
158
|
+
|
159
|
+
|
160
|
+
def is_pkcs8(data: bytes) -> bool:
|
161
|
+
"""Validate data is a valid looking PKCS8 SSH private key."""
|
162
|
+
return (data.startswith(PKCS8_MARKER_START) and data.endswith(PKCS8_MARKER_END)) or (
|
163
|
+
data.startswith(PKCS8_MARKER_START_ENCRYPTED) and data.endswith(PKCS8_MARKER_END_ENCRYPTED)
|
164
|
+
)
|
165
|
+
|
166
|
+
|
167
|
+
def is_pem(data: bytes) -> bool:
|
168
|
+
"""Validate data is a valid looking PEM SSH private key."""
|
169
|
+
return (
|
170
|
+
(data.startswith(PEM_MARKER_START_RSA) and data.endswith(PEM_MARKER_END_RSA))
|
171
|
+
or (data.startswith(PEM_MARKER_START_DSA) and data.endswith(PEM_MARKER_END_DSA))
|
172
|
+
or (data.startswith(PEM_MARKER_START_EC) and data.endswith(PEM_MARKER_END_EC))
|
173
|
+
)
|
174
|
+
|
175
|
+
|
176
|
+
class SSHPrivateKey:
|
177
|
+
"""A class to parse (OpenSSH-supported) SSH private keys.
|
178
|
+
|
179
|
+
OpenSSH supports three types of keys:
|
180
|
+
* RFC4716 (default)
|
181
|
+
* PKCS8
|
182
|
+
* PEM
|
183
|
+
"""
|
184
|
+
|
185
|
+
def __init__(self, data: bytes):
|
186
|
+
self.key_type = None
|
187
|
+
self.public_key = None
|
188
|
+
self.comment = ""
|
189
|
+
|
190
|
+
if is_rfc4716(data):
|
191
|
+
self.format = "RFC4716"
|
192
|
+
self._parse_rfc4716(data)
|
193
|
+
|
194
|
+
elif is_pkcs8(data):
|
195
|
+
self.format = "PKCS8"
|
196
|
+
self.is_encrypted = data.startswith(PKCS8_MARKER_START_ENCRYPTED)
|
197
|
+
|
198
|
+
elif is_pem(data):
|
199
|
+
self.format = "PEM"
|
200
|
+
self._parse_pem(data)
|
201
|
+
|
202
|
+
else:
|
203
|
+
raise ValueError("Unsupported private key format")
|
204
|
+
|
205
|
+
def _parse_rfc4716(self, data: bytes) -> None:
|
206
|
+
"""Parse OpenSSH format SSH private keys.
|
207
|
+
|
208
|
+
The format:
|
209
|
+
"openssh-key-v1"0x00 # NULL-terminated "Auth Magic" string
|
210
|
+
32-bit length, "none" # ciphername length and string
|
211
|
+
32-bit length, "none" # kdfname length and string
|
212
|
+
32-bit length, nil # kdf (0 length, no kdf)
|
213
|
+
32-bit 0x01 # number of keys, hard-coded to 1 (no length)
|
214
|
+
32-bit length, sshpub # public key in ssh format
|
215
|
+
32-bit length, keytype
|
216
|
+
32-bit length, pub0
|
217
|
+
32-bit length, pub1
|
218
|
+
32-bit length for rnd+prv+comment+pad
|
219
|
+
64-bit dummy checksum? # a random 32-bit int, repeated
|
220
|
+
32-bit length, keytype # the private key (including public)
|
221
|
+
32-bit length, pub0 # Public Key parts
|
222
|
+
32-bit length, pub1
|
223
|
+
32-bit length, prv0 # Private Key parts
|
224
|
+
... # (number varies by type)
|
225
|
+
32-bit length, comment # comment string
|
226
|
+
padding bytes 0x010203 # pad to blocksize (see notes below)
|
227
|
+
|
228
|
+
Source: https://coolaj86.com/articles/the-openssh-private-key-format/
|
229
|
+
"""
|
230
|
+
|
231
|
+
key_data = decode_rfc4716(data)
|
232
|
+
private_key = c_rfc4716.ssh_private_key(key_data)
|
233
|
+
|
234
|
+
# RFC4716 only supports 1 key at the moment.
|
235
|
+
if private_key.magic != RFC4716_MAGIC or private_key.number_of_keys != 1:
|
236
|
+
raise ValueError("Unexpected number of keys for RFC4716 format private key")
|
237
|
+
|
238
|
+
self.is_encrypted = private_key.cipher.value != RFC4716_NONE
|
239
|
+
|
240
|
+
self.public_key = base64.b64encode(private_key.public.value)
|
241
|
+
public_key_type = c_rfc4716.ssh_string(private_key.public.value)
|
242
|
+
self.key_type = public_key_type.value
|
243
|
+
|
244
|
+
if not self.is_encrypted:
|
245
|
+
private_key_data = private_key.private.value.rstrip(RFC4716_PADDING)
|
246
|
+
|
247
|
+
# We skip the two dummy uint32s at the start.
|
248
|
+
private_key_index = 8
|
249
|
+
|
250
|
+
private_key_type = c_rfc4716.ssh_string(private_key_data[private_key_index:])
|
251
|
+
private_key_index += 4 + private_key_type.length
|
252
|
+
self.key_type = private_key_type.value
|
253
|
+
|
254
|
+
private_key_fields = []
|
255
|
+
while private_key_index < len(private_key_data):
|
256
|
+
field = c_rfc4716.ssh_string(private_key_data[private_key_index:])
|
257
|
+
private_key_index += 4 + field.length
|
258
|
+
private_key_fields.append(field)
|
259
|
+
|
260
|
+
# There is always a comment present (with a length field of 0 for empty comments).
|
261
|
+
self.comment = private_key_fields[-1].value
|
262
|
+
|
263
|
+
def _parse_pem(self, data: bytes) -> None:
|
264
|
+
"""Detect key type and encryption of PEM keys."""
|
265
|
+
self.is_encrypted = PEM_ENCRYPTED in data
|
266
|
+
|
267
|
+
if data.startswith(PEM_MARKER_START_RSA):
|
268
|
+
self.key_type = "ssh-rsa"
|
269
|
+
|
270
|
+
elif data.startswith(PEM_MARKER_START_DSA):
|
271
|
+
self.key_type = "ssh-dss"
|
272
|
+
|
273
|
+
# This is not a valid SSH key type, but we currently do not detect the specific ecdsa variant.
|
274
|
+
else:
|
275
|
+
self.key_type = "ecdsa"
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from dissect.target.helpers.descriptor_extensions import UserRecordDescriptorExtension
|
2
|
+
from dissect.target.helpers.record import create_extended_descriptor
|
3
|
+
from dissect.target.plugin import NamespacePlugin
|
4
|
+
|
5
|
+
GENERIC_TAB_CONTENTS_RECORD_FIELDS = [("string", "content"), ("path", "path"), ("string", "deleted_content")]
|
6
|
+
|
7
|
+
TexteditorTabContentRecord = create_extended_descriptor([UserRecordDescriptorExtension])(
|
8
|
+
"texteditor/tab", GENERIC_TAB_CONTENTS_RECORD_FIELDS
|
9
|
+
)
|
10
|
+
|
11
|
+
|
12
|
+
class TexteditorPlugin(NamespacePlugin):
|
13
|
+
__namespace__ = "texteditor"
|
@@ -0,0 +1,340 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import logging
|
4
|
+
import zlib
|
5
|
+
from typing import Iterator
|
6
|
+
|
7
|
+
from dissect.cstruct import cstruct
|
8
|
+
from dissect.util.ts import wintimestamp
|
9
|
+
from flow.record.fieldtypes import digest
|
10
|
+
|
11
|
+
from dissect.target.exceptions import UnsupportedPluginError
|
12
|
+
from dissect.target.helpers.descriptor_extensions import UserRecordDescriptorExtension
|
13
|
+
from dissect.target.helpers.fsutil import TargetPath
|
14
|
+
from dissect.target.helpers.record import (
|
15
|
+
UnixUserRecord,
|
16
|
+
WindowsUserRecord,
|
17
|
+
create_extended_descriptor,
|
18
|
+
)
|
19
|
+
from dissect.target.plugin import export
|
20
|
+
from dissect.target.plugins.apps.texteditor.texteditor import (
|
21
|
+
GENERIC_TAB_CONTENTS_RECORD_FIELDS,
|
22
|
+
TexteditorPlugin,
|
23
|
+
)
|
24
|
+
from dissect.target.target import Target
|
25
|
+
|
26
|
+
# Thanks to @Nordgaren, @daddycocoaman, @JustArion and @ogmini for their suggestions and feedback in the PR
|
27
|
+
# thread. This really helped to figure out the last missing bits and pieces
|
28
|
+
# required for recovering text from these files.
|
29
|
+
|
30
|
+
windowstab_def = """
|
31
|
+
struct file_header {
|
32
|
+
char magic[2]; // NP
|
33
|
+
uleb128 updateNumber; // increases on every settings update when fileType=9,
|
34
|
+
// doesn't seem to change on fileType 0 or 1
|
35
|
+
uleb128 fileType; // 0 if unsaved, 1 if saved, 9 if contains settings?
|
36
|
+
}
|
37
|
+
|
38
|
+
struct tab_header_saved {
|
39
|
+
uleb128 filePathLength;
|
40
|
+
wchar filePath[filePathLength];
|
41
|
+
uleb128 fileSize; // likely similar to fixedSizeBlockLength
|
42
|
+
uleb128 encoding;
|
43
|
+
uleb128 carriageReturnType;
|
44
|
+
uleb128 timestamp; // Windows Filetime format (not unix timestamp)
|
45
|
+
char sha256[32];
|
46
|
+
char unk0;
|
47
|
+
char unk1;
|
48
|
+
uleb128 fixedSizeBlockLength;
|
49
|
+
uleb128 fixedSizeBlockLengthDuplicate;
|
50
|
+
uint8 wordWrap; // 1 if wordwrap enabled, 0 if disabled
|
51
|
+
uint8 rightToLeft;
|
52
|
+
uint8 showUnicode;
|
53
|
+
uint8 optionsVersion;
|
54
|
+
};
|
55
|
+
|
56
|
+
struct tab_header_unsaved {
|
57
|
+
char unk0;
|
58
|
+
uleb128 fixedSizeBlockLength; // will always be 00 when unsaved because size is not yet known
|
59
|
+
uleb128 fixedSizeBlockLengthDuplicate; // will always be 00 when unsaved because size is not yet known
|
60
|
+
uint8 wordWrap; // 1 if wordwrap enabled, 0 if disabled
|
61
|
+
uint8 rightToLeft;
|
62
|
+
uint8 showUnicode;
|
63
|
+
uint8 optionsVersion;
|
64
|
+
};
|
65
|
+
|
66
|
+
struct tab_header_crc32_stub {
|
67
|
+
char unk1;
|
68
|
+
char unk2;
|
69
|
+
char crc32[4];
|
70
|
+
};
|
71
|
+
|
72
|
+
struct fixed_size_data_block {
|
73
|
+
uleb128 nAdded;
|
74
|
+
wchar data[nAdded];
|
75
|
+
uint8 hasRemainingVariableDataBlocks; // indicates whether after this single-data block more data will follow
|
76
|
+
char crc32[4];
|
77
|
+
};
|
78
|
+
|
79
|
+
struct variable_size_data_block {
|
80
|
+
uleb128 offset;
|
81
|
+
uleb128 nDeleted;
|
82
|
+
uleb128 nAdded;
|
83
|
+
wchar data[nAdded];
|
84
|
+
char crc32[4];
|
85
|
+
};
|
86
|
+
|
87
|
+
struct options_v1 {
|
88
|
+
uleb128 unk;
|
89
|
+
};
|
90
|
+
|
91
|
+
struct options_v2 {
|
92
|
+
uleb128 unk1; // likely autocorrect or spellcheck
|
93
|
+
uleb128 unk2; // likely autocorrect or spellcheck
|
94
|
+
};
|
95
|
+
"""
|
96
|
+
|
97
|
+
WINDOWS_SAVED_TABS_EXTRA_FIELDS = [("datetime", "modification_time"), ("digest", "hashes"), ("path", "saved_path")]
|
98
|
+
|
99
|
+
WindowsNotepadUnsavedTabRecord = create_extended_descriptor([UserRecordDescriptorExtension])(
|
100
|
+
"texteditor/windowsnotepad/tab/unsaved",
|
101
|
+
GENERIC_TAB_CONTENTS_RECORD_FIELDS,
|
102
|
+
)
|
103
|
+
|
104
|
+
WindowsNotepadSavedTabRecord = create_extended_descriptor([UserRecordDescriptorExtension])(
|
105
|
+
"texteditor/windowsnotepad/tab/saved",
|
106
|
+
GENERIC_TAB_CONTENTS_RECORD_FIELDS + WINDOWS_SAVED_TABS_EXTRA_FIELDS,
|
107
|
+
)
|
108
|
+
|
109
|
+
c_windowstab = cstruct().load(windowstab_def)
|
110
|
+
|
111
|
+
|
112
|
+
def _calc_crc32(data: bytes) -> bytes:
|
113
|
+
"""Perform a CRC32 checksum on the data and return it as bytes."""
|
114
|
+
return zlib.crc32(data).to_bytes(length=4, byteorder="big")
|
115
|
+
|
116
|
+
|
117
|
+
class WindowsNotepadTab:
|
118
|
+
"""Windows notepad tab content parser"""
|
119
|
+
|
120
|
+
def __init__(self, file: TargetPath):
|
121
|
+
self.file = file
|
122
|
+
self.is_saved = None
|
123
|
+
self.content = None
|
124
|
+
self.deleted_content = None
|
125
|
+
self._process_tab_file()
|
126
|
+
|
127
|
+
def __repr__(self) -> str:
|
128
|
+
return (
|
129
|
+
f"<{self.__class__.__name__} saved={self.is_saved} "
|
130
|
+
f"content_size={len(self.content)} has_deleted_content={self.deleted_content is not None}>"
|
131
|
+
)
|
132
|
+
|
133
|
+
def _process_tab_file(self) -> None:
|
134
|
+
"""Parse a binary tab file and reconstruct the contents."""
|
135
|
+
with self.file.open("rb") as fh:
|
136
|
+
# Header is the same for all types
|
137
|
+
self.file_header = c_windowstab.file_header(fh)
|
138
|
+
|
139
|
+
# fileType == 1 # 0 is unsaved, 1 is saved, 9 is settings?
|
140
|
+
self.is_saved = self.file_header.fileType == 1
|
141
|
+
|
142
|
+
# Tabs can be saved to a file with a filename on disk, or unsaved (kept in the TabState folder).
|
143
|
+
# Depending on the file's saved state, different header fields are present
|
144
|
+
self.tab_header = (
|
145
|
+
c_windowstab.tab_header_saved(fh) if self.is_saved else c_windowstab.tab_header_unsaved(fh)
|
146
|
+
)
|
147
|
+
|
148
|
+
# There appears to be a optionsVersion field that specifies the options that are passed.
|
149
|
+
# At the moment of writing, it is not sure whether this specifies a version or a number of bytes
|
150
|
+
# that is parsed, so just going with the 'optionsVersion' type for now.
|
151
|
+
# We don't use the options, but since they are required for the CRC32 checksum
|
152
|
+
# we store the byte representation
|
153
|
+
if self.tab_header.optionsVersion == 0:
|
154
|
+
# No options specified
|
155
|
+
self.options = b""
|
156
|
+
elif self.tab_header.optionsVersion == 1:
|
157
|
+
self.options = c_windowstab.options_v1(fh).dumps()
|
158
|
+
elif self.tab_header.optionsVersion == 2:
|
159
|
+
self.options = c_windowstab.options_v2(fh).dumps()
|
160
|
+
else:
|
161
|
+
# Raise an error, since we don't know how many bytes future optionVersions will occupy.
|
162
|
+
# Now knowing how many bytes to parse can mess up the alignment and structs.
|
163
|
+
raise NotImplementedError("Unknown Windows Notepad tab option version")
|
164
|
+
|
165
|
+
# If the file is not saved to disk and no fixedSizeBlockLength is present, an extra checksum stub
|
166
|
+
# is present. So parse that first
|
167
|
+
if not self.is_saved and self.tab_header.fixedSizeBlockLength == 0:
|
168
|
+
# Two unknown bytes before the CRC32
|
169
|
+
tab_header_crc32_stub = c_windowstab.tab_header_crc32_stub(fh)
|
170
|
+
|
171
|
+
# Calculate CRC32 of the header and check if it matches
|
172
|
+
actual_header_crc32 = _calc_crc32(
|
173
|
+
self.file_header.dumps()[3:]
|
174
|
+
+ self.tab_header.dumps()
|
175
|
+
+ self.options
|
176
|
+
+ tab_header_crc32_stub.dumps()[:-4]
|
177
|
+
)
|
178
|
+
if tab_header_crc32_stub.crc32 != actual_header_crc32:
|
179
|
+
logging.warning(
|
180
|
+
"CRC32 mismatch in header of file: %s (expected=%s, actual=%s)",
|
181
|
+
self.file.name,
|
182
|
+
tab_header_crc32_stub.crc32.hex(),
|
183
|
+
actual_header_crc32.hex(),
|
184
|
+
)
|
185
|
+
|
186
|
+
# Used to store the final content
|
187
|
+
self.content = ""
|
188
|
+
|
189
|
+
# In the case that a fixedSizeDataBlock is present, this value is set to a nonzero value
|
190
|
+
if self.tab_header.fixedSizeBlockLength > 0:
|
191
|
+
# So we parse the fixed size data block
|
192
|
+
self.data_entry = c_windowstab.fixed_size_data_block(fh)
|
193
|
+
|
194
|
+
# The header (minus the magic) plus all data is included in the checksum
|
195
|
+
actual_crc32 = _calc_crc32(
|
196
|
+
self.file_header.dumps()[3:] + self.tab_header.dumps() + self.options + self.data_entry.dumps()[:-4]
|
197
|
+
)
|
198
|
+
|
199
|
+
if self.data_entry.crc32 != actual_crc32:
|
200
|
+
logging.warning(
|
201
|
+
"CRC32 mismatch in single-block file: %s (expected=%s, actual=%s)",
|
202
|
+
self.file.name,
|
203
|
+
self.data_entry.crc32.hex(),
|
204
|
+
actual_crc32.hex(),
|
205
|
+
)
|
206
|
+
|
207
|
+
# Add the content of the fixed size data block to the tab content
|
208
|
+
self.content += self.data_entry.data
|
209
|
+
|
210
|
+
# Used to store the deleted content, if available
|
211
|
+
deleted_content = ""
|
212
|
+
|
213
|
+
# If fixedSizeBlockLength in the header has a value of zero, this means that the entire file consists of
|
214
|
+
# variable-length blocks. Furthermore, if there is any remaining data after the
|
215
|
+
# first fixed size blocks, as indicated by the value of hasRemainingVariableDataBlocks,
|
216
|
+
# also continue we also want to continue parsing
|
217
|
+
if self.tab_header.fixedSizeBlockLength == 0 or (
|
218
|
+
self.tab_header.fixedSizeBlockLength > 0 and self.data_entry.hasRemainingVariableDataBlocks == 1
|
219
|
+
):
|
220
|
+
# Here, data is stored in variable-length blocks. This happens, for example, when several
|
221
|
+
# additions and deletions of characters have been recorded and these changes have not been 'flushed'
|
222
|
+
|
223
|
+
# Since we don't know the size of the file up front, and offsets don't necessarily have to be in order,
|
224
|
+
# a list is used to easily insert text at offsets
|
225
|
+
text = []
|
226
|
+
|
227
|
+
while True:
|
228
|
+
# Unfortunately, there is no way of determining how many blocks there are. So just try to parse
|
229
|
+
# until we reach EOF, after which we stop.
|
230
|
+
try:
|
231
|
+
data_entry = c_windowstab.variable_size_data_block(fh)
|
232
|
+
except EOFError:
|
233
|
+
break
|
234
|
+
|
235
|
+
# Either the nAdded is nonzero, or the nDeleted
|
236
|
+
if data_entry.nAdded > 0:
|
237
|
+
# Check the CRC32 checksum for this block
|
238
|
+
actual_crc32 = _calc_crc32(data_entry.dumps()[:-4])
|
239
|
+
if data_entry.crc32 != actual_crc32:
|
240
|
+
logging.warning(
|
241
|
+
"CRC32 mismatch in multi-block file: %s (expected=%s, actual=%s)",
|
242
|
+
self.file.name,
|
243
|
+
data_entry.crc32.hex(),
|
244
|
+
actual_crc32.hex(),
|
245
|
+
)
|
246
|
+
|
247
|
+
# Insert the text at the correct offset.
|
248
|
+
for idx in range(data_entry.nAdded):
|
249
|
+
text.insert(data_entry.offset + idx, data_entry.data[idx])
|
250
|
+
|
251
|
+
elif data_entry.nDeleted > 0:
|
252
|
+
# Create a new slice. Include everything up to the offset,
|
253
|
+
# plus everything after the nDeleted following bytes
|
254
|
+
deleted_content += "".join(text[data_entry.offset : data_entry.offset + data_entry.nDeleted])
|
255
|
+
text = text[: data_entry.offset] + text[data_entry.offset + data_entry.nDeleted :]
|
256
|
+
|
257
|
+
# Join all the characters to reconstruct the original text within the variable-length data blocks
|
258
|
+
text = "".join(text)
|
259
|
+
|
260
|
+
# Finally, add the reconstructed text to the tab content
|
261
|
+
self.content += text
|
262
|
+
|
263
|
+
# Set None if no deleted content was found
|
264
|
+
self.deleted_content = deleted_content if deleted_content else None
|
265
|
+
|
266
|
+
|
267
|
+
class WindowsNotepadPlugin(TexteditorPlugin):
|
268
|
+
"""Windows notepad tab content plugin."""
|
269
|
+
|
270
|
+
__namespace__ = "windowsnotepad"
|
271
|
+
|
272
|
+
GLOB = "AppData/Local/Packages/Microsoft.WindowsNotepad_*/LocalState/TabState/*.bin"
|
273
|
+
|
274
|
+
def __init__(self, target: Target):
|
275
|
+
super().__init__(target)
|
276
|
+
self.users_tabs: list[TargetPath, UnixUserRecord | WindowsUserRecord] = []
|
277
|
+
for user_details in self.target.user_details.all_with_home():
|
278
|
+
for tab_file in user_details.home_path.glob(self.GLOB):
|
279
|
+
# These files seem to contain information on different settings / configurations,
|
280
|
+
# and are skipped for now
|
281
|
+
if tab_file.name.endswith(".1.bin") or tab_file.name.endswith(".0.bin"):
|
282
|
+
continue
|
283
|
+
|
284
|
+
self.users_tabs.append((tab_file, user_details.user))
|
285
|
+
|
286
|
+
def check_compatible(self) -> None:
|
287
|
+
if not self.users_tabs:
|
288
|
+
raise UnsupportedPluginError("No Windows Notepad tab files found")
|
289
|
+
|
290
|
+
@export(record=[WindowsNotepadSavedTabRecord, WindowsNotepadUnsavedTabRecord])
|
291
|
+
def tabs(self) -> Iterator[WindowsNotepadSavedTabRecord | WindowsNotepadUnsavedTabRecord]:
|
292
|
+
"""Return contents from Windows 11 Notepad tabs - and its deleted content if available.
|
293
|
+
|
294
|
+
Windows Notepad application for Windows 11 is now able to restore both saved and unsaved tabs when you re-open
|
295
|
+
the application.
|
296
|
+
|
297
|
+
|
298
|
+
Resources:
|
299
|
+
- https://github.com/fox-it/dissect.target/pull/540
|
300
|
+
- https://github.com/JustArion/Notepad-Tabs
|
301
|
+
- https://github.com/ogmini/Notepad-Tabstate-Buffer
|
302
|
+
- https://github.com/ogmini/Notepad-State-Library
|
303
|
+
- https://github.com/Nordgaren/tabstate-util
|
304
|
+
- https://github.com/Nordgaren/tabstate-util/issues/1
|
305
|
+
- https://medium.com/@mahmoudsoheem/new-digital-forensics-artifact-from-windows-notepad-527645906b7b
|
306
|
+
|
307
|
+
Yields a WindowsNotepadSavedTabRecord or WindowsNotepadUnsavedTabRecord. with fields:
|
308
|
+
|
309
|
+
.. code-block:: text
|
310
|
+
|
311
|
+
content (string): The content of the tab.
|
312
|
+
path (path): The path to the tab file.
|
313
|
+
deleted_content (string): The deleted content of the tab, if available.
|
314
|
+
hashes (digest): A digest of the tab content.
|
315
|
+
saved_path (path): The path where the tab was saved.
|
316
|
+
modification_time (datetime): The modification time of the tab.
|
317
|
+
"""
|
318
|
+
for file, user in self.users_tabs:
|
319
|
+
# Parse the file
|
320
|
+
tab: WindowsNotepadTab = WindowsNotepadTab(file)
|
321
|
+
|
322
|
+
if tab.is_saved:
|
323
|
+
yield WindowsNotepadSavedTabRecord(
|
324
|
+
content=tab.content,
|
325
|
+
path=tab.file,
|
326
|
+
deleted_content=tab.deleted_content,
|
327
|
+
hashes=digest((None, None, tab.tab_header.sha256.hex())),
|
328
|
+
saved_path=tab.tab_header.filePath,
|
329
|
+
modification_time=wintimestamp(tab.tab_header.timestamp),
|
330
|
+
_target=self.target,
|
331
|
+
_user=user,
|
332
|
+
)
|
333
|
+
else:
|
334
|
+
yield WindowsNotepadUnsavedTabRecord(
|
335
|
+
content=tab.content,
|
336
|
+
path=tab.file,
|
337
|
+
_target=self.target,
|
338
|
+
_user=user,
|
339
|
+
deleted_content=tab.deleted_content,
|
340
|
+
)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import Iterator
|
4
|
+
|
5
|
+
from dissect.target.exceptions import UnsupportedPluginError
|
6
|
+
from dissect.target.helpers.record import ChildTargetRecord
|
7
|
+
from dissect.target.plugin import ChildTargetPlugin
|
8
|
+
|
9
|
+
|
10
|
+
class QemuChildTargetPlugin(ChildTargetPlugin):
|
11
|
+
"""Child target plugin that yields all QEMU domains from a KVM libvirt deamon."""
|
12
|
+
|
13
|
+
__type__ = "qemu"
|
14
|
+
|
15
|
+
def check_compatible(self) -> None:
|
16
|
+
if not self.target.fs.path("/etc/libvirt/qemu").exists():
|
17
|
+
raise UnsupportedPluginError("No libvirt QEMU installation found")
|
18
|
+
|
19
|
+
def list_children(self) -> Iterator[ChildTargetRecord]:
|
20
|
+
for domain in self.target.fs.path("/etc/libvirt/qemu").glob("*.xml"):
|
21
|
+
yield ChildTargetRecord(type=self.__type__, path=domain)
|