Skip to content

Commit ddd4b7e

Browse files
committed
Applying fixes
1 parent 5369f88 commit ddd4b7e

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

modules/post/windows/gather/local_admin_search_enum.rb

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
##
2-
# ## This file is part of the Metasploit Framework and may be subject to
2+
# This file is part of the Metasploit Framework and may be subject to
33
# redistribution and commercial restrictions. Please see the Metasploit
44
# Framework web site for more information on licensing and terms of use.
5-
# http://metasploit.com/framework/
5+
# http://metasploit.com/framework/
66
##
77

8+
89
require 'msf/core'
910
require 'rex'
1011
require 'msf/core/post/common'
@@ -17,35 +18,42 @@ class Metasploit3 < Msf::Post
1718
include Msf::Post::Common
1819

1920
def initialize(info={})
20-
super(
21-
'Name' => 'Windows Local Admin Search',
21+
super(update_info(info,
22+
'Name' => 'Windows Gather Local Admin Search',
2223
'Description' => %q{
23-
This module will identify systems in a given range that the
24+
This module will identify systems in a given range that the
2425
supplied domain user (should migrate into a user pid) has administrative
25-
access to by using the windows api OpenSCManagerA to establishing a handle
26+
access to by using the Windows API OpenSCManagerA to establishing a handle
2627
to the remote host. Additionally it can enumerate logged in users and group
27-
membership via windows api NetWkstaUserEnum and NetUserGetGroups.
28-
},
28+
membership via Windows API NetWkstaUserEnum and NetUserGetGroups.
29+
},
2930
'License' => MSF_LICENSE,
30-
'Version' => '$Revision: 14767 $',
31-
'Author' => [ 'Brandon McCann "zeknox" <bmccann [at] accuvant.com>', 'Thomas McCarthy "smilingraccoon" <smilingraccoon [at] gmail.com>', 'Royce Davis "r3dy" <rdavis [at] accuvant.com>'],
31+
'Author' =>
32+
[
33+
'Brandon McCann "zeknox" <bmccann[at]accuvant.com>',
34+
'Thomas McCarthy "smilingraccoon" <smilingraccoon[at]gmail.com>',
35+
'Royce Davis "r3dy" <rdavis[at]accuvant.com>'
36+
],
3237
'Platform' => [ 'windows'],
3338
'SessionTypes' => [ 'meterpreter' ]
34-
)
39+
))
3540

3641
register_options(
3742
[
3843
OptBool.new('ENUM_USERS', [ true, 'Enumerates logged on users.', true]),
3944
OptBool.new('ENUM_GROUPS', [ false, 'Enumerates groups for identified users.', true]),
40-
OptString.new('DOMAIN', [false, 'Domain to enumerate user\'s groups for', nil]),
41-
OptString.new('DOMAIN_CONTROLLER', [false, 'Domain Controller to query groups', nil])
42-
45+
OptString.new('DOMAIN', [false, 'Domain to enumerate user\'s groups for']),
46+
OptString.new('DOMAIN_CONTROLLER', [false, 'Domain Controller to query groups'])
4347
], self.class)
4448
end
4549

4650
def setup
4751
super
4852

53+
# This datastore option can be modified during runtime.
54+
# Saving it here so the modified value remains with this module.
55+
@domain_controller = datastore['DOMAIN_CONTROLLER']
56+
4957
if is_system?
5058
# running as SYSTEM and will not pass any network credentials
5159
print_error "Running as SYSTEM, module should be run with USER level rights"
@@ -59,7 +67,7 @@ def setup
5967
datastore['DOMAIN'] = user.split('\\')[0]
6068
end
6169

62-
if datastore['DOMAIN_CONTROLLER'].nil? and datastore['ENUM_GROUPS']
70+
if @domain_controll.nil? and datastore['ENUM_GROUPS']
6371
@dc_error = false
6472

6573
# Uses DC which applied policy since it would be a DC this device normally talks to
@@ -72,7 +80,7 @@ def setup
7280

