From cc4b13a0a0470f52e199801571aa5510633b01c3 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Wed, 24 Feb 2010 04:46:59 +0000 Subject: [PATCH] check for empty args to sessions -c git-svn-id: file:///home/svn/framework3/trunk@8616 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/ui/console/command_dispatcher/core.rb | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 62c4960b21..212f476dda 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -1083,10 +1083,12 @@ class Core when "-q" quiet = true + # Run a command on all sessions when "-c" method = 'cmd' - cmds << val - + if (val) + cmds << val + end when "-v" verbose = true @@ -1094,7 +1096,7 @@ class Core # Interact with the supplied session identifier when "-i" method = 'interact' - sid = val + sid = val # Display the list of active sessions when "-l" @@ -1111,6 +1113,7 @@ class Core method = 'detach' sid = val + # Run a script on all meterpreter sessions when "-s" method = 'scriptall' script = val @@ -1129,32 +1132,36 @@ class Core case method when 'cmd' - cmds.each do |cmd| - framework.sessions.each_sorted do |s| - session = framework.sessions.get(s) - print_status("Running '#{cmd}' on session #{s} (#{session.tunnel_peer})") - if (session.type == "meterpreter") - c,args = cmd.split(' ', 2) - begin - process = session.sys.process.execute(c, args, { - 'Channelized' => true, - 'Hidden' => true - }) - rescue ::Rex::Post::Meterpreter::RequestError - print_error("Failed: #{$!.class} #{$!}") - end - print_line(process.channel.read) if process and process.channel - elsif session.type == "shell" - output = session.shell_command(cmd) - if (output) - print_line(output) + if (cmds.length > 0) + cmds.each do |cmd| + framework.sessions.each_sorted do |s| + session = framework.sessions.get(s) + print_status("Running '#{cmd}' on session #{s} (#{session.tunnel_peer})") + if (session.type == "meterpreter") + c,args = cmd.split(' ', 2) + begin + process = session.sys.process.execute(c, args, { + 'Channelized' => true, + 'Hidden' => true + }) + rescue ::Rex::Post::Meterpreter::RequestError + print_error("Failed: #{$!.class} #{$!}") + end + print_line(process.channel.read) if process and process.channel + elsif session.type == "shell" + output = session.shell_command(cmd) + if (output) + 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 - # 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 + else + print_error("No command specified!") end when 'kill'