Sha256: a37fae1baa17198197e6ff4dac16a0d108eb3bcb90160aa17c2410ae231070f5

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require "otx_ruby"

module Mihari
  module Analyzers
    class OTX < Base
      attr_reader :query, :type, :title, :description, :tags

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

        @query = query
        @type = TypeChecker.type(query)

        @title = title || "OTX lookup"
        @description = description || "query = #{query}"
        @tags = tags
      end

      def artifacts
        lookup || []
      end

      private

      def config_keys
        %w[otx_api_key]
      end

      def domain_client
        @domain_client ||= ::OTX::Domain.new(Mihari.config.otx_api_key)
      end

      def ip_client
        @ip_client ||= ::OTX::IP.new(Mihari.config.otx_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, "#{query}(type: #{type || "unknown"}) is not supported." unless valid_type?
        end
      end

      def domain_lookup
        records = domain_client.get_passive_dns(query)
        records.map do |record|
          record.address if record.record_type == "A"
        end.compact.uniq
      end

      def ip_lookup
        records = ip_client.get_passive_dns(query)
        records.map do |record|
          record.hostname if record.record_type == "A"
        end.compact.uniq
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mihari-2.4.0 lib/mihari/analyzers/otx.rb
mihari-2.3.1 lib/mihari/analyzers/otx.rb
mihari-2.3.0 lib/mihari/analyzers/otx.rb
mihari-2.2.1 lib/mihari/analyzers/otx.rb
mihari-2.2.0 lib/mihari/analyzers/otx.rb
mihari-2.1.0 lib/mihari/analyzers/otx.rb
mihari-2.0.0 lib/mihari/analyzers/otx.rb
mihari-1.5.1 lib/mihari/analyzers/otx.rb
mihari-1.5.0 lib/mihari/analyzers/otx.rb