Skip to content

Commit 501224f

Browse files
committed
setup() added
1 parent e7a565b commit 501224f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

modules/post/windows/gather/local_admin_search_enum.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ def initialize(info={})
4343
], self.class)
4444
end
4545

46-
def run
46+
def setup
47+
super
48+
4749
if is_system?
4850
# running as SYSTEM and will not pass any network credentials
4951
print_error "Running as SYSTEM, module should be run with USER level rights"
5052
return
5153
else
52-
adv = client.railgun.advapi32
54+
@adv = client.railgun.advapi32
5355

5456
# Get domain and domain controller if options left blank
5557
if datastore['DOMAIN'].nil?
@@ -76,7 +78,6 @@ def run
7678
print_error("User never logged into device, will not enumerate groups or manually specify DC.")
7779
end
7880
end
79-
super
8081
end
8182
end
8283

@@ -93,6 +94,7 @@ def enum_users(host)
9394
winsessions = client.railgun.netapi32.NetWkstaUserEnum("\\\\#{host}", 1, 4, -1, 4, 4, nil)
9495
rescue ::Exception => e
9596
print_error("Issue enumerating users on #{host}")
97+
print_error(e.backtrace) if datastore['VERBOSE']
9698
end
9799
count = winsessions['totalentries'] * 2
98100
startmem = winsessions['bufptr']
@@ -120,7 +122,7 @@ def enum_users(host)
120122
# an error, or if option disabled
121123
data = ""
122124
if datastore['DOMAIN'].upcase == temp[:domain].upcase and not @dc_error and datastore['ENUM_GROUPS']
123-
data = " - Groups: #{enum_groups(temp[:user]).chomp(", ")}"
125+
data << " - Groups: #{enum_groups(temp[:user]).chomp(", ")}"
124126
end
125127
line = "\tLogged in user:\t#{temp[:domain]}\\#{temp[:user]}#{data}\n"
126128

@@ -134,6 +136,7 @@ def enum_users(host)
134136
}
135137
rescue ::Exception => e
136138
print_error("Issue enumerating users on #{host}")
139+
print_error(e.backtrace) if datastore['VERBOSE']
137140
end
138141
return userlist
139142
end
@@ -188,9 +191,13 @@ def enum_groups(user)
188191
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms684323(v=vs.85).aspx
189192
# method to connect to remote host using windows api
190193
def connect(host)
194+
if @adv.nil?
195+
return
196+
end
197+
191198
user = client.sys.config.getuid
192199
# use railgun and OpenSCManagerA api to connect to remote host
193-
manag = adv.OpenSCManagerA("\\\\#{host}", nil, 0xF003F) # SC_MANAGER_ALL_ACCESS
200+
manag = @adv.OpenSCManagerA("\\\\#{host}", nil, 0xF003F) # SC_MANAGER_ALL_ACCESS
194201
195202
if(manag["return"] != 0) # we have admin rights
196203
result = "#{host.ljust(16)} #{user} - Local admin found\n"
@@ -203,10 +210,10 @@ def connect(host)
203210
end
204211
205212
# close the handle if connection was made
206-
adv.CloseServiceHandle(manag["return"])
213+
@adv.CloseServiceHandle(manag["return"])
207214
# Append data to loot table within database
208-
db_loot(host, user, "localadmin.user")
209215
print_good(result.chomp("\n")) unless result.nil?
216+
db_loot(host, user, "localadmin.user")
210217
else
211218
# we dont have admin rights
212219
print_error("#{host.ljust(16)} #{user} - No Local Admin rights")
@@ -229,7 +236,7 @@ def db_note(host, data, type)
229236
def db_loot(host, user, type)
230237
if db
231238
p = store_loot(type, 'text/plain', host, "#{host}:#{user}", 'hosts_localadmin.txt', user)
232-
print_status("User data stored in: #{p}")
239+
print_status("User data stored in: #{p}") if datastore['VERBOSE']
233240
end
234241
end
235-
end
242+
end

0 commit comments

Comments
 (0)