Sha256: 2bbfd2a806d9f8c1d898549b08aed17468b91842591047198ba43963bc445a2a

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require "virustotal"

module Mihari
  module Analyzers
    class VirusTotal < Base
      attr_reader :indicator
      attr_reader :type

      attr_reader :title
      attr_reader :description
      attr_reader :tags

      def initialize(indicator, title: nil, description: nil, tags: [])
        super()

        @indicator = indicator
        @type = TypeChecker.type(indicator)

        @title = title || "VirusTotal lookup"
        @description = description || "indicator = #{indicator}"
        @tags = tags
      end

      def artifacts
        lookup || []
      end

      private

      def config_keys
        %w(virustotal_api_key)
      end

      def api
        @api = ::VirusTotal::API.new(key: Mihari.config.virustotal_api_key)
      end

      def valid_type?
        %w(ip domain).include? type
      end

      def lookup
        case type
        when "domain"
          domain_lookup
        when "ip"
          ip_lookup
        else
          raise InvalidInputError, "#{indicator}(type: #{type || 'unknown'}) is not supported." unless valid_type?
        end
      end

      def domain_lookup
        res = api.domain.resolutions(indicator)

        data = res.dig("data") || []
        data.map do |item|
          item.dig("attributes", "ip_address")
        end.compact.uniq
      end

      def ip_lookup
        res = api.ip_address.resolutions(indicator)

        data = res.dig("data") || []
        data.map do |item|
          item.dig("attributes", "host_name")
        end.compact.uniq
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mihari-1.4.1 lib/mihari/analyzers/virustotal.rb
mihari-1.4.0 lib/mihari/analyzers/virustotal.rb
mihari-1.3.2 lib/mihari/analyzers/virustotal.rb
mihari-1.3.1 lib/mihari/analyzers/virustotal.rb
mihari-1.3.0 lib/mihari/analyzers/virustotal.rb
mihari-1.2.1 lib/mihari/analyzers/virustotal.rb
mihari-1.2.0 lib/mihari/analyzers/virustotal.rb
mihari-1.1.1 lib/mihari/analyzers/virustotal.rb
mihari-1.1.0 lib/mihari/analyzers/virustotal.rb