New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Identify Managed AD Security Groups #6375
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae09549
New module, strating with managedby_groups
stufus 89728fd
Working version
stufus c0a9343
msftidy
stufus 07caaf3
made comment match purpose
stufus c394caa
actually made the securitygroups only option do something
stufus 9493b33
rubocop
stufus b0fca76
capitalisation
stufus e8c8c54
Use a regex with a negative lookbehind to cope with CNs that contain …
stufus File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
modules/post/windows/gather/enum_ad_managedby_groups.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
## | ||
# This module requires Metasploit: http://metasploit.com/download | ||
# Current source: https://github.com/rapid7/metasploit-framework | ||
## | ||
|
||
require 'rex' | ||
require 'msf/core' | ||
|
||
class Metasploit3 < Msf::Post | ||
include Msf::Auxiliary::Report | ||
include Msf::Post::Windows::LDAP | ||
|
||
USER_FIELDS = ['cn', | ||
'distinguishedname', | ||
'managedBy', | ||
'description'].freeze | ||
|
||
def initialize(info = {}) | ||
super(update_info( | ||
info, | ||
'Name' => 'Windows Gather Active Directory Managed Groups', | ||
'Description' => %{ | ||
This module will enumerate AD groups on the specified domain which are specifically managed. | ||
It cannot at the moment identify whether the 'Manager can update membership list' option | ||
option set; if so, it would allow that member to update the contents of that group. This | ||
could either be used as a persistence mechanism (for example, set your user as the 'Domain | ||
Admins' group manager) or could be used to detect privilege escalation opportunities | ||
without having domain admin privileges. | ||
}, | ||
'License' => MSF_LICENSE, | ||
'Author' => [ | ||
'Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>' | ||
], | ||
'Platform' => [ 'win' ], | ||
'SessionTypes' => [ 'meterpreter' ] | ||
)) | ||
|
||
register_options([ | ||
OptString.new('ADDITIONAL_FIELDS', [false, 'Additional group fields to retrieve, comma separated.', nil]), | ||
OptBool.new('RESOLVE_MANAGERS', [true, 'Query LDAP to get the account name of group managers.', TRUE]), | ||
OptBool.new('SECURITY_GROUPS_ONLY', [true, 'Only include security groups.', TRUE]) | ||
], self.class) | ||
end | ||
|
||
def run | ||
@user_fields = USER_FIELDS.dup | ||
|
||
if datastore['ADDITIONAL_FIELDS'] | ||
additional_fields = datastore['ADDITIONAL_FIELDS'].gsub(/\s+/, "").split(',') | ||
@user_fields.push(*additional_fields) | ||
end | ||
|
||
max_search = datastore['MAX_SEARCH'] | ||
|
||
begin | ||
qs = '(&(objectClass=group)(managedBy=*))' | ||
if datastore['SECURITY_GROUPS_ONLY'] | ||
qs = '(&(objectClass=group)(managedBy=*)(groupType:1.2.840.113556.1.4.803:=2147483648))' | ||
end | ||
q = query(qs, max_search, @user_fields) | ||
rescue ::RuntimeError, ::Rex::Post::Meterpreter::RequestError => e | ||
# Can't bind or in a network w/ limited accounts | ||
print_error(e.message) | ||
return | ||
end | ||
|
||
if q.nil? || q[:results].empty? | ||
print_status('No results returned.') | ||
else | ||
@user_fields << 'Manager Account Name' if datastore['RESOLVE_MANAGERS'] | ||
results_table = parse_results(q[:results]) | ||
print_line results_table.to_s | ||
end | ||
end | ||
|
||
# Takes the results of LDAP query, parses them into a table | ||
def parse_results(results) | ||
results_table = Rex::Ui::Text::Table.new( | ||
'Header' => "Groups with Managers", | ||
'Indent' => 1, | ||
'SortIndex' => -1, | ||
'Columns' => @user_fields | ||
) | ||
|
||
results.each do |result| | ||
row = [] | ||
|
||
result.each do |field| | ||
if field.nil? | ||
row << "" | ||
else | ||
row << field[:value] | ||
end | ||
end | ||
if datastore['RESOLVE_MANAGERS'] | ||
begin | ||
managedby_cn = result[2][:value].split(/,(?<!\\,)/)[0] | ||
m = query("(&(objectClass=user)(objectCategory=person)(#{managedby_cn}))", 1, ['sAMAccountName']) | ||
if !m.nil? && !m[:results].empty? | ||
row << m[:results][0][0][:value] | ||
else | ||
row << "" | ||
end | ||
rescue | ||
row << "" | ||
end | ||
end | ||
results_table << row | ||
end | ||
results_table | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a Group is managed by a Group then this fails to resolve the 'Manager Account Name', although 'managedBy' will be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update this just to search on the distinguishedName