Added -c, -r, -v options to msfconsole

git-svn-id: file:///home/svn/incoming/trunk@3584 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2006-04-02 16:28:02 +00:00
parent 86671cef89
commit 3aa45638df
2 changed files with 83 additions and 8 deletions

View File

@ -75,7 +75,7 @@ class Driver < Msf::Ui::Driver
register_event_handlers register_event_handlers
# Load console-specific configuration # Load console-specific configuration
load_config load_config(opts['Config'])
# Re-enable output # Re-enable output
self.disable_output = false self.disable_output = false
@ -84,7 +84,7 @@ class Driver < Msf::Ui::Driver
on_startup on_startup
# Process the resource script # Process the resource script
process_rc_file load_resource(opts['Resource'])
# Whether or not command passthru should be allowed # Whether or not command passthru should be allowed
self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true
@ -112,9 +112,9 @@ class Driver < Msf::Ui::Driver
# #
# Loads configuration for the console. # Loads configuration for the console.
# #
def load_config def load_config(path=nil)
begin begin
conf = Msf::Config.load conf = Msf::Config.load(path)
rescue rescue
wlog("Failed to load configuration: #{$!}") wlog("Failed to load configuration: #{$!}")
return return
@ -151,12 +151,34 @@ class Driver < Msf::Ui::Driver
end end
end end
#
# TODO:
# #
# Processes the resource script file for the console. # Processes the resource script file for the console.
# #
def process_rc_file def load_resource(path=nil)
path ||= File.join(Msf::Config.config_directory, 'msfconsole.rc')
return if not File.readable?(path)
rcfd = File.open(path, 'r')
rcfd.each_line do |line|
print_line("resource> #{line.strip}")
run_single(line.strip)
end
rcfd.close
end
#
# Creates the resource script file for the console.
#
def save_resource(data, path=nil)
path ||= File.join(Msf::Config.config_directory, 'msfconsole.rc')
begin
rcfd = File.open(path, 'w')
rcfd.write(data)
rcfd.close
rescue ::Exception => e
#
end
end end
# #

View File

@ -8,8 +8,61 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'rex' require 'rex'
require 'msf/ui' require 'msf/ui'
require 'optparse'
class OptsConsole
#
# Return a hash describing the options.
#
def self.parse(args)
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: msfconsole [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
options['Resource'] = r
end
opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
options['Config'] = c
end
# Boolean switch.
opts.on("-v", "--version", "Show version") do |v|
options['Version'] = true
end
opts.separator ""
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
opts.parse!(args)
options
end
end
options = OptsConsole.parse(ARGV)
if (options['Version'])
$stderr.puts 'Framework Version: ' + Msf::Framework::Version
exit
end
begin begin
Msf::Ui::Console::Driver.new.run Msf::Ui::Console::Driver.new(
Msf::Ui::Console::Driver::DefaultPrompt,
Msf::Ui::Console::Driver::DefaultPromptChar,
options
).run
rescue Interrupt rescue Interrupt
end end