Skip to content

Commit 4d5695f

Browse files
committed
Land rapid7#6743, reimplement HD's session interrupt handler
MS-385
2 parents cde89b9 + 64b94df commit 4d5695f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/msf/core/exploit.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,9 +1197,15 @@ def handler_enabled?
11971197
# value can be one of the Handler::constants.
11981198
#
11991199
def handler(*args)
1200-
return if not payload_instance
1201-
return if not handler_enabled?
1202-
return payload_instance.handler(*args)
1200+
unless payload_instance && handler_enabled?
1201+
payload_instance.handler(*args)
1202+
end
1203+
end
1204+
1205+
def interrupt_handler
1206+
if payload_instance && handler_enabled? && payload_instance.respond_to?(:interrupt_wait_for_session)
1207+
payload_instance.interrupt_wait_for_session()
1208+
end
12031209
end
12041210

12051211
##
@@ -1351,6 +1357,9 @@ def handle_exception e
13511357

13521358
# Report the failure (and attempt) in the database
13531359
self.report_failure
1360+
1361+
# Interrupt any session waiters in the handler
1362+
self.interrupt_handler
13541363
end
13551364

13561365
def report_failure

lib/msf/core/handler.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ def wait_for_session(t = wfs_delay)
163163
return session
164164
end
165165

166+
#
167+
# Interrupts a wait_for_session call by notifying with a nil event
168+
#
169+
def interrupt_wait_for_session
170+
return unless session_waiter_event
171+
session_waiter_event.notify(nil)
172+
end
173+
166174
#
167175
# Set by the exploit module to configure handler
168176
#

0 commit comments

Comments
 (0)