コード例 #1
0
    def set_filetype(self, fname=None, ftype=None):
        """
        Calls the filetype functions and loops through the category
        plug-ins to see which ones will handle this file.
        """

        log = logging.getLogger('Mastiff.FileType')

        if fname is None and self.file_name is None:
            log.error("No file to analyze has been specified. Exiting.")
            sys.exit(1)
        elif fname is not None and self.file_name is None:
            if self.init_file(fname) is None:
                log.error("ERROR accessing file. Exiting.")
                sys.exit(1)

        if self.cat_list:
            # if self.cat_list is already set, assume that we've already
            # gone through this function
            return self.filetype

        if ftype is not None:
            # we are forcing a file type to run
            log.info('Forcing category plug-in "%s" to be added.', ftype)
            self.cat_list.append(ftype)

        # Grab the magic file type of the file. This is done here so as not
        # to do it in every category plug-in.
        self.filetype['magic'] = FileType.get_magic(self.file_name)

        # Grab the TrID type
        trid_opts = self.config.get_section('File ID')
        self.filetype['trid'] = list()
        if trid_opts['trid']:
            self.filetype['trid'] = FileType.get_trid(self.file_name,
                                                      trid_opts['trid'],
                                                      trid_opts['trid_db'])

        # Cycle through all of the categories and see if they should be added
        # to the list of categories to be run.
        for pluginInfo in self.cat_manager.getAllPlugins():
            cat_name = pluginInfo.plugin_object.is_my_filetype(
                self.filetype, self.file_name)
            log.debug('Checking cat %s for filetype.', pluginInfo.name)
            if cat_name is not None:
                # cat_list contains analysis plugin categories to be used
                self.cat_list.append(cat_name)
                log.debug('Adding %s to plugin selection list.', cat_name)

        # add file type to the DB
        if self.db is not None:
            DB.insert_mastiff_item(self.db, self.hashes, self.cat_list)

        return self.filetype
コード例 #2
0
ファイル: core.py プロジェクト: 7h3rAm/mastiff
    def set_filetype(self, fname=None, ftype=None):
        """
        Calls the filetype functions and loops through the category
        plug-ins to see which ones will handle this file.
        """

        log = logging.getLogger('Mastiff.FileType')

        if fname is None and self.file_name is None:
            log.error("No file to analyze has been specified. Exiting.")
            sys.exit(1)
        elif fname is not None and self.file_name is None:
            if self.init_file(fname) is None:
                log.error("ERROR accessing file. Exiting.")
                sys.exit(1)

        if self.cat_list:
            # if self.cat_list is already set, assume that we've already
            # gone through this function
            return self.filetype

        if ftype is not None:
            # we are forcing a file type to run
            log.info('Forcing category plug-in "%s" to be added.', ftype)
            self.cat_list.append(ftype)

        # Grab the magic file type of the file.
        self.filetype['magic'] = FileType.get_magic(self.file_name)

        # Grab the TrID type
        trid_opts = self.config.get_section('File ID')
        self.filetype['trid'] = FileType.get_trid(self.file_name,
                                                  trid_opts['trid'],
                                                  trid_opts['trid_db'])

        # Cycle through all of the categories and see if they should be added
        # to the list of categories to be run.
        for pluginInfo in self.cat_manager.getAllPlugins():
            cat_name = pluginInfo.plugin_object.is_my_filetype(self.filetype,
                                                               self.file_name)
            log.debug('Checking cat %s for filetype.', pluginInfo.name)
            if cat_name is not None:
                # cat_list contains analysis plugin categories to be used
                self.cat_list.append(cat_name)
                log.debug('Adding %s to plugin selection list.', cat_name)

        # add file type to the DB
        if self.db is not None:
            DB.insert_mastiff_item(self.db,  self.hashes, self.cat_list)


        return self.filetype
コード例 #3
0
        # copy file to the log directory
        if self.config.get_bvar('Misc', 'copy') is True:
            try:
                copyfile(
                    self.file_name, log_dir + os.sep +
                    os.path.basename(self.file_name) + '.VIR')
            except IOError, err:
                log.error('Unable to copy file: %s', err)
            log.debug('Copied file to log directory.')
        else:
            log.debug('Configuration set to not copy file.')

        # add entry to database if it exists
        if self.db is not None:
            log.debug('Adding entry to database.')
            DB.insert_mastiff_item(self.db, self.hashes)

        return self.hashes

    def activate_plugins(self, single_plugin=None):
        """
           Activate all plugins that are in the categories we selected.
           If single_plugin is given, only activate that plug-in.
           Note: File Information plug-in is ALWAYS run.
        """

        has_prereq = list()

        for cats in self.cat_list:

            log = logging.getLogger('Mastiff.Plugins.Activate')
コード例 #4
0
ファイル: core.py プロジェクト: 7h3rAm/mastiff
        log.info("Log Directory: %s", log_dir)

        # copy file to the log directory
        if self.config.get_bvar('Misc', 'copy') is True:
            try:
                copyfile(self.file_name, log_dir + os.sep + os.path.basename(self.file_name) + '.VIR')
            except IOError, err:
                log.error('Unable to copy file: %s', err)
            log.debug('Copied file to log directory.')
        else:
            log.debug('Configuration set to not copy file.')

        # add entry to database if it exists
        if self.db is not None:
            log.debug('Adding entry to database.')
            DB.insert_mastiff_item(self.db,  self.hashes)

        return self.hashes

    def activate_plugins(self,  single_plugin=None):
        """
           Activate all plugins that are in the categories we selected.
           If single_plugin is given, only activate that plug-in.
        """

        has_prereq = list()

        for cats in self.cat_list:

            log = logging.getLogger('Mastiff.Plugins.Activate')
            log.debug('Activating plugins for category %s.', cats)