Skip to content

Commit fde4a3e

Browse files
committed
Get it all working...
1 parent 54cf1ba commit fde4a3e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/msf/core/exploit/dcerpc_services.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ module Exploit::Remote::DCERPC_SERVICES
99

1010
NDR = Rex::Encoder::NDR
1111

12+
SC_MANAGER_ALL_ACCESS = 0xF003F
1213
SERVICE_ALL_ACCESS = 0x0F01FF
1314
ERROR_SUCCESS = 0x0
15+
ERROR_FILE_NOT_FOUND = 0x2
16+
ERROR_ACCESS_DENIED = 0x5
1417
ERROR_SERVICE_EXISTS = 0x431
1518

1619
# Calls OpenSCManagerW() to obtain a handle to the service control manager.
@@ -19,9 +22,9 @@ module Exploit::Remote::DCERPC_SERVICES
1922
# @param rhost [String] the target host.
2023
# @param access [Fixnum] the access flags requested.
2124
#
22-
# @return [String] the handle to the service control manager or nil if
23-
# the call is not successful.
24-
def dce_openscmanagerw(dcerpc, rhost, access = SERVICE_ALL_ACCESS)
25+
# @return [String, Integer] the handle to the service control manager or nil if
26+
# the call is not successful and the Windows error code
27+
def dce_openscmanagerw(dcerpc, rhost, access = SC_MANAGER_ALL_ACCESS)
2528
scm_handle = nil
2629
scm_status = nil
2730
stubdata =
@@ -40,7 +43,7 @@ def dce_openscmanagerw(dcerpc, rhost, access = SERVICE_ALL_ACCESS)
4043
print_error("#{peer} - Error getting scm handle: #{e}")
4144
end
4245

43-
scm_handle
46+
return scm_handle, scm_status
4447
end
4548

4649

@@ -103,7 +106,7 @@ def dce_createservicew(dcerpc, scm_handle, service_name, display_name, binary_pa
103106
begin
104107
response = dcerpc.call(0x0c, stubdata)
105108
if response
106-
svc_status = response[20,4].unpack('V').first
109+
svc_status = response[24,4].unpack('V').first
107110

108111
if svc_status == ERROR_SUCCESS
109112
svc_handle = response[4,20]

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module Exploit::Remote::SMB::Psexec
1515
include Msf::Exploit::Remote::DCERPC
1616
include Msf::Exploit::Remote::SMB::Authenticated
1717

18-
ERROR_FILE_NOT_FOUND = 0x2
19-
2018
def initialize(info = {})
2119
super
2220
register_options(
@@ -102,8 +100,11 @@ def psexec(command, disconnect=true)
102100
vprint_status("#{peer} - Bound to #{handle} ...")
103101
vprint_status("#{peer} - Obtaining a service manager handle...")
104102

105-
scm_handle = dce_openscmanagerw(dcerpc, datastore['RHOST'])
103+
scm_handle, scm_status = dce_openscmanagerw(dcerpc, datastore['RHOST'])
106104

105+
if scm_status == ERROR_ACCESS_DENIED
106+
print_error("#{peer} - ERROR_ACCESS_DENIED opening the Service Manager")
107+
end
107108
return false unless scm_handle
108109

109110
vprint_status("#{peer} - Creating the service...")
@@ -161,7 +162,7 @@ def psexec(command, disconnect=true)
161162
end
162163
ensure
163164
vprint_status("#{peer} - Closing service handle...")
164-
dce_closehandle(svc_handle)
165+
dce_closehandle(dcerpc, svc_handle)
165166
end
166167
end
167168
end

0 commit comments

Comments
 (0)