Skip to content

Commit d2ebab0

Browse files
committed
Add timeout for SSL renegotiation after migrating
[SeeRM rapid7#8794]
1 parent 773fd7a commit d2ebab0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def migrate( pid )
266266
end
267267

268268
# Send the migration request (bump up the timeout to 60 seconds)
269-
response = client.send_request( request, 60 )
269+
client.send_request( request, 60 )
270270

271271
if client.passive_service
272272
# Sleep for 5 seconds to allow the full handoff, this prevents
@@ -282,12 +282,25 @@ def migrate( pid )
282282
# Now communicating with the new process
283283
###
284284

285-
# Renegotiate SSL over this socket
286-
client.swap_sock_ssl_to_plain()
287-
client.swap_sock_plain_to_ssl()
285+
# If renegotiation takes longer than a minute, it's a pretty
286+
# good bet that migration failed and the remote side is hung.
287+
# Since we have the comm_mutex here, we *must* release it to
288+
# keep from hanging the packet dispatcher thread, which results
289+
# in blocking the entire process. See Redmine #8794
290+
begin
291+
Timeout.timeout(60) do
292+
# Renegotiate SSL over this socket
293+
client.swap_sock_ssl_to_plain()
294+
client.swap_sock_plain_to_ssl()
295+
end
296+
rescue TimeoutError
297+
client.alive = false
298+
return false
299+
end
288300

289301
# Restart the socket monitor
290302
client.monitor_socket
303+
291304
end
292305
end
293306

0 commit comments

Comments
 (0)