Sha256: 6ce9ae84b0a9bbdf2d22aeb404dd14d93f6462d83734335d653914d34b69f97f

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "parallel"

module Mihari
  module Analyzers
    class SSHFingerprint < Base
      attr_reader :fingerprint

      attr_reader :title
      attr_reader :description
      attr_reader :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

19 entries across 19 versions & 1 rubygems

Version Path
mihari-1.4.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.4.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.3.2 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.3.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.3.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.2.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.2.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.1.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.1.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.0.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-1.0.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.17.5 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.17.4 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.17.3 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.17.2 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.17.1 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.17.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.16.0 lib/mihari/analyzers/ssh_fingerprint.rb
mihari-0.15.0 lib/mihari/analyzers/ssh_fingerprint.rb