Skip to content

ScanSave

Compress and encode raw file data

Source code in strelka/src/python/strelka/scanners/scan_save.py
class ScanSave(strelka.Scanner):
    """Compress and encode raw file data"""

    def init(self):
        # Compression algorithm choices
        self.compress_data = {
            "gzip": gzip.compress,
            "bzip2": bz2.compress,
            "lzma": lzma.compress,
        }
        # JSON compatible encoding choices
        self.encode_data = {
            "base64": base64.b64encode,
            "base85": base64.b85encode,
        }

    def scan(self, data, file, options, expire_at):
        # Inputs
        encoding = options.get("encoding", "base64")
        compression = options.get("compression", "gzip")

        # Compress the data
        if compression != "none":
            # Verify the compression algorithm is available
            if compression not in self.compress_data:
                self.flags.append("save_compression_value_error")
                return

            try:
                data = self.compress_data[compression](data)
            except strelka.ScannerTimeout:
                raise
            except Exception:
                self.flags.append("save_compression_error")
                return
        self.event["compression"] = compression

        # Verify the encoding algorithm is available
        if encoding not in self.encode_data:
            self.flag.append("save_encoding_value_error")
            return
        self.event["encoding"] = encoding

        # Encode the data for JSON compatibility
        try:
            out_data = self.encode_data[encoding](data)
        except strelka.ScannerTimeout:
            raise
        except Exception:
            self.flags.append("save_encoding_error")
            return
        self.event["file"] = out_data

Features

The features of this scanner are detailed below. These features represent the capabilities and the type of analysis the scanner can perform. This may include support for Indicators of Compromise (IOC), the ability to emit files for further analysis, and the presence of extended documentation for complex analysis techniques.

Feature
Support
IOC Support
Emit Files
Extended Docs
Malware Scanner
Image Thumbnails

Tastes

Strelka's file distribution system assigns scanners to files based on 'flavors' and 'tastes'. Flavors describe the type of file, typically determined by MIME types from libmagic, matches from YARA rules, or characteristics of parent files. Tastes are the criteria used within Strelka to determine which scanners are applied to which files, with positive and negative tastes defining files to be included or excluded respectively.

Source Filetype
Include / Exclude

Scanner Fields

This section provides a list of fields that are extracted from the files processed by this scanner. These fields include the data elements that the scanner extracts from each file, representing the analytical results produced by the scanner. If the test file is missing or cannot be parsed, this section will not contain any data.

Field Name
Field Type
compression
str
elapsed
str
encoding
str
file
str
flags
list

Sample Event

Below is a sample event generated by this scanner, demonstrating the kind of output that can be expected when it processes a file. This sample is derived from a mock scan event configured in the scanner's test file. If no test file is available, this section will not display a sample event.

    test_scan_event = {
        "elapsed": 0.001,
        "file": file_contents,
        "compression": compression,
        "encoding": encoding,
        "flags": [],
    }