Sha256: e216d2022cdbe4d6747ef67d947097be3cd4e35d1afc4abedbf7d656e6aee8b1

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    class VirusTotalIntelligence < Base
      # @return [String, nil]
      attr_reader :api_key

      #
      # @param [String] query
      # @param [Hash, nll] options
      # @param [String, nil] api_key
      #
      def initialize(query, options: nil, api_key: nil)
        super(query, options: options)

        @api_key = api_key || Mihari.config.virustotal_api_key
      end

      def artifacts
        search_with_cursor.map(&:to_artifacts).flatten
      end

      private

      def configuration_keys
        %w[virustotal_api_key]
      end

      #
      # VT API
      #
      # @return [::VirusTotal::API]
      #
      def client
        @client = Clients::VirusTotal.new(api_key: api_key)
      end

      #
      # Search with cursor
      #
      # @return [Array<Structs::VirusTotalIntelligence::Response>]
      #
      def search_with_cursor
        cursor = nil
        responses = []

        loop do
          response = Structs::VirusTotalIntelligence::Response.from_dynamic!(client.intel_search(query,
            cursor: cursor))
          responses << response
          break if response.meta.cursor.nil?

          cursor = response.meta.cursor
          # sleep #{interval} seconds to avoid the rate limitation (if it is set)
          sleep_interval
        end

        responses
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mihari-5.3.2 lib/mihari/analyzers/virustotal_intelligence.rb