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_ad_managedby_groups.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::Auxiliary::Report7include Msf::Post::Windows::LDAP89USER_FIELDS = [10'cn',11'distinguishedname',12'managedBy',13'description'14].freeze1516def initialize(info = {})17super(18update_info(19info,20'Name' => 'Windows Gather Active Directory Managed Groups',21'Description' => %q{22This module will enumerate AD groups on the specified domain which are specifically managed.23It cannot at the moment identify whether the 'Manager can update membership list' option24option set; if so, it would allow that member to update the contents of that group. This25could either be used as a persistence mechanism (for example, set your user as the 'Domain26Admins' group manager) or could be used to detect privilege escalation opportunities27without having domain admin privileges.28},29'License' => MSF_LICENSE,30'Author' => [31'Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>'32],33'Platform' => [ 'win' ],34'SessionTypes' => [ 'meterpreter' ]35)36)3738register_options([39OptString.new('ADDITIONAL_FIELDS', [false, 'Additional group fields to retrieve, comma separated.', nil]),40OptBool.new('RESOLVE_MANAGERS', [true, 'Query LDAP to get the account name of group managers.', true]),41OptBool.new('SECURITY_GROUPS_ONLY', [true, 'Only include security groups.', true])42])43end4445def run46@user_fields = USER_FIELDS.dup4748if datastore['ADDITIONAL_FIELDS']49additional_fields = datastore['ADDITIONAL_FIELDS'].gsub(/\s+/, '').split(',')50@user_fields.push(*additional_fields)51end5253max_search = datastore['MAX_SEARCH']5455begin56qs = '(&(objectClass=group)(managedBy=*))'57if datastore['SECURITY_GROUPS_ONLY']58qs = '(&(objectClass=group)(managedBy=*)(groupType:1.2.840.113556.1.4.803:=2147483648))'59end60q = query(qs, max_search, @user_fields)61rescue ::RuntimeError, ::Rex::Post::Meterpreter::RequestError => e62# Can't bind or in a network w/ limited accounts63print_error(e.message)64return65end6667if q.nil? || q[:results].empty?68print_status('No results returned.')69else70@user_fields << 'Manager Account Name' if datastore['RESOLVE_MANAGERS']71results_table = parse_results(q[:results])72print_line results_table.to_s73end74end7576# Takes the results of LDAP query, parses them into a table77def parse_results(results)78results_table = Rex::Text::Table.new(79'Header' => 'Groups with Managers',80'Indent' => 1,81'SortIndex' => -1,82'Columns' => @user_fields83)8485results.each do |result|86row = []8788result.each do |field|89if field.nil?90row << ''91else92row << field[:value]93end94end95if datastore['RESOLVE_MANAGERS']96begin97m = query("(distinguishedName=#{result[2][:value]})", 1, ['sAMAccountName'])98if !m.nil? && !m[:results].empty?99row << m[:results][0][0][:value]100else101row << ''102end103rescue StandardError104row << ''105end106end107results_table << row108end109results_table110end111end112113114