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

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

110 lines
2.8 KiB
Ruby
Raw Normal View History

2011-11-10 03:13:57 -06:00
##
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
2011-11-10 03:13:57 -06:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-09-05 13:41:25 -05:00
include Msf::Post::File
2011-11-20 12:53:25 +11:00
2013-09-05 13:41:25 -05:00
include Msf::Post::Windows::Registry
2011-11-10 03:13:57 -06:00
2021-09-10 12:53:39 +01:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Windows Gather Enumerate Computers',
'Description' => %q{
This module will enumerate computers included in the primary Domain.
2013-09-05 13:41:25 -05:00
},
2021-09-10 12:53:39 +01:00
'License' => MSF_LICENSE,
'Author' => [ 'Joshua Abraham <jabra[at]rapid7.com>'],
'Platform' => [ 'win'],
2021-10-06 13:43:31 +01:00
'SessionTypes' => [ 'meterpreter' ],
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
stdapi_net_resolve_host
]
}
}
2021-09-10 12:53:39 +01:00
)
)
2013-09-05 13:41:25 -05:00
end
2011-11-10 03:13:57 -06:00
2013-09-05 13:41:25 -05:00
# Run Method for when run command is issued
def run
print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
domain = get_domain()
if not domain.empty?
hostname_list = get_domain_computers()
list_computers(domain, hostname_list)
end
end
2011-11-10 03:13:57 -06:00
2013-09-05 13:41:25 -05:00
def gethost(hostname)
## get IP for host
2013-09-24 21:58:04 +01:00
vprint_status("Looking up IP for #{hostname}")
result = client.net.resolve.resolve_host(hostname)
2011-11-10 03:13:57 -06:00
2013-09-24 21:58:04 +01:00
return nil if result[:ip].nil? or result[:ip].blank?
2021-09-10 12:53:39 +01:00
2013-09-24 21:58:04 +01:00
return result[:ip]
2013-09-05 13:41:25 -05:00
end
2011-11-10 03:13:57 -06:00
2013-09-05 13:41:25 -05:00
# List Members of a domain group
def get_domain_computers()
computer_list = []
devisor = "-------------------------------------------------------------------------------\r\n"
2015-06-29 11:56:38 -05:00
raw_list = cmd_exec('net view').split(devisor)[1]
2013-09-05 13:41:25 -05:00
if raw_list =~ /The command completed successfully/
2021-09-10 12:53:39 +01:00
raw_list.sub!(/The command completed successfully\./, '')
raw_list.gsub!(/\\\\/, '')
2013-09-05 13:41:25 -05:00
raw_list.split(" ").each do |m|
computer_list << m
end
end
2011-11-10 03:13:57 -06:00
2013-09-05 13:41:25 -05:00
return computer_list
end
2011-11-10 03:13:57 -06:00
2013-09-05 13:41:25 -05:00
# Gets the Domain Name
def get_domain()
domain = ""
begin
subkey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History"
v_name = "DCName"
domain_dc = registry_getvaldata(subkey, v_name)
2021-09-10 12:53:39 +01:00
dom_info = domain_dc.split('.')
2013-09-05 13:41:25 -05:00
domain = dom_info[1].upcase
rescue
print_error("This host is not part of a domain.")
end
return domain
end
2011-11-10 03:13:57 -06:00
2021-09-10 12:53:39 +01:00
def list_computers(domain, hosts)
2016-08-10 13:30:09 -05:00
tbl = Rex::Text::Table.new(
2021-09-10 12:53:39 +01:00
'Header' => "List of Domain Hosts for the primary Domain.",
'Indent' => 1,
2013-09-05 13:41:25 -05:00
'Columns' =>
[
"Domain",
"Hostname",
"IPs",
2021-09-10 12:53:39 +01:00
]
)
2013-09-05 13:41:25 -05:00
hosts.each do |hostname|
hostip = gethost(hostname)
2021-09-10 12:53:39 +01:00
tbl << [domain, hostname, hostip]
2013-09-05 13:41:25 -05:00
end
results = tbl.to_s
print_line("\n" + results + "\n")
2011-11-10 03:13:57 -06:00
2013-09-05 13:41:25 -05:00
report_note(
:host => session,
:type => 'domain.hosts',
:data => tbl.to_csv
)
end
2011-11-10 03:13:57 -06:00
end