Skip to content

Commit 8e50baa

Browse files
David MaloneyDavid Maloney
authored andcommitted
Land rapid7#4771, userPrincipalName fix
Lands Meatballs1's PR to add userPrincipalName as a column enumerated by the enum_ad_user* post modules.
2 parents 6eaa3c2 + ecefad9 commit 8e50baa

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

modules/post/windows/gather/enum_ad_user_comments.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize(info={})
3131

3232
register_options([
3333
OptBool.new('STORE_LOOT', [true, 'Store file in loot.', false]),
34-
OptString.new('FIELDS', [true, 'Fields to retrieve.','sAMAccountName,userAccountControl,comment,description']),
34+
OptString.new('FIELDS', [true, 'Fields to retrieve.','userPrincipalName,sAMAccountName,userAccountControl,comment,description']),
3535
OptString.new('FILTER', [true, 'Search filter.','(&(&(objectCategory=person)(objectClass=user))(|(description=*pass*)(comment=*pass*)))']),
3636
], self.class)
3737
end
@@ -63,7 +63,6 @@ def run
6363
q[:results].each do |result|
6464
row = []
6565

66-
report = {}
6766
result.each do |field|
6867
if field[:value].nil?
6968
row << ""

modules/post/windows/gather/enum_ad_users.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ class Metasploit3 < Msf::Post
1212
include Msf::Post::Windows::Accounts
1313

1414
UAC_DISABLED = 0x02
15-
USER_FIELDS = ['sAMAccountName', 'userAccountControl', 'lockoutTime', 'mail', 'primarygroupid', 'description'].freeze
15+
USER_FIELDS = ['sAMAccountName',
16+
'userPrincipalName',
17+
'userAccountControl',
18+
'lockoutTime',
19+
'mail',
20+
'primarygroupid',
21+
'description'].freeze
1622

1723
def initialize(info = {})
1824
super(update_info(
@@ -35,6 +41,7 @@ def initialize(info = {})
3541
OptBool.new('STORE_LOOT', [true, 'Store file in loot.', false]),
3642
OptBool.new('EXCLUDE_LOCKED', [true, 'Exclude in search locked accounts..', false]),
3743
OptBool.new('EXCLUDE_DISABLED', [true, 'Exclude from search disabled accounts.', false]),
44+
OptString.new('ADDITIONAL_FIELDS', [false, 'Additional fields to retrieve, comma separated', nil]),
3845
OptEnum.new('UAC', [true, 'Filter on User Account Control Setting.', 'ANY',
3946
[
4047
'ANY',
@@ -48,10 +55,17 @@ def initialize(info = {})
4855
end
4956

5057
def run
58+
@user_fields = USER_FIELDS.dup
59+
60+
if datastore['ADDITIONAL_FIELDS']
61+
additional_fields = datastore['ADDITIONAL_FIELDS'].gsub(/\s+/,"").split(',')
62+
@user_fields.push(*additional_fields)
63+
end
64+
5165
max_search = datastore['MAX_SEARCH']
5266

5367
begin
54-
q = query(query_filter, max_search, USER_FIELDS)
68+
q = query(query_filter, max_search, @user_fields)
5569
rescue ::RuntimeError, ::Rex::Post::Meterpreter::RequestError => e
5670
# Can't bind or in a network w/ limited accounts
5771
print_error(e.message)
@@ -93,7 +107,7 @@ def parse_results(results)
93107
'Header' => "Domain Users",
94108
'Indent' => 1,
95109
'SortIndex' => -1,
96-
'Columns' => USER_FIELDS
110+
'Columns' => @user_fields
97111
)
98112

99113
results.each do |result|
@@ -107,9 +121,9 @@ def parse_results(results)
107121
end
108122
end
109123

110-
username = result.first[:value]
111-
uac = result[1][:value]
112-
lockout_time = result[2][:value]
124+
username = result[@user_fields.index('sAMAccountName')][:value]
125+
uac = result[@user_fields.index('userAccountControl')][:value]
126+
lockout_time = result[@user_fields.index('lockoutTime')][:value]
113127
store_username(username, uac, lockout_time, domain, domain_ip)
114128

115129
results_table << row

0 commit comments

Comments
 (0)