class Apullo::Fingerprint::SSH

Constants

DEFAULT_OPTIONS
DEFAULT_PORTS

Private Instance Methods

_scan(target, port: 22) click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 39
def _scan(target, port: 22)
  return nil unless target.host

  engine = SSHScan::ScanEngine.new
  dest = "#{target.host}:#{port}"
  result = engine.scan_target(dest, DEFAULT_OPTIONS)
  result.to_hash
end
build_results() click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 17
def build_results
  results = fingerprints
  results = results.merge(meta: { links: links }) unless results.empty?
  results
end
fingerprints() click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 23
def fingerprints
  result = scan
  keys = result.dig("keys") || {}
  keys.map do |cipher, data|
    fingerprints = data.dig("fingerprints") || []
    normalized_fingerprints = fingerprints.map do |hash, value|
      [hash, value.delete(":")]
    end.to_h
    [
      cipher,
      normalized_fingerprints
    ]
  end.to_h
end
scan() click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 48
def scan
  [target].product(DEFAULT_PORTS).each do |target, port|
    result = _scan(target, port: port)
    keys = result.dig("keys") || {}
    return result unless keys.empty?
  end
  {}
end