Sha256: 7e2f3725638546c0e6163ef7d5deee54f1146b6a2dc5a8268c06496a1d0675e0

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    class Base
      attr_reader :the_hive

      def initialize
        @the_hive = TheHive.new
      end

      # @return [Array<String>, Array<Mihari::Artifact>]
      def artifacts
        raise NotImplementedError, "You must implement #{self.class}##{__method__}"
      end

      # @return [String]
      def title
        self.class.to_s.split("::").last
      end

      # @return [String]
      def description
        raise NotImplementedError, "You must implement #{self.class}##{__method__}"
      end

      # @return [Array<String>]
      def tags
        []
      end

      def run
        Mihari.emitters.each do |emitter_class|
          emitter = emitter_class.new
          next unless emitter.valid?

          run_emitter emitter
        end
      end

      def run_emitter(emitter)
        emitter.emit(title: title, description: description, artifacts: unique_artifacts, tags: tags)
      rescue StandardError => e
        puts "Emission by #{emitter.class} is failed: #{e}"
      end

      private

      # @return [Array<Mihari::Artifact>]
      def normalized_artifacts
        @normalized_artifacts ||= artifacts.map do |artifact|
          artifact.is_a?(Artifact) ? artifact : Artifact.new(artifact)
        end.select(&:valid?)
      end

      # @return [Array<Mihari::Artifact>]
      def unique_artifacts
        return normalized_artifacts unless the_hive.valid?

        the_hive.artifact.find_non_existing_artifacts(normalized_artifacts)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mihari-0.8.0 lib/mihari/analyzers/base.rb
mihari-0.7.0 lib/mihari/analyzers/base.rb
mihari-0.6.0 lib/mihari/analyzers/base.rb
mihari-0.5.2 lib/mihari/analyzers/base.rb
mihari-0.5.1 lib/mihari/analyzers/base.rb