Sha256: e0da802f50b17af138c7f84ca3c1250ba3f44581dc6f1de938be181f8df51326

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

require "ssh_scan"

module Apullo
  module Fingerprint
    class SSH < Base
      DEFAULT_OPTIONS = { "timeout" => 3 }.freeze
      DEFAULT_PORT = 22

      def results
        @results ||= pluck
      end

      private

      def pluck
        result = scan
        keys = result.dig("keys") || []
        keys.map do |cipher, data|
          fingerprints = data.dig("fingerprints") || []
          normalized = fingerprints.map do |hash, value|
            [hash, value.delete(":")]
          end.to_h
          [cipher, normalized]
        end.to_h
      end

      def scan
        return {} unless target.ipv4

        engine = SSHScan::ScanEngine.new
        dest = "#{target.host}:#{DEFAULT_PORT}"
        result = engine.scan_target(dest, DEFAULT_OPTIONS)
        result.to_hash
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apullo-0.1.3 lib/apullo/fingerprints/ssh.rb
apullo-0.1.2 lib/apullo/fingerprints/ssh.rb
apullo-0.1.1 lib/apullo/fingerprints/ssh.rb
apullo-0.1.0 lib/apullo/fingerprints/ssh.rb