2005-12-17 14:46:23 +08:00
|
|
|
#!/usr/bin/env ruby
|
2005-11-29 05:38:48 +08:00
|
|
|
#
|
2010-05-04 01:13:09 +08:00
|
|
|
# $Id$
|
|
|
|
#
|
2005-11-29 05:38:48 +08:00
|
|
|
# This user interface provides users with a command console interface to the
|
|
|
|
# framework.
|
|
|
|
#
|
2010-05-04 01:13:09 +08:00
|
|
|
# $Revision$
|
|
|
|
#
|
2005-07-14 05:09:07 +08:00
|
|
|
|
2009-01-30 14:27:10 +08:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
|
|
|
end
|
|
|
|
|
2011-11-22 04:18:57 +08:00
|
|
|
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
|
|
|
|
require 'fastlib'
|
|
|
|
|
2011-11-24 13:02:43 +08:00
|
|
|
'))
|
2011-11-22 04:18:57 +08:00
|
|
|
|
2008-02-03 05:29:46 +08:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2005-05-23 03:39:21 +08:00
|
|
|
|
2006-04-03 00:28:02 +08:00
|
|
|
require 'optparse'
|
|
|
|
|
2007-02-21 23:15:59 +08:00
|
|
|
if(RUBY_PLATFORM =~ /mswin32/)
|
2007-02-21 23:14:55 +08: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-15 02:45:16 +08:00
|
|
|
$stderr.puts " be handled correctly. Please install Cygwin or use Linux in VMWare.\n\n"
|
2007-02-21 23:10:56 +08:00
|
|
|
end
|
|
|
|
|
2006-04-03 00:28:02 +08: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 12:48:35 +08:00
|
|
|
opts.on("-d", "-d", "Execute the console as defanged") do
|
|
|
|
options['Defanged'] = true
|
|
|
|
end
|
2006-04-03 00:28:02 +08:00
|
|
|
|
|
|
|
opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
|
2010-02-03 07:13:42 +08:00
|
|
|
options['Resource'] ||= []
|
|
|
|
options['Resource'] << r
|
2006-04-03 00:28:02 +08:00
|
|
|
end
|
|
|
|
|
2010-12-29 04:24:17 +08:00
|
|
|
opts.on("-o", "-o <filename>", "Output to the specified file") do |o|
|
|
|
|
options['LocalOutput'] = o
|
|
|
|
end
|
|
|
|
|
2006-04-03 00:28:02 +08:00
|
|
|
opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c|
|
|
|
|
options['Config'] = c
|
|
|
|
end
|
|
|
|
|
2007-02-24 13:29:05 +08:00
|
|
|
opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m|
|
|
|
|
options['ModulePath'] = m
|
|
|
|
end
|
|
|
|
|
2011-02-14 06:19:43 +08:00
|
|
|
opts.on("-p", "-p <plugin>", "Load a plugin on startup") do |p|
|
|
|
|
options['Plugins'] ||= []
|
|
|
|
options['Plugins'] << p
|
|
|
|
end
|
|
|
|
|
2010-10-19 15:51:58 +08:00
|
|
|
opts.on("-y", "--yaml <database.yml>", "Specify a YAML file containing database settings") do |m|
|
|
|
|
options['DatabaseYAML'] = m
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-e", "--environment <production|development>", "Specify the database environment to load from the YAML") do |m|
|
|
|
|
options['DatabaseEnv'] = m
|
|
|
|
end
|
2011-01-26 06:58:21 +08:00
|
|
|
|
|
|
|
# Boolean switches
|
2006-04-03 00:28:02 +08:00
|
|
|
opts.on("-v", "--version", "Show version") do |v|
|
|
|
|
options['Version'] = true
|
|
|
|
end
|
2010-05-04 01:13:09 +08:00
|
|
|
|
2009-10-02 22:17:03 +08:00
|
|
|
opts.on("-L", "--real-readline", "Use the system Readline library instead of RbReadline") do |v|
|
|
|
|
options['RealReadline'] = true
|
|
|
|
end
|
2010-05-04 01:13:09 +08:00
|
|
|
|
2010-08-05 10:24:40 +08:00
|
|
|
opts.on("-n", "--no-database", "Disable database support") do |v|
|
|
|
|
options['DisableDatabase'] = true
|
|
|
|
end
|
|
|
|
|
2011-01-26 06:58:21 +08:00
|
|
|
opts.on("-q", "--quiet", "Do not print the banner on start up") do |v|
|
|
|
|
options['DisableBanner'] = true
|
|
|
|
end
|
|
|
|
|
2006-04-03 00:28:02 +08:00
|
|
|
opts.separator ""
|
|
|
|
opts.separator "Common options:"
|
|
|
|
|
|
|
|
opts.on_tail("-h", "--help", "Show this message") do
|
|
|
|
puts opts
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-30 07:47:03 +08:00
|
|
|
begin
|
|
|
|
opts.parse!(args)
|
|
|
|
rescue OptionParser::InvalidOption
|
|
|
|
puts "Invalid option, try -h for usage"
|
|
|
|
exit
|
|
|
|
end
|
2009-02-16 03:27:53 +08:00
|
|
|
|
|
|
|
options
|
2006-04-03 00:28:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
options = OptsConsole.parse(ARGV)
|
2010-05-26 06:29:01 +08: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 08:06:30 +08:00
|
|
|
require 'rex'
|
2010-05-26 06:29:01 +08:00
|
|
|
require 'msf/ui'
|
2010-10-09 08:06:30 +08:00
|
|
|
|
2010-05-26 06:29:01 +08:00
|
|
|
#
|
|
|
|
# Everything below this line requires the framework.
|
|
|
|
#
|
|
|
|
|
2006-04-03 00:28:02 +08:00
|
|
|
if (options['Version'])
|
|
|
|
$stderr.puts 'Framework Version: ' + Msf::Framework::Version
|
|
|
|
exit
|
|
|
|
end
|
2005-05-23 03:39:21 +08:00
|
|
|
|
2005-12-13 14:27:34 +08:00
|
|
|
begin
|
2006-04-03 00:28:02 +08:00
|
|
|
Msf::Ui::Console::Driver.new(
|
|
|
|
Msf::Ui::Console::Driver::DefaultPrompt,
|
|
|
|
Msf::Ui::Console::Driver::DefaultPromptChar,
|
|
|
|
options
|
|
|
|
).run
|
2005-12-13 14:27:34 +08:00
|
|
|
rescue Interrupt
|
2008-11-17 05:10:35 +08:00
|
|
|
end
|