Sha256: cb59dee8c5bc075958dca465e56b110dfbdef2a523d728e6c6d6330534e3d84e

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require "passive_circl"

module Mihari
  module Analyzers
    class CIRCL < Base
      attr_reader :title
      attr_reader :description
      attr_reader :tags

      def initialize(query, title: nil, description: nil, tags: [])
        super()

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

        @title = title || "CIRCL passive lookup"
        @description = description || "query = #{query}"
        @tags = tags
      end

      def artifacts
        lookup || []
      end

      private

      def config_keys
        %w(CIRCL_PASSIVE_USERNAME CIRCL_PASSIVE_PASSWORD)
      end

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

      def lookup
        case @type
        when "domain"
          passive_dns_lookup
        when "hash"
          passive_ssl_lookup
        else
          raise InvalidInputError, "#{@query}(type: #{@type || 'unknown'}) is not supported."
        end
      end

      def passive_dns_lookup
        results = api.dns.query(@query)
        results.map do |result|
          type = result.dig("rrtype")
          type == "A" ? result.dig("rdata") : nil
        end.compact.uniq
      end

      def passive_ssl_lookup
        result = api.ssl.cquery(@query)
        seen = result.dig("seen") || []
        seen.uniq
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mihari-0.17.5 lib/mihari/analyzers/circl.rb
mihari-0.17.4 lib/mihari/analyzers/circl.rb
mihari-0.17.3 lib/mihari/analyzers/circl.rb
mihari-0.17.2 lib/mihari/analyzers/circl.rb
mihari-0.17.1 lib/mihari/analyzers/circl.rb