Sha256: 41a1199bf528d77d266303324784f948021f1d28352fc4efbfe3499181d7e32f

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    #
    # Fofa analyzer
    #
    class Fofa < Base
      # @return [String, nil]
      attr_reader :api_key

      # @return [String, nil]
      attr_reader :email

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

        @api_key = api_key || Mihari.config.fofa_api_key
        @email = email || Mihari.config.fofa_email
      end

      def artifacts
        client.search_with_pagination(query, pagination_limit: pagination_limit).map do |res|
          (res.results || []).map { |result| result[1] }
        end.flatten.compact
      end

      def configured?
        api_key? && email?
      end

      private

      def email?
        !email.nil?
      end

      #
      # @return [Mihari::Clients::Fofa]
      #
      def client
        Clients::Fofa.new(
          api_key: api_key,
          email: email,
          pagination_interval: pagination_interval,
          timeout: timeout
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mihari-7.3.2 lib/mihari/analyzers/fofa.rb
mihari-7.3.1 lib/mihari/analyzers/fofa.rb
mihari-7.3.0 lib/mihari/analyzers/fofa.rb
mihari-7.2.0 lib/mihari/analyzers/fofa.rb