# -*- coding: utf-8 -*-
"""This file contains the NetworkList registry plugin."""
from __future__ import unicode_literals
from dfdatetime import systemtime as dfdatetime_systemtime
from plaso.containers import events
from plaso.containers import time_events
from plaso.lib import definitions
from plaso.lib import errors
from plaso.parsers import winreg
from plaso.parsers.winreg_plugins import dtfabric_plugin
from plaso.parsers.winreg_plugins import interface
[docs]class WindowsRegistryNetworkEventData(events.EventData):
"""Windows network event data.
Attributes:
connection_type (str): type of connection.
default_gateway_mac (str): MAC address for the default gateway.
description (str): description of the wireless connection.
dns_suffix (str): DNS suffix.
ssid (str): SSID of the connection.
"""
DATA_TYPE = 'windows:registry:network'
def __init__(self):
"""Initializes event data."""
super(WindowsRegistryNetworkEventData, self).__init__(
data_type=self.DATA_TYPE)
self.connection_type = None
self.default_gateway_mac = None
self.description = None
self.dns_suffix = None
self.ssid = None
[docs]class NetworksWindowsRegistryPlugin(
dtfabric_plugin.DtFabricBaseWindowsRegistryPlugin):
"""Windows Registry plugin for parsing the NetworkList key."""
NAME = 'networks'
DESCRIPTION = 'Parser for NetworkList data.'
FILTERS = frozenset([
interface.WindowsRegistryKeyPathFilter(
'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion'
'\\NetworkList')])
_DEFINITION_FILE = 'systemtime.yaml'
_CONNECTION_TYPE = {
0x06: 'Wired',
0x17: '3g',
0x47: 'Wireless'}
_EMPTY_SYSTEM_TIME_TUPLE = (0, 0, 0, 0, 0, 0, 0, 0)
def _GetNetworkInfo(self, signatures_key):
"""Retrieves the network info within the signatures subkey.
Args:
signatures_key (dfwinreg.WinRegistryKey): a Windows Registry key.
Returns:
dict[str, tuple]: a tuple of default_gateway_mac and dns_suffix per
profile identifier (GUID).
"""
network_info = {}
for category in signatures_key.GetSubkeys():
for signature in category.GetSubkeys():
profile_guid_value = signature.GetValueByName('ProfileGuid')
if profile_guid_value:
profile_guid = profile_guid_value.GetDataAsObject()
else:
continue
default_gateway_mac_value = signature.GetValueByName(
'DefaultGatewayMac')
if default_gateway_mac_value:
default_gateway_mac = ':'.join([
'{0:02x}'.format(octet)
for octet in bytearray(default_gateway_mac_value.data)])
else:
default_gateway_mac = None
dns_suffix_value = signature.GetValueByName('DnsSuffix')
if dns_suffix_value:
dns_suffix = dns_suffix_value.GetDataAsObject()
else:
dns_suffix = None
network_info[profile_guid] = (default_gateway_mac, dns_suffix)
return network_info
def _ParseSystemTime(self, byte_stream):
"""Parses a SYSTEMTIME date and time value from a byte stream.
Args:
byte_stream (bytes): byte stream.
Returns:
dfdatetime.Systemtime: SYSTEMTIME date and time value or None if no
value is set.
Raises:
ParseError: if the SYSTEMTIME could not be parsed.
"""
systemtime_map = self._GetDataTypeMap('systemtime')
try:
systemtime = self._ReadStructureFromByteStream(
byte_stream, 0, systemtime_map)
except (ValueError, errors.ParseError) as exception:
raise errors.ParseError(
'Unable to parse SYSTEMTIME value with error: {0!s}'.format(
exception))
system_time_tuple = (
systemtime.year, systemtime.month, systemtime.weekday,
systemtime.day_of_month, systemtime.hours, systemtime.minutes,
systemtime.seconds, systemtime.milliseconds)
if system_time_tuple == self._EMPTY_SYSTEM_TIME_TUPLE:
return None
try:
return dfdatetime_systemtime.Systemtime(
system_time_tuple=system_time_tuple)
except ValueError:
raise errors.ParseError(
'Invalid SYSTEMTIME value: {0!s}'.format(system_time_tuple))
# pylint 1.9.3 wants a docstring for kwargs, but this is not useful to add.
# pylint: disable=missing-param-doc
parser_mediator.ProduceEventWithEventData(event, event_data)
winreg.WinRegistryParser.RegisterPlugin(NetworksWindowsRegistryPlugin)