| 1 |
#!/usr/bin/env ruby |
|---|
| 2 |
# |
|---|
| 3 |
# This user interface provides users with a command console interface to the |
|---|
| 4 |
# framework. |
|---|
| 5 |
# |
|---|
| 6 |
|
|---|
| 7 |
msfbase = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ |
|---|
| 8 |
$:.unshift(File.join(File.dirname(msfbase), 'lib')) |
|---|
| 9 |
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB'] |
|---|
| 10 |
|
|---|
| 11 |
require 'rex' |
|---|
| 12 |
require 'msf/ui' |
|---|
| 13 |
require 'optparse' |
|---|
| 14 |
|
|---|
| 15 |
if(RUBY_PLATFORM =~ /mswin32/) |
|---|
| 16 |
$stderr.puts "[*] The msfconsole interface is not supported on the native Windows Ruby\n" |
|---|
| 17 |
$stderr.puts " interpreter. Things will break, exploits will fail, payloads will not\n" |
|---|
| 18 |
$stderr.puts " be handled correctly. Please use the msfweb 'console' or install \n" |
|---|
| 19 |
$stderr.puts " Cygwin or Linux in VMWare.\n\n" |
|---|
| 20 |
end |
|---|
| 21 |
|
|---|
| 22 |
class OptsConsole |
|---|
| 23 |
# |
|---|
| 24 |
# Return a hash describing the options. |
|---|
| 25 |
# |
|---|
| 26 |
def self.parse(args) |
|---|
| 27 |
options = {} |
|---|
| 28 |
|
|---|
| 29 |
opts = OptionParser.new do |opts| |
|---|
| 30 |
opts.banner = "Usage: msfconsole [options]" |
|---|
| 31 |
|
|---|
| 32 |
opts.separator "" |
|---|
| 33 |
opts.separator "Specific options:" |
|---|
| 34 |
|
|---|
| 35 |
opts.on("-d", "-d", "Execute the console as defanged") do |
|---|
| 36 |
options['Defanged'] = true |
|---|
| 37 |
end |
|---|
| 38 |
|
|---|
| 39 |
opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r| |
|---|
| 40 |
options['Resource'] = r |
|---|
| 41 |
end |
|---|
| 42 |
|
|---|
| 43 |
opts.on("-c", "-c <filename>", "Load the specified configuration file") do |c| |
|---|
| 44 |
options['Config'] = c |
|---|
| 45 |
end |
|---|
| 46 |
|
|---|
| 47 |
opts.on("-m", "-m <directory>", "Specifies an additional module search path") do |m| |
|---|
| 48 |
options['ModulePath'] = m |
|---|
| 49 |
end |
|---|
| 50 |
|
|---|
| 51 |
# Boolean switch. |
|---|
| 52 |
opts.on("-v", "--version", "Show version") do |v| |
|---|
| 53 |
options['Version'] = true |
|---|
| 54 |
end |
|---|
| 55 |
|
|---|
| 56 |
opts.separator "" |
|---|
| 57 |
opts.separator "Common options:" |
|---|
| 58 |
|
|---|
| 59 |
opts.on_tail("-h", "--help", "Show this message") do |
|---|
| 60 |
puts opts |
|---|
| 61 |
exit |
|---|
| 62 |
end |
|---|
| 63 |
end |
|---|
| 64 |
|
|---|
| 65 |
opts.parse!(args) |
|---|
| 66 |
|
|---|
| 67 |
options |
|---|
| 68 |
end |
|---|
| 69 |
end |
|---|
| 70 |
|
|---|
| 71 |
options = OptsConsole.parse(ARGV) |
|---|
| 72 |
if (options['Version']) |
|---|
| 73 |
$stderr.puts 'Framework Version: ' + Msf::Framework::Version |
|---|
| 74 |
exit |
|---|
| 75 |
end |
|---|
| 76 |
|
|---|
| 77 |
begin |
|---|
| 78 |
Msf::Ui::Console::Driver.new( |
|---|
| 79 |
Msf::Ui::Console::Driver::DefaultPrompt, |
|---|
| 80 |
Msf::Ui::Console::Driver::DefaultPromptChar, |
|---|
| 81 |
options |
|---|
| 82 |
).run |
|---|
| 83 |
rescue Interrupt |
|---|
| 84 |
end |
|---|