remove superfluous sleeps, simplify logic
parent
4b767efd6c
commit
c06f13b33e
|
@ -142,54 +142,52 @@ module Exploit::Remote::SMB::Client::Psexec
|
||||||
if svc_handle.nil?
|
if svc_handle.nil?
|
||||||
print_error("No service handle retrieved")
|
print_error("No service handle retrieved")
|
||||||
return false
|
return false
|
||||||
else
|
end
|
||||||
|
|
||||||
if service_description
|
if service_description
|
||||||
vprint_status("Changing service description...")
|
vprint_status("Changing service description...")
|
||||||
svc_client.changeservicedescription(svc_handle, service_description)
|
svc_client.changeservicedescription(svc_handle, service_description)
|
||||||
|
end
|
||||||
|
|
||||||
|
vprint_status("Starting the service...")
|
||||||
|
begin
|
||||||
|
svc_status = svc_client.startservice(svc_handle)
|
||||||
|
case svc_status
|
||||||
|
when ERROR_SUCCESS
|
||||||
|
print_good("Service started successfully...")
|
||||||
|
when ERROR_FILE_NOT_FOUND
|
||||||
|
print_error("Service failed to start - FILE_NOT_FOUND")
|
||||||
|
when ERROR_ACCESS_DENIED
|
||||||
|
print_error("Service failed to start - ACCESS_DENIED")
|
||||||
|
when ERROR_SERVICE_REQUEST_TIMEOUT
|
||||||
|
print_good("Service start timed out, OK if running a command or non-service executable...")
|
||||||
|
else
|
||||||
|
print_error("Service failed to start, ERROR_CODE: #{svc_status}")
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
vprint_status("Starting the service...")
|
|
||||||
begin
|
begin
|
||||||
svc_status = svc_client.startservice(svc_handle)
|
# If service already exists don't delete it!
|
||||||
case svc_status
|
# Maybe we could have a force cleanup option..?
|
||||||
when ERROR_SUCCESS
|
if service_exists
|
||||||
print_good("Service started successfully...")
|
print_warning("Not removing service as it already existed...")
|
||||||
when ERROR_FILE_NOT_FOUND
|
elsif datastore['SERVICE_PERSIST']
|
||||||
print_error("Service failed to start - FILE_NOT_FOUND")
|
print_warning("Not removing service for persistence...")
|
||||||
when ERROR_ACCESS_DENIED
|
|
||||||
print_error("Service failed to start - ACCESS_DENIED")
|
|
||||||
when ERROR_SERVICE_REQUEST_TIMEOUT
|
|
||||||
print_good("Service start timed out, OK if running a command or non-service executable...")
|
|
||||||
else
|
else
|
||||||
print_error("Service failed to start, ERROR_CODE: #{svc_status}")
|
vprint_status("Removing the service...")
|
||||||
|
svc_status = svc_client.deleteservice(svc_handle)
|
||||||
|
if svc_status == ERROR_SUCCESS
|
||||||
|
vprint_good("Successfully removed the service")
|
||||||
|
else
|
||||||
|
print_error("Unable to remove the service, ERROR_CODE: #{svc_status}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
begin
|
vprint_status("Closing service handle...")
|
||||||
# If service already exists don't delete it!
|
svc_client.closehandle(svc_handle)
|
||||||
# Maybe we could have a force cleanup option..?
|
|
||||||
if service_exists
|
|
||||||
print_warning("Not removing service as it already existed...")
|
|
||||||
elsif datastore['SERVICE_PERSIST']
|
|
||||||
print_warning("Not removing service for persistence...")
|
|
||||||
else
|
|
||||||
vprint_status("Removing the service...")
|
|
||||||
svc_status = svc_client.deleteservice(svc_handle)
|
|
||||||
if svc_status == ERROR_SUCCESS
|
|
||||||
vprint_good("Successfully removed the service")
|
|
||||||
else
|
|
||||||
print_error("Unable to remove the service, ERROR_CODE: #{svc_status}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
vprint_status("Closing service handle...")
|
|
||||||
svc_client.closehandle(svc_handle)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if disconnect
|
if disconnect
|
||||||
sleep(1)
|
|
||||||
simple.disconnect("\\\\#{datastore['RHOST']}\\IPC$")
|
simple.disconnect("\\\\#{datastore['RHOST']}\\IPC$")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -260,8 +260,6 @@ require 'rex/proto/smb/exceptions'
|
||||||
|
|
||||||
raw_response = ''
|
raw_response = ''
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
raw_response = self.read()
|
raw_response = self.read()
|
||||||
rescue ::EOFError
|
rescue ::EOFError
|
||||||
|
@ -272,7 +270,6 @@ require 'rex/proto/smb/exceptions'
|
||||||
raise Rex::Proto::DCERPC::Exceptions::NoResponse
|
raise Rex::Proto::DCERPC::Exceptions::NoResponse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
self.last_response = Rex::Proto::DCERPC::Response.new(raw_response)
|
self.last_response = Rex::Proto::DCERPC::Response.new(raw_response)
|
||||||
|
|
||||||
if self.last_response.type == 3
|
if self.last_response.type == 3
|
||||||
|
|
Loading…
Reference in New Issue