Skip to content

Commit 3a2049e

Browse files
committed
Fixup open sm
1 parent f55d78c commit 3a2049e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/msf/core/exploit/dcerpc_services.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ module Exploit::Remote::DCERPC_SERVICES
1616
# @param rhost [String] the target host.
1717
# @param access [Fixnum] the access flags requested.
1818
#
19-
# @return [String] the handle to the service control manager.
19+
# @return [String] the handle to the service control manager or nil if
20+
# the call is not successful.
2021
def dce_openscmanagerw(dcerpc, rhost, access = 0xF003F)
2122
scm_handle = nil
2223
scm_status = nil
2324
stubdata =
2425
NDR.uwstring("\\\\#{rhost}") +
2526
NDR.long(0) +
2627
NDR.long(access)
27-
response = dcerpc.call(0x0f, stubdata)
28-
if dcerpc.last_response and dcerpc.last_response.stub_data
29-
scm_handle = dcerpc.last_response.stub_data[0,20]
30-
scm_status = dcerpc.last_response.stub_data[20,4]
28+
begin
29+
response = dcerpc.call(0x0f, stubdata)
30+
if response
31+
scm_status = response[20,4].unpack('V').first
32+
if scm_status == 0
33+
scm_handle = response[0,20]
34+
end
35+
end
36+
rescue Rex::Proto::DCERPC::Exceptions::Fault => e
37+
print_error("#{peer} - Error getting scm handle: #{e}")
3138
end
3239

33-
if scm_status.to_i != 0
34-
scm_handle = nil
35-
end
36-
return scm_handle
40+
scm_handle
3741
end
3842

3943

0 commit comments

Comments
 (0)