示例#1
0
    def testMemoryImageLiteralMatchFilterWithSendToSocketAction(self):
        literal_filter = rdfvalue.MemoryScannerFilter(
            filter_type=rdfvalue.MemoryScannerFilter.Type.LITERAL_MATCH,
            literal_match=rdfvalue.FileFinderContentsLiteralMatchFilter(
                mode=rdfvalue.FileFinderContentsLiteralMatchFilter.Mode.
                ALL_HITS,
                literal="session opened for user dearjohn"))
        dump_option = rdfvalue.MemoryScannerDumpOption(
            option_type=rdfvalue.MemoryScannerDumpOption.Option.
            WITH_LOCAL_COPY,
            with_local_copy=rdfvalue.MemoryScannerWithLocalCopyDumpOption(
                gzip=False))
        flow_urn, encrypted, decrypted = self.RunWithSendToSocket(
            dump_option, filters=[literal_filter])

        # Check that matches are in the collection
        output = aff4.FACTORY.Open(self.client_id.Add(self.output_path),
                                   aff4_type="RDFValueCollection",
                                   token=self.token)
        self.assertEqual(len(output), 1)
        self.assertEqual(output[0].offset, 350)
        self.assertEqual(output[0].length, 52)
        self.assertEqual(
            output[0].data, "session): session opened for user "
            "dearjohn by (uid=0")

        flow_obj = aff4.FACTORY.Open(flow_urn, token=self.token)
        # There was a local file, so dest_path should not be empty
        self.assertTrue(flow_obj.state.memory_src_path is not None)

        # Data should be encrypted, so they're not equal
        self.assertNotEqual(encrypted, self.memory_dump)
        # Decrypted data should be equal to the memory dump
        self.assertEqual(decrypted, self.memory_dump)
示例#2
0
    def testMemoryImageRegexMatchFilterWithNoAction(self):
        regex_filter = rdfvalue.MemoryScannerFilter(
            filter_type=rdfvalue.MemoryScannerFilter.Type.REGEX_MATCH,
            regex_match=rdfvalue.FileFinderContentsRegexMatchFilter(
                mode=rdfvalue.FileFinderContentsLiteralMatchFilter.Mode.
                ALL_HITS,
                regex="session opened for user .*?john"))

        self.RunWithNoAction(filters=[regex_filter])

        output = aff4.FACTORY.Open(self.client_id.Add(self.output_path),
                                   aff4_type="RDFValueCollection",
                                   token=self.token)
        self.assertEqual(len(output), 1)
        self.assertEqual(output[0].offset, 350)
        self.assertEqual(output[0].length, 52)
        self.assertEqual(
            output[0].data, "session): session opened for user "
            "dearjohn by (uid=0")
示例#3
0
    def testDoesNothingWhenFilterDoesNotMatch(self):
        literal_filter = rdfvalue.MemoryScannerFilter(
            filter_type=rdfvalue.MemoryScannerFilter.Type.LITERAL_MATCH,
            literal_match=rdfvalue.FileFinderContentsLiteralMatchFilter(
                mode=rdfvalue.FileFinderContentsLiteralMatchFilter.Mode.
                ALL_HITS,
                literal="session opened for user foobar"))
        dump_option = rdfvalue.MemoryScannerDumpOption(
            option_type=rdfvalue.MemoryScannerDumpOption.Option.
            WITH_LOCAL_COPY,
            with_local_copy=rdfvalue.MemoryScannerWithLocalCopyDumpOption(
                gzip=False))
        flow_obj = self.RunWithDownload(dump_option, filters=[literal_filter])

        # Check that there are no matches
        with self.assertRaises(aff4.InstantiationError):
            aff4.FACTORY.Open(self.client_id.Add(self.output_path),
                              aff4_type="RDFValueCollection",
                              token=self.token)

        # Assert nothing got downloaded
        self.assertTrue("dest_path" not in flow_obj.state)
        self.assertTrue("downloaded_file" not in flow_obj.state)
示例#4
0
    def testMemoryImageLiteralMatchFilterWithDownloadAction(self):
        literal_filter = rdfvalue.MemoryScannerFilter(
            filter_type=rdfvalue.MemoryScannerFilter.Type.LITERAL_MATCH,
            literal_match=rdfvalue.FileFinderContentsLiteralMatchFilter(
                mode=rdfvalue.FileFinderContentsLiteralMatchFilter.Mode.
                ALL_HITS,
                literal="session opened for user dearjohn"))
        dump_option = rdfvalue.MemoryScannerDumpOption(
            option_type=rdfvalue.MemoryScannerDumpOption.Option.
            WITH_LOCAL_COPY,
            with_local_copy=rdfvalue.MemoryScannerWithLocalCopyDumpOption(
                gzip=False))
        flow_obj = self.RunWithDownload(dump_option, filters=[literal_filter])

        # Check that matches are in the collection
        output = aff4.FACTORY.Open(self.client_id.Add(self.output_path),
                                   aff4_type="RDFValueCollection",
                                   token=self.token)
        # First item of the collection is the BufferReference, second is the
        # path of the downloaded
        self.assertEqual(len(output), 1)
        self.assertEqual(output[0].offset, 350)
        self.assertEqual(output[0].length, 52)
        self.assertEqual(
            output[0].data, "session): session opened for user "
            "dearjohn by (uid=0")

        self.assertTrue(flow_obj.state.memory_src_path is not None)
        self.assertEqual(
            flow_obj.state.downloaded_file,
            self.client_id.Add("fs/os").Add(
                flow_obj.state.memory_src_path.path))

        fd = aff4.FACTORY.Open(flow_obj.state.downloaded_file,
                               token=self.token)
        self.assertEqual(fd.Read(1024 * 1024), self.memory_dump)