Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/util/host.rb
Views: 11780
# -*- coding: binary -*-12module Msf3module Util4module Host56#7# Returns something suitable for the +:host+ parameter to the various report_* methods8#9# Takes a Host object, a Session object, an Msf::Session object or a String10# address11#12def self.normalize_host(host)13return host if defined?(::Mdm) && host.kind_of?(::Mdm::Host)14norm_host = nil1516if host.kind_of?(String)17if Rex::Socket.is_ipv4?(host)18norm_host = host19elsif Rex::Socket.is_ipv6?(host)20# If it's an IPv6 addr, drop the zone_id21address, _ = host.split('%', 2)22norm_host = address23else24begin25norm_host = Rex::Socket.getaddress(host, true)26rescue SocketError27end28end29elsif defined?(::Mdm) && host.kind_of?(::Mdm::Session)30norm_host = host.host31elsif host.respond_to?(:session_host)32# Then it's an Msf::Session object33norm_host = host.session_host34end3536# If we got here and don't have a norm_host yet, it could be a37# Msf::Session object with an empty or nil tunnel_host and tunnel_peer;38# see if it has a socket and use its peerhost if so.39if (40norm_host.nil? &&41host.respond_to?(:sock) &&42host.sock.respond_to?(:peerhost) &&43host.sock.peerhost.to_s.length > 044)45norm_host = session.sock.peerhost46end47# If We got here and still don't have a real host, there's nothing left48# to try, just log it and return what we were given49if !norm_host50dlog("Host could not be normalized: #{host.inspect}")51end5253norm_host54end55end56end57end585960