2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-11-28 21:38:48 +00:00
|
|
|
#
|
2010-05-03 17:13:09 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
2005-11-28 21:38:48 +00:00
|
|
|
# This user interface provides users with a command console interface to the
|
|
|
|
# framework.
|
|
|
|
#
|
2010-05-03 17:13:09 +00:00
|
|
|
# $Revision$
|
|
|
|
#
|
2005-07-13 21:09:07 +00:00
|
|
|
|
2009-01-30 06:27:10 +00:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
|
|
|
end
|
|
|
|
|
2008-11-16 21:10:35 +00:00
|
|
|
$:.unshift(File.join(File.expand_path(File.dirname(msfbase)), 'lib'))
|
2008-02-02 21:29:46 +00:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2005-05-22 19:39:21 +00:00
|
|
|
|
2006-04-02 16:28:02 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
2007-02-21 15:15:59 +00:00
|
|
|
if(RUBY_PLATFORM =~ /mswin32/)
|
2007-02-21 15:14:55 +00: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"
|
2010-10-14 18:45:16 +00:00
|
|
|
$stderr.puts " be handled correctly. Please install Cygwin or use Linux in VMWare.\n\n"
|
2007-02-21 15:10:56 +00:00
|
|
|
end
|
|
|
|
|
2006-04-02 16:28:02 +00: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 04:48:35 +00:00
|
|
|
opts.on("-d", "-d", "Execute the console as defanged") do
|
|
|
|
options['Defanged'] = true
|
|
|
|
end
|
2006-04-02 16:28:02 +00:00
|
|
|
|
|
|
|
opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
|
2010-02-02 23:13:42 +00:00
|
|
|
options['Resource'] ||= []
|
|
|
|
options['Resource'] << r
|
2006-04-02 16:28:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
|
|
|
|
options['Config'] = c
|
|
|
|
end
|
|
|
|
|
2007-02-24 05:29:05 +00:00
|
|
|
opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m|
|
|
|
|
options['ModulePath'] = m
|
|
|
|
end
|
|
|
|
|
2006-04-02 16:28:02 +00:00
|
|
|
# Boolean switch.
|
|
|
|
opts.on("-v", "--version", "Show version") do |v|
|
|
|
|
options['Version'] = true
|
|
|
|
end
|
2010-05-03 17:13:09 +00:00
|
|
|
|
2009-10-02 14:17:03 +00: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 17:13:09 +00:00
|
|
|
|
2010-08-05 02:24:40 +00:00
|
|
|
# Boolean switch.
|
|
|
|
opts.on("-n", "--no-database", "Disable database support") do |v|
|
|
|
|
options['DisableDatabase'] = true
|
|
|
|
end
|
|
|
|
|
2006-04-02 16:28:02 +00:00
|
|
|
opts.separator ""
|
|
|
|
opts.separator "Common options:"
|
|
|
|
|
|
|
|
opts.on_tail("-h", "--help", "Show this message") do
|
|
|
|
puts opts
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-29 23:47:03 +00:00
|
|
|
begin
|
|
|
|
opts.parse!(args)
|
|
|
|
rescue OptionParser::InvalidOption
|
|
|
|
puts "Invalid option, try -h for usage"
|
|
|
|
exit
|
|
|
|
end
|
2009-02-15 19:27:53 +00:00
|
|
|
|
|
|
|
options
|
2006-04-02 16:28:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
options = OptsConsole.parse(ARGV)
|
2010-05-25 22:29:01 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# NOTE: we don't require this until down here since we may not need it
|
|
|
|
# when processing certain options (currently only -h)
|
|
|
|
#
|
2010-10-09 00:06:30 +00:00
|
|
|
require 'rex'
|
2010-05-25 22:29:01 +00:00
|
|
|
require 'msf/ui'
|
2010-10-09 00:06:30 +00:00
|
|
|
|
2010-05-25 22:29:01 +00:00
|
|
|
#
|
|
|
|
# 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 16:28:02 +00:00
|
|
|
if (options['Version'])
|
|
|
|
$stderr.puts 'Framework Version: ' + Msf::Framework::Version
|
|
|
|
exit
|
|
|
|
end
|
2005-05-22 19:39:21 +00:00
|
|
|
|
2005-12-13 06:27:34 +00:00
|
|
|
begin
|
2006-04-02 16:28:02 +00:00
|
|
|
Msf::Ui::Console::Driver.new(
|
|
|
|
Msf::Ui::Console::Driver::DefaultPrompt,
|
|
|
|
Msf::Ui::Console::Driver::DefaultPromptChar,
|
|
|
|
options
|
|
|
|
).run
|
2005-12-13 06:27:34 +00:00
|
|
|
rescue Interrupt
|
2008-11-16 21:10:35 +00:00
|
|
|
end
|