Sha256: 0d8c979222e0539e3b4f61bff42a749506b7b6fb387a28d97ddd6420eced0c45

Contents?: true

Size: 1.38 KB

Versions: 27

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "dnstwister"

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

      param :query

      option :tags, default: proc { [] }

      attr_reader :type

      def initialize(*args, **kwargs)
        super

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

      def artifacts
        search || []
      end

      private

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

      def api
        @api ||= ::DNSTwister::API.new
      end

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

      #
      # Search
      #
      # @return [Array<String>]
      #
      def search
        raise InvalidInputError, "#{query}(type: #{type || "unknown"}) is not supported." unless valid_type?

        res = api.fuzz(query)
        fuzzy_domains = res["fuzzy_domains"] || []
        domains = fuzzy_domains.map { |domain| domain["domain"] }
        Parallel.map(domains) do |domain|
          resolvable?(domain) ? domain : nil
        end.compact
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mihari-5.1.0 lib/mihari/analyzers/dnstwister.rb
mihari-5.0.1 lib/mihari/analyzers/dnstwister.rb
mihari-5.0.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.12.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.11.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.10.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.9.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.8.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.7.4 lib/mihari/analyzers/dnstwister.rb
mihari-4.7.3 lib/mihari/analyzers/dnstwister.rb
mihari-4.7.2 lib/mihari/analyzers/dnstwister.rb
mihari-4.7.1 lib/mihari/analyzers/dnstwister.rb
mihari-4.7.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.6.1 lib/mihari/analyzers/dnstwister.rb
mihari-4.6.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.5.3 lib/mihari/analyzers/dnstwister.rb
mihari-4.5.2 lib/mihari/analyzers/dnstwister.rb
mihari-4.5.1 lib/mihari/analyzers/dnstwister.rb
mihari-4.5.0 lib/mihari/analyzers/dnstwister.rb
mihari-4.4.1 lib/mihari/analyzers/dnstwister.rb