2005-12-17 07:46:23 +01:00
|
|
|
#!/usr/bin/env ruby
|
2005-11-28 22:38:48 +01:00
|
|
|
#
|
2010-05-03 19:13:09 +02:00
|
|
|
# $Id$
|
|
|
|
#
|
2005-11-28 22:38:48 +01:00
|
|
|
# This user interface provides users with a command console interface to the
|
|
|
|
# framework.
|
|
|
|
#
|
2010-05-03 19:13:09 +02:00
|
|
|
# $Revision$
|
|
|
|
#
|
2005-07-13 23:09:07 +02:00
|
|
|
|
2009-01-30 07:27:10 +01:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
|
|
|
end
|
|
|
|
|
2008-11-16 22:10:35 +01:00
|
|
|
$:.unshift(File.join(File.expand_path(File.dirname(msfbase)), 'lib'))
|
2008-02-02 22:29:46 +01:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2005-05-22 21:39:21 +02:00
|
|
|
|
2005-07-09 23:22:32 +02:00
|
|
|
require 'rex'
|
2006-04-02 18:28:02 +02:00
|
|
|
require 'optparse'
|
|
|
|
|
2007-02-21 16:15:59 +01:00
|
|
|
if(RUBY_PLATFORM =~ /mswin32/)
|
2007-02-21 16:14:55 +01:00
|
|
|
$stderr.puts "[*] The msfconsole interface is not supported on the native Windows Ruby\n"
|
|
|
|
$stderr.puts " interpreter. Things will break, exploits will fail, payloads will not\n"
|
|
|
|
$stderr.puts " be handled correctly. Please use the msfweb 'console' or install \n"
|
|
|
|
$stderr.puts " Cygwin or Linux in VMWare.\n\n"
|
2007-02-21 16:10:56 +01:00
|
|
|
end
|
|
|
|
|
2006-04-02 18:28:02 +02:00
|
|
|
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:"
|
|
|
|
|
2007-01-30 05:48:35 +01:00
|
|
|
opts.on("-d", "-d", "Execute the console as defanged") do
|
|
|
|
options['Defanged'] = true
|
|
|
|
end
|
2006-04-02 18:28:02 +02:00
|
|
|
|
|
|
|
opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
|
2010-02-03 00:13:42 +01:00
|
|
|
options['Resource'] ||= []
|
|
|
|
options['Resource'] << r
|
2006-04-02 18:28:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
|
|
|
|
options['Config'] = c
|
|
|
|
end
|
|
|
|
|
2007-02-24 06:29:05 +01:00
|
|
|
opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m|
|
|
|
|
options['ModulePath'] = m
|
|
|
|
end
|
|
|
|
|
2006-04-02 18:28:02 +02:00
|
|
|
# Boolean switch.
|
|
|
|
opts.on("-v", "--version", "Show version") do |v|
|
|
|
|
options['Version'] = true
|
|
|
|
end
|
2010-05-03 19:13:09 +02:00
|
|
|
|
2009-10-02 16:17:03 +02:00
|
|
|
# Boolean switch.
|
|
|
|
opts.on("-L", "--real-readline", "Use the system Readline library instead of RbReadline") do |v|
|
|
|
|
options['RealReadline'] = true
|
|
|
|
end
|
2010-05-03 19:13:09 +02:00
|
|
|
|
2006-04-02 18:28:02 +02:00
|
|
|
opts.separator ""
|
|
|
|
opts.separator "Common options:"
|
|
|
|
|
|
|
|
opts.on_tail("-h", "--help", "Show this message") do
|
|
|
|
puts opts
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-30 00:47:03 +01:00
|
|
|
begin
|
|
|
|
opts.parse!(args)
|
|
|
|
rescue OptionParser::InvalidOption
|
|
|
|
puts "Invalid option, try -h for usage"
|
|
|
|
exit
|
|
|
|
end
|
2009-02-15 20:27:53 +01:00
|
|
|
|
|
|
|
options
|
2006-04-02 18:28:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
options = OptsConsole.parse(ARGV)
|
2010-05-26 00:29:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# NOTE: we don't require this until down here since we may not need it
|
|
|
|
# when processing certain options (currently only -h)
|
|
|
|
#
|
|
|
|
require 'msf/ui'
|
|
|
|
#
|
|
|
|
# Everything below this line requires the framework.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# XXX: It would be nice to not have to load the entire framework just to get
|
|
|
|
# the version number.
|
|
|
|
#
|
2006-04-02 18:28:02 +02:00
|
|
|
if (options['Version'])
|
|
|
|
$stderr.puts 'Framework Version: ' + Msf::Framework::Version
|
|
|
|
exit
|
|
|
|
end
|
2005-05-22 21:39:21 +02:00
|
|
|
|
2005-12-13 07:27:34 +01:00
|
|
|
begin
|
2006-04-02 18:28:02 +02:00
|
|
|
Msf::Ui::Console::Driver.new(
|
|
|
|
Msf::Ui::Console::Driver::DefaultPrompt,
|
|
|
|
Msf::Ui::Console::Driver::DefaultPromptChar,
|
|
|
|
options
|
|
|
|
).run
|
2005-12-13 07:27:34 +01:00
|
|
|
rescue Interrupt
|
2008-11-16 22:10:35 +01:00
|
|
|
end
|