remove superfluous sleeps, simplify logic

GSoC/Meterpreter_Web_Console
Brent Cook 2018-06-25 17:24:43 -05:00 committed by Jacob Robles
parent 4b767efd6c
commit c06f13b33e
No known key found for this signature in database
GPG Key ID: 3EC9F18F2B12401C
2 changed files with 36 additions and 41 deletions

View File

@ -142,54 +142,52 @@ module Exploit::Remote::SMB::Client::Psexec
if svc_handle.nil?
print_error("No service handle retrieved")
return false
else
end
if service_description
vprint_status("Changing service description...")
svc_client.changeservicedescription(svc_handle, service_description)
if service_description
vprint_status("Changing 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
vprint_status("Starting the service...")
ensure
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...")
# If service already exists don't delete it!
# 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
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
ensure
begin
# If service already exists don't delete it!
# 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
vprint_status("Closing service handle...")
svc_client.closehandle(svc_handle)
end
end
if disconnect
sleep(1)
simple.disconnect("\\\\#{datastore['RHOST']}\\IPC$")
end

View File

@ -260,8 +260,6 @@ require 'rex/proto/smb/exceptions'
raw_response = ''
sleep 3
begin
raw_response = self.read()
rescue ::EOFError
@ -272,7 +270,6 @@ require 'rex/proto/smb/exceptions'
raise Rex::Proto::DCERPC::Exceptions::NoResponse
end
self.last_response = Rex::Proto::DCERPC::Response.new(raw_response)
if self.last_response.type == 3