Skip to content

Commit

Permalink
Added -c, -r, -v options to msfconsole
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/svn/incoming/trunk@3584 4d416f70-5f16-0410-b530-b9f4589650da
  • Loading branch information
HD Moore committed Apr 2, 2006
1 parent 86671ce commit 3aa4563
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
36 changes: 29 additions & 7 deletions lib/msf/ui/console/driver.rb
Expand Up @@ -75,7 +75,7 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
register_event_handlers

# Load console-specific configuration
load_config
load_config(opts['Config'])

# Re-enable output
self.disable_output = false
Expand All @@ -84,7 +84,7 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
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
Expand Down Expand Up @@ -112,9 +112,9 @@ def load_preconfig
#
# 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
Expand Down Expand Up @@ -151,14 +151,36 @@ def save_config
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.
Expand Down
55 changes: 54 additions & 1 deletion msfconsole
Expand Up @@ -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

0 comments on commit 3aa4563

Please sign in to comment.