-
Notifications
You must be signed in to change notification settings - Fork 325
/
windows.py
734 lines (559 loc) · 25.7 KB
/
windows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# -*- coding: utf-8 -*-
"""This file contains preprocessors for Windows."""
import os
from plaso.containers import artifacts
from plaso.lib import dtfabric_helper
from plaso.lib import errors
from plaso.preprocessors import interface
from plaso.preprocessors import manager
from plaso.winnt import language_ids
class WindowsEnvironmentVariableArtifactPreprocessorPlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""Windows environment variable artifact preprocessor plugin interface."""
_NAME = None
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
environment_variable = artifacts.EnvironmentVariableArtifact(
case_sensitive=False, name=self._NAME, value=value_data)
try:
mediator.AddEnvironmentVariable(environment_variable)
except KeyError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'Unable to set environment variable: {0:s} in knowledge base.'.format(
self._NAME))
class WindowsPathEnvironmentVariableArtifactPreprocessorPlugin(
interface.FileSystemArtifactPreprocessorPlugin):
"""Windows path environment variable plugin interface."""
_NAME = None
def _ParsePathSpecification(
self, mediator, searcher, file_system, path_specification,
path_separator):
"""Parses artifact file system data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
searcher (dfvfs.FileSystemSearcher): file system searcher to preprocess
the file system.
file_system (dfvfs.FileSystem): file system to be preprocessed.
path_specification (dfvfs.PathSpec): path specification that contains
the artifact value data.
path_separator (str): path segment separator.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
relative_path = searcher.GetRelativePath(path_specification)
if not relative_path:
raise errors.PreProcessFail(
'Unable to read: {0:s} with error: missing relative path'.format(
self.ARTIFACT_DEFINITION_NAME))
if path_separator != file_system.PATH_SEPARATOR:
relative_path_segments = file_system.SplitPath(relative_path)
relative_path = '{0:s}{1:s}'.format(
path_separator, path_separator.join(relative_path_segments))
environment_variable = artifacts.EnvironmentVariableArtifact(
case_sensitive=False, name=self._NAME, value=relative_path)
try:
mediator.AddEnvironmentVariable(environment_variable)
except KeyError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'Unable to set environment variable: {0:s} in knowledge base.'.format(
self._NAME))
class WindowsAllUsersAppDataKnowledgeBasePlugin(
interface.KnowledgeBasePreprocessorPlugin):
"""The allusersdata knowledge base value plugin.
The allusersdata value is needed for the expansion of
%%environ_allusersappdata%% in artifact definitions.
"""
def Collect(self, mediator):
"""Collects values from the knowledge base.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
Raises:
PreProcessFail: if the preprocessing fails.
"""
environment_variable = mediator.GetEnvironmentVariable('programdata')
allusersappdata = getattr(environment_variable, 'value', None)
if not allusersappdata:
environment_variable = mediator.GetEnvironmentVariable('allusersprofile')
allusersdata = getattr(environment_variable, 'value', None)
if allusersdata:
allusersappdata = '\\'.join([allusersdata, 'Application Data'])
if allusersappdata:
environment_variable = artifacts.EnvironmentVariableArtifact(
case_sensitive=False, name='allusersappdata', value=allusersappdata)
try:
mediator.AddEnvironmentVariable(environment_variable)
except KeyError:
mediator.ProducePreprocessingWarning(
self.__class__.__name__,
('Unable to set environment variable: %AllUsersAppData% in '
'knowledge base.'))
class WindowsAllUsersProfileEnvironmentVariablePlugin(
WindowsEnvironmentVariableArtifactPreprocessorPlugin):
"""The Windows %AllUsersProfile% environment variable plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEnvironmentVariableAllUsersProfile'
_NAME = 'allusersprofile'
class WindowsAllUsersAppProfileKnowledgeBasePlugin(
interface.KnowledgeBasePreprocessorPlugin):
"""The allusersprofile knowledge base value plugin.
The allusersprofile value is needed for the expansion of
%%environ_allusersappprofile%% in artifact definitions.
It is derived from %ProgramData% for versions of Windows, Vista and later,
that do not define %AllUsersProfile%.
"""
def Collect(self, mediator):
"""Collects values from the knowledge base.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
Raises:
PreProcessFail: if the preprocessing fails.
"""
environment_variable = mediator.GetEnvironmentVariable('allusersprofile')
allusersprofile = getattr(environment_variable, 'value', None)
if not allusersprofile:
environment_variable = mediator.GetEnvironmentVariable('programdata')
allusersprofile = getattr(environment_variable, 'value', None)
if allusersprofile:
environment_variable = artifacts.EnvironmentVariableArtifact(
case_sensitive=False, name='allusersprofile', value=allusersprofile)
try:
mediator.AddEnvironmentVariable(environment_variable)
except KeyError:
mediator.ProducePreprocessingWarning(
self.__class__.__name__,
('Unable to set environment variable: %AllUsersProfile% in '
'knowledge base.'))
class WindowsAvailableTimeZonesPlugin(
interface.WindowsRegistryKeyArtifactPreprocessorPlugin,
dtfabric_helper.DtFabricHelper):
"""The Windows available time zones plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsAvailableTimeZones'
_DEFINITION_FILE = os.path.join(
os.path.dirname(__file__), 'time_zone_information.yaml')
def _ParseKey(self, mediator, registry_key, value_name):
"""Parses a Windows Registry key for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the Windows Registry value or None if not
specified.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
std_value = registry_key.GetValueByName('Std')
if std_value:
localized_name = std_value.GetDataAsObject()
else:
localized_name = registry_key.name
mui_std_value = registry_key.GetValueByName('MUI_Std')
if mui_std_value:
mui_form = std_value.GetDataAsObject()
else:
mui_form = None
tzi_value = registry_key.GetValueByName('TZI')
if not tzi_value:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'TZI value missing from Windows Registry key: {0:s}'.format(
registry_key.key_path))
return
time_zone_artifact = artifacts.TimeZoneArtifact(
localized_name=localized_name, mui_form=mui_form,
name=registry_key.name)
try:
self._ParseTZIValue(tzi_value.data, time_zone_artifact)
except (ValueError, errors.ParseError) as exception:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'Unable to parse TZI record value in Windows Registry key: {0:s} '
'with error: {2!s}'.format(
registry_key.key_path, exception))
return
try:
mediator.AddTimeZoneInformation(time_zone_artifact)
except KeyError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
('Unable to add time zone information: {0:s} to knowledge '
'base.').format(registry_key.name))
def _ParseTZIValue(self, value_data, time_zone_artifact):
"""Parses the time zone information (TZI) value data.
Args:
value_data (bytes): time zone information (TZI) value data.
time_zone_artifact (TimeZoneArtifact): time zone artifact.
Raises:
ParseError: if the value data could not be parsed.
"""
data_type_map = self._GetDataTypeMap('tzi_record')
tzi_record = self._ReadStructureFromByteStream(
value_data, 0, data_type_map)
if tzi_record.standard_bias:
time_zone_artifact.offset = tzi_record.standard_bias
else:
time_zone_artifact.offset = tzi_record.bias
class WindowsCodepagePlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""The Windows codepage plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsCodePage'
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
# Map the Windows code page name to a Python equivalent name.
codepage = 'cp{0:s}'.format(value_data)
try:
mediator.SetCodepage(codepage)
except ValueError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'Unable to set codepage in knowledge base.')
class WindowsEventLogPublishersPlugin(
interface.WindowsRegistryKeyArtifactPreprocessorPlugin):
"""The Windows Event Log publishers plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEventLogPublishers'
def _ParseKey(self, mediator, registry_key, value_name):
"""Parses a Windows Registry key for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the Windows Registry value or None if not
specified.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
registry_value = registry_key.GetValueByName('')
if not registry_value:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'EventLog source missing for: {0:s}'.format(
registry_key.name))
return
log_source = registry_value.GetDataAsObject()
event_message_files = None
registry_value = registry_key.GetValueByName('MessageFileName')
if registry_value:
event_message_files = registry_value.GetDataAsObject()
event_message_files = sorted(filter(None, [
path.strip().lower() for path in event_message_files.split(';')]))
provider_identifier = registry_key.name.lower()
windows_event_log_provider = artifacts.WindowsEventLogProviderArtifact(
event_message_files=event_message_files, identifier=provider_identifier,
log_source=log_source)
try:
mediator.AddWindowsEventLogProvider(windows_event_log_provider)
except KeyError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
('Unable to set add Windows Event Log provider: {0:s} to '
'knowledge base.').format(log_source))
class WindowsEventLogSourcesPlugin(
interface.WindowsRegistryKeyArtifactPreprocessorPlugin):
"""The Windows Event Log sources plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEventLogSources'
def _ParseKey(self, mediator, registry_key, value_name):
"""Parses a Windows Registry key for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the Windows Registry value or None if not
specified.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
category_message_files = None
registry_value = registry_key.GetValueByName('CategoryMessageFile')
if registry_value:
category_message_files = registry_value.GetDataAsObject()
category_message_files = sorted(filter(None, [
path.strip().lower() for path in category_message_files.split(';')]))
event_message_files = None
registry_value = registry_key.GetValueByName('EventMessageFile')
if registry_value:
event_message_files = registry_value.GetDataAsObject()
event_message_files = sorted(filter(None, [
path.strip().lower() for path in event_message_files.split(';')]))
parameter_message_files = None
registry_value = registry_key.GetValueByName('ParameterMessageFile')
if registry_value:
parameter_message_files = registry_value.GetDataAsObject()
parameter_message_files = sorted(filter(None, [
path.strip().lower() for path in parameter_message_files.split(';')]))
provider_identifier = None
registry_value = registry_key.GetValueByName('ProviderGuid')
if registry_value:
provider_identifier = registry_value.GetDataAsObject()
provider_identifier = provider_identifier.lower()
key_path_segments = registry_key.path.split('\\')
log_source = key_path_segments[-1]
log_type = key_path_segments[-2]
windows_event_log_provider = artifacts.WindowsEventLogProviderArtifact(
category_message_files=category_message_files,
event_message_files=event_message_files, identifier=provider_identifier,
log_source=log_source, log_type=log_type,
parameter_message_files=parameter_message_files)
try:
mediator.AddWindowsEventLogProvider(windows_event_log_provider)
except KeyError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
('Unable to set add Windows Event Log provider: {0:s}/{1:s} to '
'knowledge base.').format(log_type, log_source))
class WindowsHostnamePlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""The Windows hostname plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsComputerName'
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
if not hasattr(value_data, '__iter__'):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
# If the value data is a multi string only use the first string.
value_data = value_data[0]
hostname_artifact = artifacts.HostnameArtifact(name=value_data)
mediator.AddHostname(hostname_artifact)
class WindowsLanguagePlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""The Windows language plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsLanguage'
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
try:
lcid = int(value_data, 16)
language_tag = language_ids.LANGUAGE_TAG_PER_LCID.get(lcid, None)
except ValueError:
language_tag = None
if language_tag:
mediator.SetLanguage(language_tag)
else:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'Unable to determine language tag for LCID: {0:s}.'.format(
value_data))
class WindowsProgramDataEnvironmentVariablePlugin(
WindowsEnvironmentVariableArtifactPreprocessorPlugin):
"""The Windows %ProgramData% environment variable plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEnvironmentVariableProgramData'
_NAME = 'programdata'
class WindowsProgramDataKnowledgeBasePlugin(
interface.KnowledgeBasePreprocessorPlugin):
"""The programdata knowledge base value plugin.
The programdata value is needed for the expansion of %%environ_programdata%%
in artifact definitions.
It is derived from %AllUsersProfile% for versions of Windows prior to Vista
that do not define %ProgramData%.
"""
def Collect(self, mediator):
"""Collects values from the knowledge base.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
Raises:
PreProcessFail: if the preprocessing fails.
"""
environment_variable = mediator.GetEnvironmentVariable('programdata')
allusersprofile = getattr(environment_variable, 'value', None)
if not allusersprofile:
environment_variable = mediator.GetEnvironmentVariable('allusersprofile')
allusersprofile = getattr(environment_variable, 'value', None)
if allusersprofile:
environment_variable = artifacts.EnvironmentVariableArtifact(
case_sensitive=False, name='programdata', value=allusersprofile)
try:
mediator.AddEnvironmentVariable(environment_variable)
except KeyError:
mediator.ProducePreprocessingWarning(
self.__class__.__name__,
('Unable to set environment variable: %ProgramData% in '
'knowledge base.'))
class WindowsProgramFilesEnvironmentVariablePlugin(
WindowsEnvironmentVariableArtifactPreprocessorPlugin):
"""The Windows %ProgramFiles% environment variable plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEnvironmentVariableProgramFiles'
_NAME = 'programfiles'
class WindowsProgramFilesX86EnvironmentVariablePlugin(
WindowsEnvironmentVariableArtifactPreprocessorPlugin):
"""The Windows %ProgramFilesX86% environment variable plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEnvironmentVariableProgramFilesX86'
_NAME = 'programfilesx86'
class WindowsSystemProductPlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""The Windows system product information plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsProductName'
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
mediator.SetValue('operating_system_product', value_data)
class WindowsSystemRootEnvironmentVariablePlugin(
WindowsPathEnvironmentVariableArtifactPreprocessorPlugin):
"""The Windows %SystemRoot% environment variable plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEnvironmentVariableSystemRoot'
_NAME = 'systemroot'
class WindowsSystemVersionPlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""The Windows system version information plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsCurrentVersion'
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
mediator.SetValue('operating_system_version', value_data)
class WindowsTimeZonePlugin(
interface.WindowsRegistryValueArtifactPreprocessorPlugin):
"""The Windows time zone plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsTimezone'
def _ParseValueData(self, mediator, value_data):
"""Parses Windows Registry value data for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
value_data (object): Windows Registry value data.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
if not isinstance(value_data, str):
raise errors.PreProcessFail(
'Unsupported Windows Registry value type: {0!s} for '
'artifact: {1:s}.'.format(
type(value_data), self.ARTIFACT_DEFINITION_NAME))
try:
mediator.SetTimeZone(value_data)
except ValueError as execption:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
'Unable to map: "{0:s}" to time zone with error: {1!s}'.format(
value_data, execption))
class WindowsUserAccountsPlugin(
interface.WindowsRegistryKeyArtifactPreprocessorPlugin):
"""The Windows user account plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsRegistryProfiles'
def _GetUsernameFromProfilePath(self, path):
"""Retrieves the username from a Windows profile path.
Trailing path path segment are ignored.
Args:
path (str): a Windows path with '\\' as path segment separator.
Returns:
str: basename which is the last path segment.
"""
# Strip trailing key separators.
while path and path[-1] == '\\':
path = path[:-1]
if path:
_, _, path = path.rpartition('\\')
return path
def _ParseKey(self, mediator, registry_key, value_name):
"""Parses a Windows Registry key for a preprocessing attribute.
Args:
mediator (PreprocessMediator): mediates interactions between preprocess
plugins and other components, such as storage and knowledge base.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the Windows Registry value or None if not
specified.
Raises:
errors.PreProcessFail: if the preprocessing fails.
"""
user_account = artifacts.UserAccountArtifact(
identifier=registry_key.name, path_separator='\\')
registry_value = registry_key.GetValueByName('ProfileImagePath')
if registry_value:
profile_path = registry_value.GetDataAsObject()
username = self._GetUsernameFromProfilePath(profile_path)
user_account.user_directory = profile_path or None
user_account.username = username or None
try:
mediator.AddUserAccount(user_account)
except KeyError:
mediator.ProducePreprocessingWarning(
self.ARTIFACT_DEFINITION_NAME,
('Unable to add user account: "{0!s}" to knowledge '
'base').format(username))
class WindowsWinDirEnvironmentVariablePlugin(
WindowsPathEnvironmentVariableArtifactPreprocessorPlugin):
"""The Windows %WinDir% environment variable plugin."""
ARTIFACT_DEFINITION_NAME = 'WindowsEnvironmentVariableWinDir'
_NAME = 'windir'
manager.PreprocessPluginsManager.RegisterPlugins([
WindowsAllUsersAppDataKnowledgeBasePlugin,
WindowsAllUsersProfileEnvironmentVariablePlugin,
WindowsAllUsersAppProfileKnowledgeBasePlugin,
WindowsAvailableTimeZonesPlugin,
WindowsCodepagePlugin, WindowsEventLogPublishersPlugin,
WindowsEventLogSourcesPlugin, WindowsHostnamePlugin, WindowsLanguagePlugin,
WindowsProgramDataEnvironmentVariablePlugin,
WindowsProgramDataKnowledgeBasePlugin,
WindowsProgramFilesEnvironmentVariablePlugin,
WindowsProgramFilesX86EnvironmentVariablePlugin,
WindowsSystemProductPlugin, WindowsSystemRootEnvironmentVariablePlugin,
WindowsSystemVersionPlugin, WindowsTimeZonePlugin,
WindowsWinDirEnvironmentVariablePlugin, WindowsUserAccountsPlugin])