Sha256: 9abab7f7dc5b85e3618fff72fcc003d06341b27031bcc3ed5842acbf0be6041f

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    #
    # CIRCL passive DNS/SSL analyzer
    #
    class CIRCL < Base
      include Mixins::Refang

      # @return [String, nil]
      attr_reader :type

      # @return [String, nil]
      attr_reader :username

      # @return [String, nil]
      attr_reader :password

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

        @type = DataType.type(query)

        @username = username || Mihari.config.circl_passive_username
        @password = password || Mihari.config.circl_passive_password
      end

      def artifacts
        case type
        when "domain"
          client.passive_dns_search query
        when "hash"
          client.passive_ssl_search query
        else
          raise ValueError, "#{@query}(type: #{@type || "unknown"}) is not supported."
        end
      end

      def configured?
        configuration_keys? || (username? && password?)
      end

      def configuration_keys
        %w[circl_passive_password circl_passive_username]
      end

      private

      def client
        Clients::CIRCL.new(username: username, password: password, timeout: timeout)
      end

      def username?
        !username.nil?
      end

      def password?
        !password.nil?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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