diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 2c4b98d30b..28bc298f57 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -12,10 +12,12 @@ class Core include Msf::Ui::Console::CommandDispatcher + # Session command options @@session_opts = Rex::Parser::Arguments.new( "-i" => [ true, "Interact with the supplied session identifier." ], "-h" => [ false, "Help banner." ], - "-l" => [ false, "List all active sessions." ]) + "-l" => [ false, "List all active sessions." ], + "-q" => [ false, "Quiet mode." ]) # Returns the list of commands supported by this command dispatcher def commands @@ -231,23 +233,20 @@ class Core end begin + method = nil + quiet = false + sid = nil + + # Parse the command options @@session_opts.parse(args) { |opt, idx, val| - sid = nil - case opt + when "-q" + quiet = true + # Interact with the supplied session identifier when "-i" - if ((session = framework.sessions.get(val))) - if (session.interactive?) - print_status("Starting interaction with #{session.name}...\n") - - session.interact - else - print_error("Session #{val} is non-interactive.") - end - else - print_error("Invalid session identifier: #{val}") - end + method = 'interact' + sid = val # Display the list of active sessions when "-l" @@ -263,6 +262,32 @@ class Core return false end } + + # Now, perform the actual method + case method + when 'interact' + if ((session = framework.sessions.get(sid))) + if (session.interactive?) + print_status("Starting interaction with #{session.name}...\n") if (quiet == false) + + # Set the session's input and output handles + session.linput = driver.input + session.loutput = driver.output + + # Interact + session.interact() + + # Once interact returns, swap the output handle with a + # none output + session.loutput = Rex::Ui::Output::None.new + else + print_error("Session #{sid} is non-interactive.") + end + else + print_error("Invalid session identifier: #{sid}") + end + end + rescue log_error("Session manipulation failed: #{$!}") end diff --git a/lib/msf/ui/console/command_dispatcher/exploit.rb b/lib/msf/ui/console/command_dispatcher/exploit.rb index d05f6fcdd8..e6a23d4e47 100644 --- a/lib/msf/ui/console/command_dispatcher/exploit.rb +++ b/lib/msf/ui/console/command_dispatcher/exploit.rb @@ -107,17 +107,13 @@ class Exploit # If we were given a session, let's see what we can do with it if (session) # If we aren't told to run in the background and the session can be - # interacted with, start interacting with it + # interacted with, start interacting with it by issuing the session + # interaction command. if (bg == false and session.interactive?) - # Set the session's input and output handles - session.linput = driver.input - session.loutput = driver.output - - # Interact - session.interact() + driver.run_single("session -q -i #{session.sid}") # Otherwise, log that we created a session else - print_status("Session #{session.id} created.") + print_status("Session #{session.sid} created.") end else print_status("Exploit completed, no session was created.")