Ejemplo n.º 1
0
    def GetSystemConfigurationArtifact(self, session_number=0):
        """Retrieves the knowledge base as a system configuration artifact.

    Args:
      session_number (Optional[int]): session number, where 0 represents
          the active session.

    Returns:
      SystemConfigurationArtifact: system configuration artifact.
    """
        system_configuration = artifacts.SystemConfigurationArtifact()

        system_configuration.code_page = self._values.get(
            u'codepage', self._default_codepage)

        system_configuration.hostname = self._hostnames.get(
            session_number, None)

        system_configuration.keyboard_layout = self._values.get(
            u'keyboard_layout', None)
        system_configuration.operating_system = self._values.get(
            u'operating_system', None)
        system_configuration.operating_system_product = self._values.get(
            u'operating_system_product', None)
        system_configuration.operating_system_version = self._values.get(
            u'operating_system_version', None)
        system_configuration.time_zone = self._values.get(
            u'time_zone_str', u'UTC')

        user_accounts = self._user_accounts.get(session_number, {})
        system_configuration.user_accounts = user_accounts.values()

        return system_configuration
Ejemplo n.º 2
0
  def testGetAttributeNames(self):
    """Tests the GetAttributeNames function."""
    attribute_container = artifacts.SystemConfigurationArtifact()

    expected_attribute_names = [
        'available_time_zones', 'code_page', 'hostname', 'keyboard_layout',
        'operating_system', 'operating_system_product',
        'operating_system_version', 'time_zone', 'user_accounts']

    attribute_names = sorted(attribute_container.GetAttributeNames())
    self.assertEqual(attribute_names, expected_attribute_names)
Ejemplo n.º 3
0
    def _GetSystemConfigurationArtifact(self, session_identifier=None):
        """Retrieves the knowledge base as a system configuration artifact.

    Args:
      session_identifier (Optional[str])): session identifier, where
          None represents the active session.

    Returns:
      SystemConfigurationArtifact: system configuration artifact.
    """
        session_identifier = session_identifier or self._active_session

        system_configuration = artifacts.SystemConfigurationArtifact()

        system_configuration.code_page = self.GetValue(
            'codepage', default_value=self._codepage)

        system_configuration.hostname = self._hostnames.get(
            session_identifier, None)

        system_configuration.keyboard_layout = self.GetValue('keyboard_layout')
        system_configuration.operating_system = self.GetValue(
            'operating_system')
        system_configuration.operating_system_product = self.GetValue(
            'operating_system_product')
        system_configuration.operating_system_version = self.GetValue(
            'operating_system_version')

        time_zone = self._time_zone.zone
        if isinstance(time_zone, bytes):
            time_zone = time_zone.decode('ascii')

        system_configuration.time_zone = time_zone

        available_time_zones = self._available_time_zones.get(
            session_identifier, {})
        # In Python 3 dict.values() returns a type dict_values, which will cause
        # the JSON serializer to raise a TypeError.
        system_configuration.available_time_zones = list(
            available_time_zones.values())

        user_accounts = self._user_accounts.get(session_identifier, {})
        # In Python 3 dict.values() returns a type dict_values, which will cause
        # the JSON serializer to raise a TypeError.
        system_configuration.user_accounts = list(user_accounts.values())

        windows_eventlog_providers = self._windows_eventlog_providers.get(
            session_identifier, {})
        # In Python 3 dict.values() returns a type dict_values, which will cause
        # the JSON serializer to raise a TypeError.
        system_configuration.windows_eventlog_providers = list(
            windows_eventlog_providers.values())

        return system_configuration
Ejemplo n.º 4
0
  def testCopyToDict(self):
    """Tests the CopyToDict function."""
    attribute_container = artifacts.SystemConfigurationArtifact(
        code_page='cp1252', time_zone='UTC')

    self.assertEqual(attribute_container.time_zone, 'UTC')

    expected_dict = {
        'code_page': 'cp1252',
        'time_zone': 'UTC',
        'user_accounts': []}

    test_dict = attribute_container.CopyToDict()

    self.assertEqual(test_dict, expected_dict)
Ejemplo n.º 5
0
  def testCopyToDict(self):
    """Tests the CopyToDict function."""
    system_configuration = artifacts.SystemConfigurationArtifact(
        code_page=u'cp1252', time_zone=u'UTC')

    self.assertEqual(system_configuration.time_zone, u'UTC')

    expected_dict = {
        u'code_page': u'cp1252',
        u'time_zone': u'UTC',
        u'user_accounts': []}

    system_configuration_dict = system_configuration.CopyToDict()

    self.assertEqual(system_configuration_dict, expected_dict)
