Sha256: abc54ca09e4b5f06f4e17ed9b344baeab0911f9299a094b028f3b5d2dad89386

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    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 = TypeChecker.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
        @client ||= Clients::CIRCL.new(username: username, password: password)
      end

      def username?
        !username.nil?
      end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mihari-5.6.0 lib/mihari/analyzers/circl.rb
mihari-5.5.0 lib/mihari/analyzers/circl.rb
mihari-5.4.9 lib/mihari/analyzers/circl.rb
mihari-5.4.8 lib/mihari/analyzers/circl.rb
mihari-5.4.7 lib/mihari/analyzers/circl.rb
mihari-5.4.6 lib/mihari/analyzers/circl.rb
mihari-5.4.5 lib/mihari/analyzers/circl.rb
mihari-5.4.4 lib/mihari/analyzers/circl.rb