7381
# Check if RSOP data exists, if not disable group check
7482
unless res =~ /does not have RSOP data./
75-
datastore['DOMAIN_CONTROLLER'] = /Group Policy was applied from:\s*(.*)\s*/.match(res)[1].chomp
83+
@domain_controller = /Group Policy was applied from:\s*(.*)\s*/.match(res)[1].chomp
7684
else
7785
@dc_error = true
7886
print_error("User never logged into device, will not enumerate groups or manually specify DC.")
@@ -89,13 +97,19 @@ def run_host(ip)
8997
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa370669(v=vs.85).aspx
9098
# enumerate logged in users
9199
def enum_users(host)
100+
userlist = Array.new
101+
92102
begin
93103
# Connect to host and enumerate logged in users
94104
winsessions = client.railgun.netapi32.NetWkstaUserEnum("\\\\#{host}", 1, 4, -1, 4, 4, nil)
95105
rescue ::Exception => e
96106
print_error("Issue enumerating users on #{host}")
97-
print_error(e.backtrace) if datastore['VERBOSE']
107+
vprint_error(e.backtrace)
108+
return userlist
98109
end
110+
111+
return userlist if winsessions.nil?
112+
99113
count = winsessions['totalentries'] * 2
100114
startmem = winsessions['bufptr']
101115

@@ -105,7 +119,8 @@ def enum_users(host)
105119
mem = client.railgun.memread(startmem, 8*count)
106120
rescue ::Exception => e
107121
print_error("Issue reading memory for #{host}")
108-
print_error(e.backtrace) if datastore['VERBOSE']
122+
vprint_error(e.backtrace)
123+
return userlist
109124
end
110125
# For each entry returned, get domain and name of logged in user
111126
begin
@@ -137,7 +152,7 @@ def enum_users(host)
137152
}
138153
rescue ::Exception => e
139154
print_error("Issue enumerating users on #{host}")
140-
print_error(e.backtrace) if datastore['VERBOSE']
155+
vprint_error(e.backtrace)
141156
end
142157
return userlist
143158
end
@@ -154,7 +169,8 @@ def enum_groups(user)
154169

155170
rescue ::Exception => e
156171
print_error("Issue connecting to DC, try manually setting domain and DC")
157-
print_error(e.backtrace) if datastore['VERBOSE']
172+
vprint_error(e.backtrace)
173+
return grouplist
158174
end
159175

160176
count = usergroups['totalentries']
@@ -165,7 +181,8 @@ def enum_groups(user)
165181
mem = client.railgun.memread(startmem, 8*count)
166182
rescue ::Exception => e
167183
print_error("Issue reading memory for groups for user #{user}")
168-
print_error(e.backtrace) if datastore['VERBOSE']
184+
vprint_error(e.backtrace)
185+
return grouplist
169186
end
170187

171188
begin
@@ -185,7 +202,8 @@ def enum_groups(user)
185202
186203
rescue ::Exception => e
187204
print_error("Issue enumerating groups for user #{user}, check domain")
188-
print_error(e.backtrace) if datastore['VERBOSE']
205+
vprint_error(e.backtrace)
206+
return grouplist
189207
end
190208
191209
return grouplist.chomp("\n\t- ")
@@ -226,21 +244,17 @@ def connect(host)
226244
227245
# Write to notes database
228246
def db_note(host, data, type)
229-
if db
230-
report_note(
231-
:type => type,
232-
:data => data,
233-
:host => host,
234-
:update => :unique_data
235-
)
236-
end
247+
report_note(
248+
:type => type,
249+
:data => data,
250+
:host => host,
251+
:update => :unique_data
252+
)
237253
end
238254
239255
# Write to loot database
240256
def db_loot(host, user, type)
241-
if db
242-
p = store_loot(type, 'text/plain', host, "#{host}:#{user}", 'hosts_localadmin.txt', user)
243-
print_status("User data stored in: #{p}") if datastore['VERBOSE']
244-
end
257+
p = store_loot(type, 'text/plain', host, "#{host}:#{user}", 'hosts_localadmin.txt', user)
258+
vprint_status("User data stored in: #{p}")
245259
end
246260
end

0 commit comments

Comments
 (0)