Sha256: c0caa73d6ce9cc9a9741d5ae5ecae844b7eac60a9f369c889b582fd8a2e08638

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "parallel"

module Mihari
  module Analyzers
    class SSHFingerprint < Base
      attr_reader :fingerprint, :title, :description, :tags

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

        @fingerprint = fingerprint

        @title = title || "SSH fingerprint cross search"
        @description = description || "fingerprint = #{fingerprint}"
        @tags = tags
      end

      def artifacts
        Parallel.map(analyzers) do |analyzer|
          run_analyzer analyzer
        end.flatten
      end

      private

      def valid_fingerprint?
        /^([0-9a-f]{2}:){15}[0-9a-f]{2}$/.match? fingerprint
      end

      def binary_edge
        BinaryEdge.new "ssh.fingerprint:\"#{fingerprint}\""
      end

      def shodan
        Shodan.new fingerprint
      end

      def analyzers
        raise InvalidInputError, "Invalid fingerprint is given." unless valid_fingerprint?

        [
          binary_edge,
          shodan
        ].compact
      end

      def run_analyzer(analyzer)
        analyzer.artifacts
      rescue ArgumentError, InvalidInputError => _e
        nil
      rescue ::BinaryEdge::Error, ::Shodan::Error => _e
        nil
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mihari-2.4.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-2.3.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-2.3.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-2.2.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-2.2.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-2.1.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-2.0.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.5.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.5.0 lib/mihari/analyzers/ssh_fingerprint.rb