@@ -43,13 +43,15 @@ def initialize(info={})
43
43
] , self . class )
44
44
end
45
45
46
- def run
46
+ def setup
47
+ super
48
+
47
49
if is_system?
48
50
# running as SYSTEM and will not pass any network credentials
49
51
print_error "Running as SYSTEM, module should be run with USER level rights"
50
52
return
51
53
else
52
- adv = client . railgun . advapi32
54
+ @ adv = client . railgun . advapi32
53
55
54
56
# Get domain and domain controller if options left blank
55
57
if datastore [ 'DOMAIN' ] . nil?
@@ -76,7 +78,6 @@ def run
76
78
print_error ( "User never logged into device, will not enumerate groups or manually specify DC." )
77
79
end
78
80
end
79
- super
80
81
end
81
82
end
82
83
@@ -93,6 +94,7 @@ def enum_users(host)
93
94
winsessions = client . railgun . netapi32 . NetWkstaUserEnum ( "\\ \\ #{ host } " , 1 , 4 , -1 , 4 , 4 , nil )
94
95
rescue ::Exception => e
95
96
print_error ( "Issue enumerating users on #{ host } " )
97
+ print_error ( e . backtrace ) if datastore [ 'VERBOSE' ]
96
98
end
97
99
count = winsessions [ 'totalentries' ] * 2
98
100
startmem = winsessions [ 'bufptr' ]
@@ -120,7 +122,7 @@ def enum_users(host)
120
122
# an error, or if option disabled
121
123
data = ""
122
124
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 ( ", " ) } "
124
126
end
125
127
line = "\t Logged in user:\t #{ temp [ :domain ] } \\ #{ temp [ :user ] } #{ data } \n "
126
128
@@ -134,6 +136,7 @@ def enum_users(host)
134
136
}
135
137
rescue ::Exception => e
136
138
print_error ( "Issue enumerating users on #{ host } " )
139
+ print_error ( e . backtrace ) if datastore [ 'VERBOSE' ]
137
140
end
138
141
return userlist
139
142
end
@@ -188,9 +191,13 @@ def enum_groups(user)
188
191
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms684323(v=vs.85).aspx
189
192
# method to connect to remote host using windows api
190
193
def connect(host)
194
+ if @adv.nil?
195
+ return
196
+ end
197
+
191
198
user = client.sys.config.getuid
192
199
# 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
194
201
195
202
if(manag["return"] != 0) # we have admin rights
196
203
result = "#{ host . ljust ( 16 ) } #{ user } - Local admin found\n"
@@ -203,10 +210,10 @@ def connect(host)
203
210
end
204
211
205
212
# close the handle if connection was made
206
- adv.CloseServiceHandle(manag["return"])
213
+ @ adv.CloseServiceHandle(manag["return"])
207
214
# Append data to loot table within database
208
- db_loot(host, user, "localadmin.user")
209
215
print_good(result.chomp("\n")) unless result.nil?
216
+ db_loot(host, user, "localadmin.user")
210
217
else
211
218
# we dont have admin rights
212
219
print_error("#{ host . ljust ( 16 ) } #{ user } - No Local Admin rights")
@@ -229,7 +236,7 @@ def db_note(host, data, type)
229
236
def db_loot(host, user, type)
230
237
if db
231
238
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']
233
240
end
234
241
end
235
- end
242
+ end
0 commit comments