From a03e3bf8239297e1cf4dde2512744e2f4645cca4 Mon Sep 17 00:00:00 2001 From: James Lee Date: Mon, 14 Dec 2009 21:17:49 +0000 Subject: [PATCH] adds support for regular shell sessions when running commands with 'sessions -c'. Commands are run sequentially, so will take forever on large numbers of sessions. git-svn-id: file:///home/svn/framework3/trunk@7855 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/ui/console/command_dispatcher/core.rb | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index cba555d017..2eb8f1e5e9 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -1132,7 +1132,7 @@ class Core cmds.each do |cmd| framework.sessions.each_sorted do |s| session = framework.sessions.get(s) - print_status("Running '#{cmd}' on #{session.tunnel_peer}") + print_status("Running '#{cmd}' on session #{s} (#{session.tunnel_peer})") if (session.type == "meterpreter") c,args = cmd.split(' ', 2) begin @@ -1144,9 +1144,22 @@ class Core print_error("Failed: #{$!.class} #{$!}") end print_line(process.channel.read) if process and process.channel - else - # Just send the command to the session's stdin + elsif session.type == "shell" + # Then it's a regular shell, just send the command + # to the session's stdin. + session.write_shell(cmd + "\n") + # read_shell blocks with no timeout, so we wrap + # it in a select in case there is no output + # from the command + if select([session.rstream],nil,nil,3) + output = session.read_shell + print_line(output) + end end + # If the session isn't a meterpreter or shell type, it + # could be a VNC session (which can't run commands) or + # something custom (which we don't know how to run + # commands on), so don't bother. end end @@ -1209,7 +1222,7 @@ class Core framework.sessions.each_sorted do |s| if ((session = framework.sessions.get(s))) if (session.type == "meterpreter") - print_status("Session #{s}:") + print_status("Session #{s} (#{session.tunnel_peer}):") begin client = session client.execute_script(script, binding)