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/modules/post/multi/gather/resolve_hosts.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Multi Gather Resolve Hosts',12'Description' => %q{13Resolves hostnames to either IPv4 or IPv6 addresses from the perspective of the remote host.14},15'License' => MSF_LICENSE,16'Author' => [ 'Ben Campbell' ],17'Platform' => %w[win python],18'SessionTypes' => [ 'meterpreter' ],19'Compat' => {20'Meterpreter' => {21'Commands' => %w[22stdapi_net_resolve_hosts23]24}25}26)27)2829register_options([30OptString.new('HOSTNAMES', [false, 'Comma separated list of hostnames to resolve.']),31OptPath.new('HOSTFILE', [false, 'Line separated file with hostnames to resolve.']),32OptEnum.new('AI_FAMILY', [true, 'Address Family', 'IPv4', ['IPv4', 'IPv6'] ]),33OptBool.new('DATABASE', [false, 'Report found hosts to DB', true])34])35end3637def run38hosts = []39if datastore['HOSTNAMES']40hostnames = datastore['HOSTNAMES'].split(',')41hostnames.each do |hostname|42hostname.strip!43hosts << hostname unless hostname.empty?44end45end4647if datastore['HOSTFILE']48::File.open(datastore['HOSTFILE'], 'rb').each_line do |hostname|49hostname.strip!50hosts << hostname unless hostname.empty?51end52end5354if hosts.empty?55fail_with(Failure::BadConfig, 'No hostnames to resolve.')56end5758hosts.uniq!5960if datastore['AI_FAMILY'] == 'IPv4'61family = AF_INET62else63family = AF_INET664end6566print_status("Attempting to resolve '#{hosts.join(', ')}' on #{sysinfo['Computer']}") if sysinfo6768response = client.net.resolve.resolve_hosts(hosts, family)6970table = Rex::Text::Table.new(71'Indent' => 0,72'SortIndex' => -1,73'Columns' =>74[75'Hostname',76'IP',77]78)7980response.each do |result|81if result[:ip].nil?82table << [result[:hostname], '[Failed To Resolve]']83next84end8586if datastore['DATABASE']87report_host(88host: result[:ip],89name: result[:hostname]90)91end9293table << [result[:hostname], result[:ip]]94end9596table.print97end98end99100101