Sha256: fdfdc7eccfaf5ee92eabdc9d72d13594a9eebded1853b27438372687511f5fca

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    #
    # DNSTwister analyzer
    #
    class DNSTwister < Base
      include Mixins::Refang

      # @return [String]
      attr_reader :type

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

        @type = DataType.type(query)
      end

      def artifacts
        raise ValueError, "#{query}(type: #{type || "unknown"}) is not supported." unless valid_type?

        domains = client.fuzz(query)
        Parallel.map(domains) { |domain| resolvable?(domain) ? domain : nil }.compact
      end

      private

      #
      # Check whether a type is valid or not
      #
      # @return [Boolean]
      #
      def valid_type?
        type == "domain"
      end

      def client
        Clients::DNSTwister.new(timeout: timeout)
      end

      #
      # Check whether a domain is resolvable or not
      #
      # @param [String] domain
      #
      # @return [Boolean]
      #
      def resolvable?(domain)
        Resolv.getaddress domain
        true
      rescue Resolv::ResolvError
        false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-6.3.0 lib/mihari/analyzers/dnstwister.rb
mihari-6.2.0 lib/mihari/analyzers/dnstwister.rb