Class | HostMap::Discovery::HostDiscovery::HostMapping |
In: |
lib/discovery/host.rb
|
Parent: | Object |
Host Mapping
# File lib/discovery/host.rb, line 30 def initialize(engine) self.engine = engine # Initialize the target model @host = Host.new(self.engine.opts['target']) # Initialize the resolver used for results check if self.engine.opts['dns'] dns = self.engine.opts['dns'].gsub(/\s/, '').split(',') @resolver = Net::DNS::Resolver.new(:nameserver => dns) else @resolver = Net::DNS::Resolver.new end end
Report a job result from a running plugin
# File lib/discovery/host.rb, line 61 def report(results) results.each do |res| res.each do |key, value| case key when :hostname then self.report_hostname(value) when :domain then self.report_domain(value) when :mx then self.report_mx(value) when :ns then self.report_ns(value) end end end end
Runs the hostmapping.
# File lib/discovery/host.rb, line 46 def run self.engine.plugins.start(:ip, @host.ip, proc {stop}) end
Stops the hostmapping and prints results.
# File lib/discovery/host.rb, line 53 def stop puts "\n" puts @host.to_txt end
Checks if an hostname match host ip via dns resolution.
# File lib/discovery/host.rb, line 197 def check_host(name) @resolver.query(name).answer.each do |rr| # TODO: add this and report without check_host #if rr.type == Net::DNS::RR::CNAME # check_host(rr.cname.gsub(/.$/, '')) #end if rr.class == Net::DNS::RR::A if rr.address==IPAddr.new(self.engine.opts['target']) return true end end end return false end
Report a found domain
# File lib/discovery/host.rb, line 117 def report_domain(name) # Sanitize begin name = HostMap::Utils.sanitize_fqdn(name) rescue HostMap::Exception::EnumerationError return end # Skip if already present if @host.domains.include?(name) return end $LOG.info "Found new domain #{name}" @host.domains << name # Check if the enumerated domain is also a virtual host report_hostname(name) # Run plugins self.engine.plugins.run_domain(name) end
Report a found hostname
# File lib/discovery/host.rb, line 79 def report_hostname(name) # Sanitize begin name = HostMap::Utils.sanitize_fqdn(name) rescue HostMap::Exception::EnumerationError return end # Skip if already present if @host.alias.include?(name) return end # Checks the enumerated result if self.engine.opts['paranoid'] if check_host(name) @host.alias << name else return end else @host.alias << name end $LOG.info "Found new hostname #{name}" # Report the domain too domain = HostMap::Utils.parse_domain(name) report_domain(domain) # Run plugins self.engine.plugins.run_hostname(name) end
Report a found mail server
# File lib/discovery/host.rb, line 171 def report_mx(name) # Sanitize begin name = HostMap::Utils.sanitize_fqdn(name) rescue HostMap::Exception::EnumerationError return end # Skip if already present if @host.mx.include?(name) return end $LOG.info "Found new mail server #{name}" @host.mx << name # Check if the mail server is runned by the target ip address report_hostname(name) end
Report a found nameserver
# File lib/discovery/host.rb, line 144 def report_ns(name) # Sanitize begin name = HostMap::Utils.sanitize_fqdn(name) rescue HostMap::Exception::EnumerationError return end # Skip if already present if @host.ns.include?(name) return end $LOG.info "Found new nameserver #{name}" @host.ns << name # Check if the nameserver is runned by the target ip address report_hostname(name) # Run plugins self.engine.plugins.run_ns(name) end