Sha256: 5c9bb7f5d9f71ac0e37e27adb71a5ac422cfea61635fd01275e7fbd74446cfd8

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

require "ssh_scan"

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

      private

      def build_results
        pluck_fingerprints
      end

      def pluck_fingerprints
        result = scan
        keys = result.dig("keys") || []
        keys.map do |cipher, data|
          raw = data.dig("raw")
          fingerprints = data.dig("fingerprints") || []
          normalized_fingerprints = fingerprints.map do |hash, value|
            [hash, value.delete(":")]
          end.to_h
          [
            cipher,
            { raw: raw, fingerprints: normalized_fingerprints }
          ]
        end.to_h
      end

      def scan
        return {} unless target.host

        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

1 entries across 1 versions & 1 rubygems

Version Path
apullo-0.1.4 lib/apullo/fingerprints/ssh.rb