From 56d5c1375545f7e34247b061b460d79d819e9de6 Mon Sep 17 00:00:00 2001 From: kernelsmith Date: Thu, 20 Sep 2012 12:23:48 -0500 Subject: [PATCH 1/2] adds -s Execute the specified string as console commands to msfconsole for convenience when you don't need/want a full resource file, you just want to run something quick example usage: # say you have a saved config ready to go on load ./msfconsole -s 'exploit -j' # you can run multiple commands too ./msfconsole -s 'set ConsoleLogging true\nshow options' --- lib/msf/ui/console/driver.rb | 7 +++++++ msfconsole | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lib/msf/ui/console/driver.rb b/lib/msf/ui/console/driver.rb index 399c0781c2..00547a5aed 100644 --- a/lib/msf/ui/console/driver.rb +++ b/lib/msf/ui/console/driver.rb @@ -249,6 +249,13 @@ class Driver < Msf::Ui::Driver # If the opt is nil here, we load ~/.msf3/msfconsole.rc load_resource(opts['Resource']) end + + # Process any additional startup commands + if opts['SCommands'] and opts['SCommands'].kind_of? Array + opts['SCommands'].each { |c| + run_single(c) + } + end end # diff --git a/msfconsole b/msfconsole index c21594147f..17296a4c30 100755 --- a/msfconsole +++ b/msfconsole @@ -101,6 +101,11 @@ class OptsConsole options['DisableBanner'] = true end + opts.on("-s", "-s ", "Execute the specified string as console commands") do |s| + options['SCommands'] ||= [] + options['SCommands'] += s.split('\n') + end + opts.separator "" opts.separator "Common options:" From cf8edf8570306e46f219adc891f9c41de9d74978 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Thu, 20 Sep 2012 13:34:29 -0500 Subject: [PATCH 2/2] Touchups to msfconsole command parsing Move from -s to -x and use a semicolon. --- lib/msf/ui/console/driver.rb | 4 ++-- msfconsole | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/msf/ui/console/driver.rb b/lib/msf/ui/console/driver.rb index 00547a5aed..eac24a576d 100644 --- a/lib/msf/ui/console/driver.rb +++ b/lib/msf/ui/console/driver.rb @@ -251,8 +251,8 @@ class Driver < Msf::Ui::Driver end # Process any additional startup commands - if opts['SCommands'] and opts['SCommands'].kind_of? Array - opts['SCommands'].each { |c| + if opts['XCommands'] and opts['XCommands'].kind_of? Array + opts['XCommands'].each { |c| run_single(c) } end diff --git a/msfconsole b/msfconsole index 17296a4c30..ea8add619e 100755 --- a/msfconsole +++ b/msfconsole @@ -101,9 +101,9 @@ class OptsConsole options['DisableBanner'] = true end - opts.on("-s", "-s ", "Execute the specified string as console commands") do |s| - options['SCommands'] ||= [] - options['SCommands'] += s.split('\n') + opts.on("-x", "-x ", "Execute the specified string as console commands (use ; for multiples)") do |s| + options['XCommands'] ||= [] + options['XCommands'] += s.split(/\s*;\s*/) end opts.separator ""