Skip to content

Commit e76cacc

Browse files
committed
Handle existing service names
1 parent fde4a3e commit e76cacc

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

lib/msf/core/exploit/dcerpc_services.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ def dce_createservicew(dcerpc, scm_handle, service_name, display_name, binary_pa
119119
return svc_handle, svc_status
120120
end
121121

122+
# Calls ChangeServiceConfig2() to change the service description.
123+
#
124+
# @param dcerpc [Rex::Proto::DCERPC::Client] the DCERPC client to use.
125+
# @param svc_handle [String] the service handle to change.
126+
# @param service_description [String] the service description.
127+
#
128+
# @return [Integer] Windows error code
129+
def dce_changeservicedescription(dcerpc, svc_handle, service_description)
130+
svc_status = nil
131+
stubdata =
132+
svc_handle +
133+
NDR.long(1) + # dwInfoLevel = SERVICE_CONFIG_DESCRIPTION
134+
NDR.long(1) + # lpInfo -> *SERVICE_DESCRIPTION
135+
NDR.long(0x0200) + # SERVICE_DESCRIPTION struct
136+
NDR.long(0x04000200) +
137+
NDR.wstring(service_description)
138+
begin
139+
response = dcerpc.call(0x25, stubdata) # ChangeServiceConfig2
140+
svc_status = response.unpack('V').first
141+
rescue Rex::Proto::DCERPC::Exceptions::Fault => e
142+
print_error("#{peer} - Error changing service description : #{e}")
143+
end
144+
145+
svc_status
146+
end
147+
148+
122149
# Calls CloseHandle() to close a handle.
123150
#
124151
# @param dcerpc [Rex::Proto::DCERPC::Client] the DCERPC client to use.
@@ -147,7 +174,7 @@ def dce_closehandle(dcerpc, handle)
147174
# @param access [Fixnum] the level of access requested (default is maximum).
148175
#
149176
# @return [String, nil] the handle of the service opened, or nil on failure.
150-
def dce_openservicew(dcerpc, scm_handle, service_name, access = 0xF01FF)
177+
def dce_openservicew(dcerpc, scm_handle, service_name, access = SERVICE_ALL_ACCESS)
151178
svc_handle = nil
152179
svc_status = nil
153180
stubdata = scm_handle + NDR.wstring(service_name) + NDR.long(access)

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,6 @@ def smb_read_file(smbshare, host, file)
6161
end
6262
end
6363

64-
def change_service_description(svc_handle, service_description)
65-
svc_status = nil
66-
stubdata =
67-
svc_handle +
68-
NDR.long(1) + # dwInfoLevel = SERVICE_CONFIG_DESCRIPTION
69-
NDR.long(1) + # lpInfo -> *SERVICE_DESCRIPTION
70-
NDR.long(0x0200) + # SERVICE_DESCRIPTION struct
71-
NDR.long(0x04000200) +
72-
NDR.wstring(service_description)
73-
begin
74-
response = dcerpc.call(0x25, stubdata) # ChangeServiceConfig2
75-
svc_status = response.unpack('V').first
76-
rescue Rex::Proto::DCERPC::Exceptions::Fault => e
77-
print_error("#{peer} - Error changing service description : #{e}")
78-
end
79-
80-
svc_status
81-
end
82-
8364
# Executes a single windows command.
8465
#
8566
# If you want to retrieve the output of your command you'll have to
@@ -105,13 +86,12 @@ def psexec(command, disconnect=true)
10586
if scm_status == ERROR_ACCESS_DENIED
10687
print_error("#{peer} - ERROR_ACCESS_DENIED opening the Service Manager")
10788
end
89+
10890
return false unless scm_handle
10991

11092
vprint_status("#{peer} - Creating the service...")
11193
svc_handle, svc_status = dce_createservicew(dcerpc, scm_handle, service_name, display_name, command, {})
11294

113-
return false unless svc_handle && svc_status
114-
11595
case svc_status
11696
when ERROR_SUCCESS
11797
vprint_good("#{peer} - Successfully created the service")
@@ -131,7 +111,7 @@ def psexec(command, disconnect=true)
131111

132112
if service_description
133113
vprint_status("#{peer} - Changing service description...")
134-
change_service_description(svc_handle, service_description)
114+
dce_changeservicedescription(dcerpc, svc_handle, service_description)
135115
end
136116

137117
vprint_status("#{peer} - Starting the service...")

0 commit comments

Comments
 (0)