Added -c, -r, -v options to msfconsole
git-svn-id: file:///home/svn/incoming/trunk@3584 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
86671cef89
commit
3aa45638df
|
@ -75,7 +75,7 @@ class Driver < Msf::Ui::Driver
|
|||
register_event_handlers
|
||||
|
||||
# Load console-specific configuration
|
||||
load_config
|
||||
load_config(opts['Config'])
|
||||
|
||||
# Re-enable output
|
||||
self.disable_output = false
|
||||
|
@ -84,7 +84,7 @@ class Driver < Msf::Ui::Driver
|
|||
on_startup
|
||||
|
||||
# Process the resource script
|
||||
process_rc_file
|
||||
load_resource(opts['Resource'])
|
||||
|
||||
# Whether or not command passthru should be allowed
|
||||
self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true
|
||||
|
@ -112,9 +112,9 @@ class Driver < Msf::Ui::Driver
|
|||
#
|
||||
# Loads configuration for the console.
|
||||
#
|
||||
def load_config
|
||||
def load_config(path=nil)
|
||||
begin
|
||||
conf = Msf::Config.load
|
||||
conf = Msf::Config.load(path)
|
||||
rescue
|
||||
wlog("Failed to load configuration: #{$!}")
|
||||
return
|
||||
|
@ -151,14 +151,36 @@ class Driver < Msf::Ui::Driver
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# TODO:
|
||||
#
|
||||
# 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
|
||||
|
||||
#
|
||||
# Called before things actually get rolling such that banners can be
|
||||
# displayed, scripts can be processed, and other fun can be had.
|
||||
|
|
55
msfconsole
55
msfconsole
|
@ -8,8 +8,61 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
|||
|
||||
require 'rex'
|
||||
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
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue