Esempio n. 1
0
    def testScanVolumeScanNodeEncrypted(self):
        """Tests the _ScanVolumeScanNodeEncrypted function."""
        resolver.Resolver.key_chain.Empty()

        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(test_mediator)

        test_file = self._GetTestFilePath([u'bdetogo.raw'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        volume_scan_node = self._GetTestScanNode(scan_context)

        base_path_specs = []
        test_scanner._ScanVolumeScanNode(scan_context,
                                         volume_scan_node.sub_nodes[0],
                                         base_path_specs)
        self.assertEqual(len(base_path_specs), 1)

        # Test error conditions.
        path_spec = fake_path_spec.FakePathSpec(location=u'/')
        scan_node = source_scanner.SourceScanNode(path_spec)

        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeScanNodeEncrypted(scan_node, None, [])

        volume_scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeScanNodeEncrypted(scan_node,
                                                      volume_scan_node, [])
Esempio n. 2
0
    def testScanFileSystem(self):
        """Tests the _ScanFileSystem function."""
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.WindowsVolumeScanner(
            mediator=test_mediator)

        test_path = self._GetTestFilePath(['windows_volume.qcow2'])
        self._SkipIfPathNotExists(test_path)

        test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
            definitions.TYPE_INDICATOR_OS, location=test_path)
        test_qcow_path_spec = path_spec_factory.Factory.NewPathSpec(
            definitions.TYPE_INDICATOR_QCOW, parent=test_os_path_spec)
        test_tsk_path_spec = path_spec_factory.Factory.NewPathSpec(
            definitions.TYPE_INDICATOR_TSK,
            location='/',
            parent=test_qcow_path_spec)

        scan_node = source_scanner.SourceScanNode(test_tsk_path_spec)

        base_path_specs = []
        test_scanner._ScanFileSystem(scan_node, base_path_specs)
        self.assertEqual(len(base_path_specs), 1)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanFileSystem(None, [])

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanFileSystem(scan_node, [])
Esempio n. 3
0
    def testScanVolumeScanNodeRAW(self):
        """Tests the _ScanVolumeScanNode function on a RAW image."""
        test_scanner = volume_scanner.VolumeScanner()

        test_file = self._GetTestFilePath([u'ímynd.dd'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        volume_scan_node = scan_context.GetRootScanNode()

        base_path_specs = []
        test_scanner._ScanVolumeScanNode(scan_context, volume_scan_node,
                                         base_path_specs)
        self.assertEqual(len(base_path_specs), 1)

        # Test error conditions.
        scan_context = source_scanner.SourceScannerContext()

        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeScanNode(scan_context, None, [])

        volume_scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeScanNode(scan_context, volume_scan_node,
                                             [])
Esempio n. 4
0
    def testUnlockEncryptedVolume(self, mock_source_scanner):
        """Test the UnlockEncryptedVolume function."""
        mediator = UnattendedVolumeScannerMediator()
        mediator.credentials.append({
            'credential_type': 'password',
            'credential_data': '123456'
        })

        os_path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_OS, location='/path/to/image.dd')
        raw_path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_RAW, parent=os_path_spec)
        tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_TSK_PARTITION,
            parent=raw_path_spec)
        path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_BDE,
            parent=tsk_partition_path_spec)

        scan_node = source_scanner.SourceScanNode(path_spec)

        mock_source_scanner.Unlock.return_value = True
        result = mediator.UnlockEncryptedVolume(
            source_scanner_object=mock_source_scanner,
            scan_context=None,
            locked_scan_node=scan_node,
            credentials=None)
        self.assertTrue(result)
Esempio n. 5
0
    def testUnlockEncryptedVolume(self):
        """Test the UnlockEncryptedVolume function.

    Encrypted volume support is not yet implemented.
    """
        mediator = UnattendedVolumeScannerMediator()

        os_path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_OS, location='/path/to/image.dd')
        raw_path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_RAW, parent=os_path_spec)
        tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_TSK_PARTITION,
            parent=raw_path_spec)
        path_spec = path_spec_factory.Factory.NewPathSpec(
            dfvfs_definitions.TYPE_INDICATOR_BDE,
            parent=tsk_partition_path_spec)

        scan_node = source_scanner.SourceScanNode(path_spec)

        result = mediator.UnlockEncryptedVolume(source_scanner_object=None,
                                                scan_context=None,
                                                locked_scan_node=scan_node,
                                                credentials=None)
        self.assertFalse(result)
Esempio n. 6
0
    def testTypeIndicator(self):
        """Test the type_indicator property."""
        test_fake_path_spec = fake_path_spec.FakePathSpec(location='/')
        test_node = source_scanner.SourceScanNode(test_fake_path_spec)

        self.assertEqual(test_node.type_indicator,
                         definitions.TYPE_INDICATOR_FAKE)
Esempio n. 7
0
  def testGetUnscannedSubNode(self):
    """Test the GetUnscannedSubNode function."""
    test_fake_path_spec = fake_path_spec.FakePathSpec(location='/')
    test_node = source_scanner.SourceScanNode(test_fake_path_spec)

    sub_node = test_node.GetUnscannedSubNode()
    self.assertIsNotNone(sub_node)
Esempio n. 8
0
    def testScanFileSystem(self):
        """Tests the _ScanFileSystem function."""
        test_scanner = volume_scanner.VolumeScanner()

        path_spec = fake_path_spec.FakePathSpec(location=u'/')
        scan_node = source_scanner.SourceScanNode(path_spec)

        base_path_specs = []
        test_scanner._ScanFileSystem(scan_node, base_path_specs)
        self.assertEqual(len(base_path_specs), 1)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanFileSystem(None, [])

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanFileSystem(scan_node, [])
Esempio n. 9
0
    def testGetTSKPartitionIdentifiers(self):
        """Tests the _GetTSKPartitionIdentifiers function."""
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(mediator=test_mediator)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetTSKPartitionIdentifiers(None)

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetTSKPartitionIdentifiers(scan_node)
Esempio n. 10
0
  def testScanVolume(self):
    """Tests the _ScanVolume function."""
    test_tool = storage_media_tool.StorageMediaTool()

    scan_context = source_scanner.SourceScannerContext()

    # Test error conditions.
    with self.assertRaises(errors.SourceScannerError):
      test_tool._ScanVolume(scan_context, None, [])

    scan_node = source_scanner.SourceScanNode(None)
    with self.assertRaises(errors.SourceScannerError):
      test_tool._ScanVolume(scan_context, scan_node, [])
Esempio n. 11
0
    def testScanEncryptedVolume(self):
        """Tests the _ScanEncryptedVolume function."""
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(mediator=test_mediator)

        scan_context = source_scanner.SourceScannerContext()

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanEncryptedVolume(scan_context, None)

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanEncryptedVolume(scan_context, scan_node)
Esempio n. 12
0
    def testScanFileSystem(self):
        """Tests the _ScanFileSystem function."""
        test_scanner = volume_scanner.WindowsVolumeScanner()

        test_file = self._GetTestFilePath([u'windows_volume.qcow2'])
        test_os_path_spec = os_path_spec.OSPathSpec(location=test_file)
        test_qcow_path_spec = qcow_path_spec.QCOWPathSpec(
            parent=test_os_path_spec)
        test_tsk_path_spec = tsk_path_spec.TSKPathSpec(
            location=u'/', parent=test_qcow_path_spec)
        scan_node = source_scanner.SourceScanNode(test_tsk_path_spec)

        base_path_specs = []
        test_scanner._ScanFileSystem(scan_node, base_path_specs)
        self.assertEqual(len(base_path_specs), 1)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanFileSystem(None, [])

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanFileSystem(scan_node, [])
Esempio n. 13
0
  def testScanVolumeSystemRoot(self):
    """Tests the _ScanVolumeSystemRoot function."""
    test_scanner = storage_media_tool.StorageMediaToolVolumeScanner()

    options = storage_media_tool.StorageMediaToolVolumeScannerOptions()
    options.scan_mode = options.SCAN_MODE_ALL

    scan_context = source_scanner.SourceScannerContext()

    # Test error conditions.
    with self.assertRaises(dfvfs_errors.ScannerError):
      test_scanner._ScanVolumeSystemRoot(scan_context, None, options, [])

    scan_node = source_scanner.SourceScanNode(None)
    with self.assertRaises(dfvfs_errors.ScannerError):
      test_scanner._ScanVolumeSystemRoot(scan_context, scan_node, options, [])
Esempio n. 14
0
    def testScanVolumeSystemRoot(self):
        """Tests the _ScanVolumeSystemRoot function."""
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(mediator=test_mediator)
        test_options = volume_scanner.VolumeScannerOptions()

        scan_context = source_scanner.SourceScannerContext()

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeSystemRoot(scan_context, None,
                                               test_options, [])

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeSystemRoot(scan_context, scan_node,
                                               test_options, [])
