fix http/s handler reference counting for pymet

add a persistent session counter to avoid stopping listening when pymet stages over http/s
bug/bundler_fix
Brent Cook 2015-03-26 18:26:56 -05:00
parent 10e8cefd6d
commit 5ac1ee1d73
2 changed files with 11 additions and 2 deletions

View File

@ -77,6 +77,9 @@ module Handler
# Initialize the pending_connections counter to 0 # Initialize the pending_connections counter to 0
self.pending_connections = 0 self.pending_connections = 0
# Initialize the sessions counter to 0
self.sessions = 0
# Create the waiter event with auto_reset set to false so that # Create the waiter event with auto_reset set to false so that
# if a session is ever created, waiting on it returns immediately. # if a session is ever created, waiting on it returns immediately.
self.session_waiter_event = Rex::Sync::Event.new(false, false) self.session_waiter_event = Rex::Sync::Event.new(false, false)
@ -234,10 +237,14 @@ protected
# Decrement the pending connections counter now that we've processed # Decrement the pending connections counter now that we've processed
# one session. # one session.
self.pending_connections -= 1 self.pending_connections -= 1
# Count the number of sessions we have registered
self.sessions += 1
end end
attr_accessor :session_waiter_event # :nodoc: attr_accessor :session_waiter_event # :nodoc:
attr_accessor :pending_connections # :nodoc: attr_accessor :pending_connections # :nodoc:
attr_accessor :sessions # :nodoc:
end end

View File

@ -160,7 +160,7 @@ module ReverseHttp
def stop_handler def stop_handler
if self.service if self.service
self.service.remove_resource("/") self.service.remove_resource("/")
Rex::ServiceManager.stop_service(self.service) if self.pending_connections == 0 Rex::ServiceManager.stop_service(self.service) if self.sessions == 0
end end
end end
@ -217,6 +217,8 @@ protected
uri_match = process_uri_resource(req.relative_resource) uri_match = process_uri_resource(req.relative_resource)
self.pending_connections += 1
# Process the requested resource. # Process the requested resource.
case uri_match case uri_match
when /^\/INITPY/ when /^\/INITPY/
@ -252,7 +254,6 @@ protected
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i, :comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
:ssl => ssl?, :ssl => ssl?,
}) })
self.pending_connections += 1
when /^\/INITJM/ when /^\/INITJM/
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16) conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
@ -340,6 +341,7 @@ protected
resp.code = 200 resp.code = 200
resp.message = "OK" resp.message = "OK"
resp.body = datastore['HttpUnknownRequestResponse'].to_s resp.body = datastore['HttpUnknownRequestResponse'].to_s
self.pending_connections -= 1
end end
cli.send_response(resp) if (resp) cli.send_response(resp) if (resp)