Skip to content

Commit 443dd7b

Browse files
committed
Use constants
1 parent 250250b commit 443dd7b

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

modules/post/windows/gather/enum_ad_users_to_wordlist.rb

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,35 @@ class Metasploit3 < Msf::Post
1111
include Msf::Auxiliary::Report
1212
include Msf::Post::Windows::LDAP
1313

14+
SEARCH_FILTER = '(&(objectClass=organizationalPerson)(objectClass=user)(objectClass=person)(!(objectClass=computer)))'
15+
DEFAULT_FIELDS = [
16+
'sn',
17+
'givenName',
18+
'state',
19+
'postalCode',
20+
'physicalDeliveryOfficeName',
21+
'telephoneNumber',
22+
'mobile',
23+
'facsimileTelephoneNumber',
24+
'displayName',
25+
'title',
26+
'department',
27+
'company',
28+
'streetAddress',
29+
'sAMAccountName',
30+
'userAccountControl',
31+
'comment',
32+
'description'
33+
]
34+
1435
def initialize(info={})
1536
super( update_info( info,
1637
'Name' => 'Windows Gather Words from Active Directory',
17-
'Description' => %Q{
18-
This module will enumerate all user accounts in the default Active Domain (AD) directory and use
19-
these as words to seed a wordlist.In cases (like description) where spaces may occur, some extra processing
20-
is done to generate multiple words in addition to one long one (up to 24 characters).Results are dumped into
21-
/tmp
38+
'Description' => %q{
39+
This module will enumerate all user accounts in the default Active Domain (AD) directory
40+
and use these as words to seed a wordlist.In cases (like description) where spaces may
41+
occur, some extra processing is done to generate multiple words in addition to one long
42+
one (up to 24 characters). Results are dumped into /tmp
2243
},
2344
'License' => MSF_LICENSE,
2445
'Author' => [ 'Thomas Ring' ],
@@ -27,26 +48,15 @@ def initialize(info={})
2748
))
2849

2950
register_options([
30-
OptString.new('FIELDS', [false, 'Fields to retrieve (ie, sn, givenName, displayName, description, comment)', '']),
51+
OptString.new('FIELDS', [true, 'Fields to retrieve (ie, sn, givenName, displayName, description, comment)', DEFAULT_FIELDS]),
3152
], self.class)
3253
end
3354

3455
def run
35-
36-
fields = []
37-
if(datastore['FIELDS'] == '')
38-
field_str = 'sn,givenName,state,postalCode,physicalDeliveryOfficeName,telephoneNumber,mobile,facsimileTelephoneNumber,displayName,'
39-
field_str << 'title,department,company, streetAddress,sAMAccountName,userAccountControl,comment,description'
40-
fields = field_str.gsub!(/\s+/,'').split(',')
41-
else
42-
fields = datastore['FIELDS'].gsub(/\s+/,"").split(',')
43-
end
44-
45-
search_filter = '(&(objectClass=organizationalPerson)(objectClass=user)(objectClass=person)(!(objectClass=computer)))'
46-
max_search = datastore['MAX_SEARCH']
56+
fields = datastore['FIELDS'].gsub(/\s+/,"").split(',')
4757

4858
begin
49-
q = query(search_filter, max_search, fields)
59+
q = query(SEARCH_FILTER, datastore['MAX_SEARCH'], fields)
5060
return if !q or q[:results].empty?
5161
rescue ::RuntimeError, ::Rex::Post::Meterpreter::RequestError => e
5262
# Can't bind or in a network w/ limited accounts

0 commit comments

Comments
 (0)