class SSHScan::SshFp

Constants

ALGO_MAP
FPTYPE_MAP

Public Instance Methods

query(fqdn) click to toggle source
# File lib/ssh_scan/ssh_fp.rb, line 22
def query(fqdn)
  sshfp_records = []

  # try up to 5 times to resolve ssh_fp's
  5.times do

    # Reference: https://stackoverflow.com/questions/28867626/how-to-use-resolvdnsresourcegeneric
    # Note: this includes some fixes too, I'll post a direct link back to the SO article.
    Resolv::DNS.open do |dns|
       all_records = dns.getresources(fqdn, Resolv::DNS::Resource::IN::ANY ) rescue nil
       all_records.each do |rr|
          if rr.is_a? Resolv::DNS::Resource::Generic then
             classname = rr.class.name.split('::').last
             if classname == "Type44_Class1"
               data = rr.data.bytes
               algo = data[0].to_s
               fptype = data[1].to_s
               fp = data[2..-1]
               hex = fp.map{|b| b.to_s(16).rjust(2,'0') }.join(':')
               sshfp_records << {"fptype" => FPTYPE_MAP[fptype.to_i], "algo" => ALGO_MAP[algo.to_i], "hex" => hex}
             end
          end
       end
    end

    if sshfp_records.any?
      return sshfp_records.sort_by { |k| k["hex"] }
    end

    sleep 0.5
  end 

  return sshfp_records
end