Esempio n. 15
0
    def testGetVSSStoreIdentifiers(self):
        """Tests the _GetVSSStoreIdentifiers function."""
        # Test with mediator.
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(mediator=test_mediator)
        test_options = volume_scanner.VolumeScannerOptions()

        test_path = self._GetTestFilePath(['vsstest.qcow2'])
        self._SkipIfPathNotExists(test_path)

        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_path)

        test_scanner._source_scanner.Scan(scan_context)
        scan_node = self._GetTestScanNode(scan_context)

        identifiers = test_scanner._GetVSSStoreIdentifiers(
            scan_node.sub_nodes[0], test_options)
        self.assertEqual(len(identifiers), 2)
        self.assertEqual(identifiers, ['vss1', 'vss2'])

        # Test without mediator.
        test_scanner = volume_scanner.VolumeScanner()
        test_options = volume_scanner.VolumeScannerOptions()

        test_path = self._GetTestFilePath(['vsstest.qcow2'])
        self._SkipIfPathNotExists(test_path)

        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_path)

        test_scanner._source_scanner.Scan(scan_context)
        scan_node = self._GetTestScanNode(scan_context)

        with self.assertRaises(errors.ScannerError):
            test_scanner._GetVSSStoreIdentifiers(scan_node.sub_nodes[0],
                                                 test_options)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetVSSStoreIdentifiers(None, test_options)

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetVSSStoreIdentifiers(scan_node, test_options)
Esempio n. 16
0
    def testGetTSKPartitionIdentifiers(self):
        """Tests the _GetTSKPartitionIdentifiers function."""
        # Test with mediator.
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(test_mediator)

        test_file = self._GetTestFilePath([u'tsk_volume_system.raw'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        scan_node = self._GetTestScanNode(scan_context)

        expected_identifiers = sorted([u'p1', u'p2'])
        identifiers = test_scanner._GetTSKPartitionIdentifiers(scan_node)
        self.assertEqual(len(identifiers), 2)
        self.assertEqual(sorted(identifiers), expected_identifiers)

        # Test without mediator.
        test_scanner = volume_scanner.VolumeScanner()

        test_file = self._GetTestFilePath([u'tsk_volume_system.raw'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        scan_node = self._GetTestScanNode(scan_context)

        expected_identifiers = sorted([u'p1', u'p2'])
        identifiers = test_scanner._GetTSKPartitionIdentifiers(scan_node)
        self.assertEqual(len(identifiers), 2)
        self.assertEqual(sorted(identifiers), expected_identifiers)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetTSKPartitionIdentifiers(None)

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetTSKPartitionIdentifiers(scan_node)
Esempio n. 17
0
    def testGetVSSStoreIdentifiers(self):
        """Tests the _GetVSSStoreIdentifiers function."""
        # Test with mediator.
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(test_mediator)

        test_file = self._GetTestFilePath(['vsstest.qcow2'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        scan_node = self._GetTestScanNode(scan_context)

        expected_identifiers = sorted([1, 2])
        identifiers = test_scanner._GetVSSStoreIdentifiers(
            scan_node.sub_nodes[0])
        self.assertEqual(len(identifiers), 2)
        self.assertEqual(sorted(identifiers), expected_identifiers)

        # Test without mediator.
        test_scanner = volume_scanner.VolumeScanner()

        test_file = self._GetTestFilePath(['vsstest.qcow2'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        scan_node = self._GetTestScanNode(scan_context)

        with self.assertRaises(errors.ScannerError):
            test_scanner._GetVSSStoreIdentifiers(scan_node.sub_nodes[0])

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetVSSStoreIdentifiers(None)

        scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._GetVSSStoreIdentifiers(scan_node)
Esempio n. 18
0
    def testScanVolumeScanNodeVSS(self):
        """Tests the _ScanVolumeScanNodeVSS function."""
        test_mediator = TestVolumeScannerMediator()
        test_scanner = volume_scanner.VolumeScanner(test_mediator)

        # Test root.
        test_file = self._GetTestFilePath([u'vsstest.qcow2'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        volume_scan_node = scan_context.GetRootScanNode()

        base_path_specs = []
        test_scanner._ScanVolumeScanNodeVSS(volume_scan_node, base_path_specs)
        self.assertEqual(len(base_path_specs), 0)

        # Test VSS volume.
        test_file = self._GetTestFilePath([u'vsstest.qcow2'])
        scan_context = source_scanner.SourceScannerContext()
        scan_context.OpenSourcePath(test_file)

        test_scanner._source_scanner.Scan(scan_context)
        volume_scan_node = self._GetTestScanNode(scan_context)

        base_path_specs = []
        test_scanner._ScanVolumeScanNodeVSS(volume_scan_node.sub_nodes[0],
                                            base_path_specs)
        self.assertEqual(len(base_path_specs), 2)

        # Test error conditions.
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeScanNodeVSS(None, [])

        volume_scan_node = source_scanner.SourceScanNode(None)
        with self.assertRaises(errors.ScannerError):
            test_scanner._ScanVolumeScanNodeVSS(volume_scan_node, [])
Esempio n. 19
0
  def testSupportsEncryption(self):
    """Test the SupportsEncryption function."""
    test_fake_path_spec = fake_path_spec.FakePathSpec(location='/')
    test_node = source_scanner.SourceScanNode(test_fake_path_spec)

    self.assertFalse(test_node.SupportsEncryption())
Esempio n. 20
0
  def testIsSystemLevel(self):
    """Test the IsSystemLevel function."""
    test_fake_path_spec = fake_path_spec.FakePathSpec(location='/')
    test_node = source_scanner.SourceScanNode(test_fake_path_spec)

    self.assertTrue(test_node.IsSystemLevel())