Skip to content

Commit 5ac1ee1

Browse files
author
Brent Cook
committed
fix http/s handler reference counting for pymet
add a persistent session counter to avoid stopping listening when pymet stages over http/s
1 parent 10e8cef commit 5ac1ee1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/msf/core/handler.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def initialize(info = {})
7777
# Initialize the pending_connections counter to 0
7878
self.pending_connections = 0
7979

80+
# Initialize the sessions counter to 0
81+
self.sessions = 0
82+
8083
# Create the waiter event with auto_reset set to false so that
8184
# if a session is ever created, waiting on it returns immediately.
8285
self.session_waiter_event = Rex::Sync::Event.new(false, false)
@@ -234,10 +237,14 @@ def register_session(session)
234237
# Decrement the pending connections counter now that we've processed
235238
# one session.
236239
self.pending_connections -= 1
240+
241+
# Count the number of sessions we have registered
242+
self.sessions += 1
237243
end
238244

239245
attr_accessor :session_waiter_event # :nodoc:
240246
attr_accessor :pending_connections # :nodoc:
247+
attr_accessor :sessions # :nodoc:
241248

242249
end
243250

lib/msf/core/handler/reverse_http.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def setup_handler
160160
def stop_handler
161161
if self.service
162162
self.service.remove_resource("/")
163-
Rex::ServiceManager.stop_service(self.service) if self.pending_connections == 0
163+
Rex::ServiceManager.stop_service(self.service) if self.sessions == 0
164164
end
165165
end
166166

@@ -217,6 +217,8 @@ def on_request(cli, req, obj)
217217

218218
uri_match = process_uri_resource(req.relative_resource)
219219

220+
self.pending_connections += 1
221+
220222
# Process the requested resource.
221223
case uri_match
222224
when /^\/INITPY/
@@ -252,7 +254,6 @@ def on_request(cli, req, obj)
252254
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
253255
:ssl => ssl?,
254256
})
255-
self.pending_connections += 1
256257

257258
when /^\/INITJM/
258259
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
@@ -340,6 +341,7 @@ def on_request(cli, req, obj)
340341
resp.code = 200
341342
resp.message = "OK"
342343
resp.body = datastore['HttpUnknownRequestResponse'].to_s
344+
self.pending_connections -= 1
343345
end
344346

345347
cli.send_response(resp) if (resp)

0 commit comments

Comments
 (0)