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

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

93 lines
2.8 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
2022-09-22 17:05:19 +10:00
include Msf::Post::Windows::Priv
2015-05-09 10:48:07 +01:00
def initialize(info = {})
2021-09-10 12:53:39 +01:00
super(
update_info(
info,
'Name' => 'Windows Gather Enumerate Domain Group',
'Description' => %q{
2022-09-22 17:05:19 +10:00
This module extracts user accounts from the specified domain group
2021-09-10 12:53:39 +01:00
and stores the results in the loot. It will also verify if session
account is in the group. Data is stored in loot in a format that
2022-09-22 17:05:19 +10:00
is compatible with the token_hunter plugin. This module must be
run on a session running as a domain user.
2021-09-10 12:53:39 +01:00
},
'License' => MSF_LICENSE,
'Author' => [
2015-05-09 10:48:07 +01:00
'Carlos Perez <carlos_perez[at]darkoperator.com>',
'Stephen Haywood <haywoodsb[at]gmail.com>'
],
2021-09-10 12:53:39 +01:00
'Platform' => [ 'win' ],
2021-10-06 13:43:31 +01:00
'SessionTypes' => [ 'meterpreter' ],
2022-09-22 17:05:19 +10:00
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [],
'SideEffects' => []
},
2021-10-06 13:43:31 +01:00
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
stdapi_sys_config_getuid
]
}
}
2021-09-10 12:53:39 +01:00
)
)
2022-09-22 17:05:19 +10:00
register_options([
OptString.new('GROUP', [true, 'Domain Group to enumerate', nil])
])
2013-09-05 13:41:25 -05:00
end
def run
2022-09-22 17:05:19 +10:00
hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']
print_status("Running module against #{hostname} (#{session.session_host})")
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
group = datastore['GROUP']
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
fail_with(Failure::BadConfig, 'GROUP must be set.') if group.blank?
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
domain = get_domain_name
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
fail_with(Failure::Unknown, 'Could not retrieve domain name. Is the host part of a domain?') if domain.blank?
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
netbios_domain_name = domain.split('.').first.upcase
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
members = get_members_from_group(group, domain) || []
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
fail_with(Failure::Unknown, "No members found for '#{domain}\\#{group}' group.") if members.blank?
2021-09-10 12:53:39 +01:00
2022-09-22 17:05:19 +10:00
print_status("Found #{members.length} users in '#{domain}\\#{group}' group.")
2021-09-10 12:53:39 +01:00
2022-09-22 17:05:19 +10:00
loot = []
members.each do |user|
print_status("\t#{netbios_domain_name}\\#{user}")
loot << "#{netbios_domain_name}\\#{user}"
2013-09-05 13:41:25 -05:00
end
2022-09-22 17:05:19 +10:00
user_domain, user = client.sys.config.getuid.split('\\')
2013-09-05 13:41:25 -05:00
2022-09-22 17:05:19 +10:00
if user_domain.downcase.include?(netbios_domain_name.downcase) && members.map { |u| u.downcase == user.downcase }.include?(true)
print_good("Current session running as #{domain}\\#{user} is a member of #{domain}\\#{group}!")
else
print_status("Current session running as #{domain}\\#{user} is not a member of #{domain}\\#{group}")
2013-09-05 13:41:25 -05:00
end
2022-09-22 17:05:19 +10:00
loot_file = store_loot(
'domain.group.members',
'text/plain',
session,
loot.join("\n"),
nil,
group
)
print_good("User list stored in #{loot_file}")
2013-09-05 13:41:25 -05:00
end
end