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_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::LDAP8# include Msf::Post::Windows::Accounts910USER_FIELDS = [11'name',12'distinguishedname',13'description'14].freeze1516def initialize(info = {})17super(18update_info(19info,20'Name' => 'Windows Gather Active Directory Groups',21'Description' => %q{22This module will enumerate AD groups on the specified domain.23},24'License' => MSF_LICENSE,25'Author' => [26'Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>'27],28'Platform' => [ 'win' ],29'SessionTypes' => [ 'meterpreter' ]30)31)3233register_options([34OptString.new('ADDITIONAL_FIELDS', [false, 'Additional fields to retrieve, comma separated', nil]),35OptString.new('FILTER', [false, 'Customised LDAP filter', nil])36])37end3839def run40@user_fields = USER_FIELDS.dup4142if datastore['ADDITIONAL_FIELDS']43additional_fields = datastore['ADDITIONAL_FIELDS'].gsub(/\s+/, '').split(',')44@user_fields.push(*additional_fields)45end4647max_search = datastore['MAX_SEARCH']4849begin50f = ''51f = "(#{datastore['FILTER']})" if datastore['FILTER']52q = query("(&(objectClass=group)#{f})", max_search, @user_fields)53rescue ::RuntimeError, ::Rex::Post::Meterpreter::RequestError => e54# Can't bind or in a network w/ limited accounts55print_error(e.message)56return57end5859if q.nil? || q[:results].empty?60print_status('No results returned.')61else62results_table = parse_results(q[:results])63print_line results_table.to_s64end65end6667# Takes the results of LDAP query, parses them into a table68# and records and usernames as {Metasploit::Credential::Core}s in69# the database.70#71# @param results [Array<Array<Hash>>] The LDAP query results to parse72# @return [Rex::Text::Table] The table containing all the result data73def parse_results(results)74# Results table holds raw string data75results_table = Rex::Text::Table.new(76'Header' => 'Domain Groups',77'Indent' => 1,78'SortIndex' => -1,79'Columns' => @user_fields80)8182results.each do |result|83row = []8485result.each do |field|86if field.nil?87row << ''88else89row << field[:value]90end91end9293results_table << row94end95results_table96end97end9899100