Skip to content

Commit b3e8c33

Browse files
committed
Land rapid7#7788, Add ability to interact with a manually backgrouned session
2 parents 8c39533 + 10cfada commit b3e8c33

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,23 @@ def queue_cmd(cmd)
277277
#
278278
# Explicitly runs a command in the meterpreter console.
279279
#
280-
def run_cmd(cmd)
281-
console.run_single(cmd)
280+
def run_cmd(cmd,output_object=nil)
281+
stored_output_state = nil
282+
# If the user supplied an Output IO object, then we tell
283+
# the console to use that, while saving it's previous output/
284+
if output_object
285+
stored_output_state = console.output
286+
console.send(:output=, output_object)
287+
end
288+
success = console.run_single(cmd)
289+
# If we stored the previous output object of the channel
290+
# we restore it here to put everything back the way we found it
291+
# We re-use the conditional above, because we expect in many cases for
292+
# the stored state to actually be nil here.
293+
if output_object
294+
console.send(:output=,stored_output_state)
295+
end
296+
success
282297
end
283298

284299
#

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ def cmd_sessions(*args)
12361236
session.response_timeout = response_timeout
12371237
end
12381238

1239-
output = session.run_cmd cmd
1239+
output = session.run_cmd(cmd, driver.output)
12401240
end
12411241
end
12421242
when 'kill'

0 commit comments

Comments
 (0)