From 6d086a110feaa69606c004ad6c2d2128606e7b87 Mon Sep 17 00:00:00 2001 From: Jonathan Claudius Date: Thu, 16 Mar 2017 10:55:50 -0400 Subject: [PATCH] Add PTR lookup on IP-only target --- lib/ssh_scan/scan_engine.rb | 2 +- lib/string_ext.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/ssh_scan/scan_engine.rb b/lib/ssh_scan/scan_engine.rb index 1a4bda2d..ce7bd0c5 100644 --- a/lib/ssh_scan/scan_engine.rb +++ b/lib/ssh_scan/scan_engine.rb @@ -47,7 +47,7 @@ def scan_target(socket, opts) client = SSHScan::Client.new(target, port, timeout) client.connect() result = client.get_kex_result() - result[:hostname] = "" + result[:hostname] = target.resolve_ptr return result if result.include?(:error) end diff --git a/lib/string_ext.rb b/lib/string_ext.rb index 4db4022d..6584dbfb 100644 --- a/lib/string_ext.rb +++ b/lib/string_ext.rb @@ -55,7 +55,18 @@ def resolve_fqdn_as_ipv4(timeout = 3) end def resolve_fqdn - @fqdn ||= TCPSocket.gethostbyname(self)[3] + TCPSocket.gethostbyname(self)[3] + end + + def resolve_ptr(timeout = 3) + begin + Timeout::timeout(timeout) { + reversed_dns = Resolv.new.getname(self) + return reversed_dns + } + rescue Timeout::Error + return "" + end end def fqdn?