Ejemplo n.º 6
0
  def testReadSystemConfigurationArtifact(self):
    """Tests the ReadSystemConfigurationArtifact function."""
    knowledge_base_object = knowledge_base.KnowledgeBase()

    system_configuration = artifacts.SystemConfigurationArtifact()
    system_configuration.hostname = artifacts.HostnameArtifact(
        name='myhost.mydomain')

    user_account = artifacts.UserAccountArtifact(
        identifier='1000', user_directory='/home/testuser',
        username='******')
    system_configuration.user_accounts.append(user_account)

    knowledge_base_object.ReadSystemConfigurationArtifact(system_configuration)

    hostname = knowledge_base_object.GetHostname()
    self.assertEqual(hostname, 'myhost.mydomain')
Ejemplo n.º 7
0
    def GetSystemConfigurationArtifact(self):
        """Retrieves the knowledge base as a system configuration artifact.

    Returns:
      SystemConfigurationArtifact: system configuration artifact.
    """
        system_configuration = artifacts.SystemConfigurationArtifact()

        system_configuration.code_page = self.GetValue(
            'codepage', default_value=self._codepage)

        system_configuration.hostname = self._hostnames.get(
            self._active_session, None)

        system_configuration.keyboard_layout = self.GetValue('keyboard_layout')

        system_configuration.language = self._language

        system_configuration.operating_system = self.GetValue(
            'operating_system')
        system_configuration.operating_system_product = self.GetValue(
            'operating_system_product')
        system_configuration.operating_system_version = self.GetValue(
            'operating_system_version')

        time_zone = self._time_zone.zone
        if isinstance(time_zone, bytes):
            time_zone = time_zone.decode('ascii')

        system_configuration.time_zone = time_zone

        available_time_zones = self._available_time_zones.get(
            self._active_session, {})
        # In Python 3 dict.values() returns a type dict_values, which will cause
        # the JSON serializer to raise a TypeError.
        system_configuration.available_time_zones = list(
            available_time_zones.values())

        user_accounts = self._user_accounts.get(self._active_session, {})
        # In Python 3 dict.values() returns a type dict_values, which will cause
        # the JSON serializer to raise a TypeError.
        system_configuration.user_accounts = list(user_accounts.values())

        return system_configuration
Ejemplo n.º 8
0
    def GetSystemConfigurationArtifact(self,
                                       session_identifier=CURRENT_SESSION):
        """Retrieves the knowledge base as a system configuration artifact.

    Args:
      session_identifier (Optional[str])): session identifier, where
          CURRENT_SESSION represents the active session.

    Returns:
      SystemConfigurationArtifact: system configuration artifact.
    """
        system_configuration = artifacts.SystemConfigurationArtifact()

        system_configuration.code_page = self.GetValue(
            'codepage', default_value=self._codepage)

        system_configuration.hostname = self._hostnames.get(
            session_identifier, None)

        system_configuration.keyboard_layout = self.GetValue('keyboard_layout')
        system_configuration.operating_system = self.GetValue(
            'operating_system')
        system_configuration.operating_system_product = self.GetValue(
            'operating_system_product')
        system_configuration.operating_system_version = self.GetValue(
            'operating_system_version')

        date_time = datetime.datetime(2017, 1, 1)
        time_zone = self._time_zone.tzname(date_time)

        if time_zone and isinstance(time_zone, py2to3.BYTES_TYPE):
            time_zone = time_zone.decode('ascii')

        system_configuration.time_zone = time_zone

        user_accounts = self._user_accounts.get(session_identifier, {})
        # In Python 3 dict.values() returns a type dict_values, which will cause
        # the JSON serializer to raise a TypeError.
        system_configuration.user_accounts = list(user_accounts.values())

        return system_configuration
Ejemplo n.º 9
0
    def GetSystemConfigurationArtifact(self,
                                       session_identifier=CURRENT_SESSION):
        """Retrieves the knowledge base as a system configuration artifact.

    Args:
      session_identifier (Optional[str])): session identifier, where
          CURRENT_SESSION represents the active session.

    Returns:
      SystemConfigurationArtifact: system configuration artifact.
    """
        system_configuration = artifacts.SystemConfigurationArtifact()

        system_configuration.code_page = self._values.get(
            'codepage', self._codepage)

        system_configuration.hostname = self._hostnames.get(
            session_identifier, None)

        system_configuration.keyboard_layout = self._values.get(
            'keyboard_layout', None)
        system_configuration.operating_system = self._values.get(
            'operating_system', None)
        system_configuration.operating_system_product = self._values.get(
            'operating_system_product', None)
        system_configuration.operating_system_version = self._values.get(
            'operating_system_version', None)

        date_time = datetime.datetime(2017, 1, 1)
        time_zone = self._time_zone.tzname(date_time)
        system_configuration.time_zone = time_zone

        user_accounts = self._user_accounts.get(session_identifier, {})
        system_configuration.user_accounts = user_accounts.values()

        return system_configuration