2005-12-17 07:46:23 +01:00
|
|
|
#!/usr/bin/env ruby
|
2005-11-28 22:38:48 +01:00
|
|
|
#
|
|
|
|
# This user interface allows users to interact with the framework through a
|
|
|
|
# command line interface (CLI) rather than having to use a prompting console
|
|
|
|
# or web-based interface.
|
|
|
|
#
|
2005-10-02 07:47:52 +02:00
|
|
|
|
2006-07-31 17:36:08 +02:00
|
|
|
msfbase = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
|
|
|
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
|
2008-02-02 22:29:46 +01:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2005-10-02 07:47:52 +02:00
|
|
|
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/ui'
|
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
Indent = ' '
|
|
|
|
|
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
|
|
|
|
|
2005-10-02 07:47:52 +02:00
|
|
|
# Initialize the simplified framework instance.
|
|
|
|
$framework = Msf::Simple::Framework.create
|
|
|
|
|
2007-02-15 22:14:11 +01:00
|
|
|
if ($framework.modules.failed.length > 0)
|
|
|
|
print("Warning: The following modules could not be loaded!\n\n")
|
|
|
|
$framework.modules.failed.each_pair do |file, err|
|
|
|
|
print("\t#{file}: #{err.to_s}\n\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-01-10 17:07:45 +01:00
|
|
|
def usage (str = nil, extra = nil)
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => "Usage: #{$0} <exploit_name> <option=value> [mode]",
|
|
|
|
'Indent' => 4,
|
|
|
|
'Columns' => ['Mode', 'Description']
|
|
|
|
)
|
|
|
|
|
2006-09-14 07:33:47 +02:00
|
|
|
tbl << ['(H)elp', "You're looking at it baby!"]
|
|
|
|
tbl << ['(S)ummary', 'Show information about this module']
|
|
|
|
tbl << ['(O)ptions', 'Show available options for this module']
|
|
|
|
tbl << ['(A)dvanced', 'Show available advanced options for this module']
|
|
|
|
tbl << ['(I)DS Evasion', 'Show available ids evasion options for this module']
|
|
|
|
tbl << ['(P)ayloads', 'Show available payloads for this module']
|
2007-02-15 08:33:40 +01:00
|
|
|
tbl << ['(T)argets', 'Show available targets for this exploit module']
|
|
|
|
tbl << ['(AC)tions', 'Show available actions for this auxiliary module']
|
2006-09-14 07:33:47 +02:00
|
|
|
tbl << ['(C)heck', 'Run the check routine of the selected module']
|
|
|
|
tbl << ['(E)xecute', 'Execute the selected module']
|
2006-01-10 17:07:45 +01:00
|
|
|
|
|
|
|
$stdout.puts "Error: #{str}\n\n" if str
|
|
|
|
$stdout.puts tbl.to_s + "\n"
|
|
|
|
$stdout.puts extra + "\n" if extra
|
|
|
|
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2006-01-05 23:20:28 +01:00
|
|
|
if (ARGV.length < 1)
|
2006-09-14 07:33:47 +02:00
|
|
|
ext = ''
|
|
|
|
|
2005-12-15 06:07:14 +01:00
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => 'Exploits',
|
|
|
|
'Indent' => 4,
|
|
|
|
'Columns' => [ 'Name', 'Description' ])
|
|
|
|
|
|
|
|
$framework.exploits.each_module { |name, mod|
|
2006-09-14 07:33:47 +02:00
|
|
|
tbl << [ 'exploit/' + name, mod.new.name ]
|
2005-12-15 06:07:14 +01:00
|
|
|
}
|
2006-09-14 07:33:47 +02:00
|
|
|
ext << tbl.to_s + "\n"
|
|
|
|
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => 'Auxiliary',
|
|
|
|
'Indent' => 4,
|
|
|
|
'Columns' => [ 'Name', 'Description' ])
|
2005-12-15 06:07:14 +01:00
|
|
|
|
2006-09-14 07:33:47 +02:00
|
|
|
$framework.auxiliary.each_module { |name, mod|
|
|
|
|
tbl << [ 'auxiliary/' + name, mod.new.name ]
|
|
|
|
}
|
|
|
|
|
|
|
|
ext << tbl.to_s + "\n"
|
|
|
|
|
|
|
|
usage(nil, ext)
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
|
|
|
|
2006-09-14 07:33:47 +02:00
|
|
|
# Get the module name we'll be using
|
2005-10-02 07:47:52 +02:00
|
|
|
exploit_name = ARGV.shift
|
2006-09-14 07:33:47 +02:00
|
|
|
exploit = nil
|
2007-03-17 20:39:30 +01:00
|
|
|
module_class = "exploit"
|
2006-09-14 07:33:47 +02:00
|
|
|
|
2008-10-04 22:46:54 +02:00
|
|
|
if(exploit_name == "-h")
|
|
|
|
usage()
|
|
|
|
end
|
|
|
|
|
2007-02-18 13:27:17 +01:00
|
|
|
# Process special var/val pairs...
|
|
|
|
Msf::Ui::Common.process_cli_arguments($framework, ARGV)
|
|
|
|
|
2006-09-14 07:33:47 +02:00
|
|
|
# Determine what type of module it is
|
|
|
|
case exploit_name
|
|
|
|
when /exploit\/(.*)/
|
|
|
|
exploit = $framework.exploits.create($1)
|
|
|
|
module_class = 'exploit'
|
|
|
|
|
|
|
|
when /auxiliary\/(.*)/
|
|
|
|
exploit = $framework.auxiliary.create($1)
|
|
|
|
module_class = 'auxiliary'
|
2007-02-18 13:27:17 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
exploit = $framework.exploits.create(exploit_name)
|
|
|
|
|
2006-09-14 07:33:47 +02:00
|
|
|
end
|
2005-10-02 07:47:52 +02:00
|
|
|
|
2008-10-04 22:46:54 +02:00
|
|
|
|
|
|
|
|
2005-10-02 07:47:52 +02:00
|
|
|
if (exploit == nil)
|
2006-09-14 07:33:47 +02:00
|
|
|
usage("Invalid module: #{exploit_name}")
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
|
|
|
|
2006-02-05 00:59:17 +01:00
|
|
|
exploit.init_ui(
|
|
|
|
Rex::Ui::Text::Input::Stdio.new,
|
|
|
|
Rex::Ui::Text::Output::Stdio.new
|
|
|
|
)
|
|
|
|
|
2006-01-05 23:20:28 +01:00
|
|
|
# Evalulate the command (default to "help")
|
|
|
|
mode = ARGV.pop || 'h'
|
2005-10-02 07:47:52 +02:00
|
|
|
|
|
|
|
# Import options
|
2006-03-16 17:33:32 +01:00
|
|
|
exploit.datastore.import_options_from_s(ARGV.join('_|_'), '_|_')
|
2005-10-02 07:47:52 +02:00
|
|
|
|
2007-04-28 20:41:09 +02:00
|
|
|
|
|
|
|
# Initialize associated modules
|
|
|
|
payload = nil
|
|
|
|
encoder = nil
|
|
|
|
nop = nil
|
|
|
|
|
|
|
|
if (exploit.datastore['PAYLOAD'])
|
|
|
|
payload = $framework.payloads.create(exploit.datastore['PAYLOAD'])
|
2008-11-08 20:44:35 +01:00
|
|
|
payload.datastore.import_options_from_s(ARGV.join('_|_'), '_|_')
|
2007-04-28 20:41:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if (exploit.datastore['ENCODER'])
|
|
|
|
encoder = $framework.encoders.create(exploit.datastore['ENCODER'])
|
2008-11-08 20:44:35 +01:00
|
|
|
encoder.datastore.import_options_from_s(ARGV.join('_|_'), '_|_')
|
2007-04-28 20:41:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if (exploit.datastore['NOP'])
|
|
|
|
nop = $framework.nops.create(exploit.datastore['NOP'])
|
2008-11-08 20:44:35 +01:00
|
|
|
nop.datastore.import_options_from_s(ARGV.join('_|_'), '_|_')
|
2007-04-28 20:41:09 +02:00
|
|
|
end
|
|
|
|
|
2005-10-02 07:47:52 +02:00
|
|
|
case mode.downcase
|
2006-01-10 17:07:45 +01:00
|
|
|
when 'h'
|
|
|
|
usage
|
2005-10-02 07:47:52 +02:00
|
|
|
when "s"
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_module(exploit, Indent))
|
2007-04-28 20:41:09 +02:00
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_module(payload, Indent)) if payload
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_module(encoder, Indent)) if encoder
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_module(nop, Indent)) if nop
|
|
|
|
|
2005-10-02 07:47:52 +02:00
|
|
|
when "o"
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_options(exploit, Indent))
|
2007-04-28 20:41:09 +02:00
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_options(payload, Indent)) if payload
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_options(encoder, Indent)) if encoder
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_options(nop, Indent)) if nop
|
2005-10-02 07:47:52 +02:00
|
|
|
when "a"
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_advanced_options(exploit, Indent))
|
2007-04-28 20:41:09 +02:00
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_advanced_options(payload, Indent)) if payload
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_advanced_options(encoder, Indent)) if encoder
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_advanced_options(nop, Indent)) if nop
|
2006-01-05 04:57:12 +01:00
|
|
|
when "i"
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_evasion_options(exploit, Indent))
|
2007-04-28 20:41:09 +02:00
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_evasion_options(payload, Indent)) if payload
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_evasion_options(encoder, Indent)) if encoder
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_evasion_options(nop, Indent)) if nop
|
2005-10-02 07:47:52 +02:00
|
|
|
when "p"
|
2006-09-14 07:33:47 +02:00
|
|
|
if (module_class == 'exploit')
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_compatible_payloads(exploit, Indent, "Compatible payloads"))
|
|
|
|
else
|
|
|
|
$stdout.puts("\nError: This type of module does not support payloads")
|
|
|
|
end
|
2005-10-02 07:47:52 +02:00
|
|
|
when "t"
|
2006-09-14 07:33:47 +02:00
|
|
|
if (module_class == 'exploit')
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_exploit_targets(exploit, Indent))
|
|
|
|
else
|
|
|
|
$stdout.puts("\nError: This type of module does not support targets")
|
|
|
|
end
|
2007-02-15 08:33:40 +01:00
|
|
|
when "ac"
|
2006-09-14 07:33:47 +02:00
|
|
|
if (module_class == 'auxiliary')
|
|
|
|
$stdout.puts("\n" + Msf::Serializer::ReadableText.dump_auxiliary_actions(exploit, Indent))
|
|
|
|
else
|
|
|
|
$stdout.puts("\nError: This type of module does not support actions")
|
|
|
|
end
|
2005-10-02 07:47:52 +02:00
|
|
|
when "c"
|
2006-09-14 07:33:47 +02:00
|
|
|
if (module_class == 'exploit')
|
|
|
|
begin
|
2007-03-17 20:39:30 +01:00
|
|
|
if (code = exploit.check_simple(
|
|
|
|
'LocalInput' => Rex::Ui::Text::Input::Stdio.new,
|
|
|
|
'LocalOutput' => Rex::Ui::Text::Output::Stdio.new))
|
2006-09-14 07:33:47 +02:00
|
|
|
stat = (code == Msf::Exploit::CheckCode::Vulnerable) ? '[+]' : '[*]'
|
|
|
|
|
|
|
|
$stdout.puts("#{stat} #{code[1]}")
|
|
|
|
else
|
|
|
|
$stderr.puts("Check failed: The state could not be determined.")
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
$stderr.puts("Check failed: #{$!}")
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
2006-09-14 07:33:47 +02:00
|
|
|
else
|
|
|
|
$stdout.puts("\nError: This type of module does not support the check feature")
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
|
|
|
when "e"
|
2006-09-14 07:33:47 +02:00
|
|
|
|
|
|
|
case module_class
|
|
|
|
when 'exploit'
|
|
|
|
begin
|
|
|
|
session = exploit.exploit_simple(
|
|
|
|
'Encoder' => exploit.datastore['ENCODER'],
|
|
|
|
'Target' => exploit.datastore['TARGET'],
|
|
|
|
'Payload' => exploit.datastore['PAYLOAD'],
|
|
|
|
'Nop' => exploit.datastore['NOP'],
|
|
|
|
'LocalInput' => Rex::Ui::Text::Input::Stdio.new,
|
|
|
|
'LocalOutput' => Rex::Ui::Text::Output::Stdio.new,
|
|
|
|
'ForceBlocking' => true)
|
|
|
|
|
|
|
|
if (session)
|
|
|
|
$stdout.puts("[*] #{session.desc} session #{session.name} opened (#{session.tunnel_to_s})\n\n")
|
|
|
|
|
2007-02-21 04:47:32 +01:00
|
|
|
session.interact(
|
2006-09-14 07:33:47 +02:00
|
|
|
Rex::Ui::Text::Input::Stdio.new,
|
2007-02-21 04:47:32 +01:00
|
|
|
Rex::Ui::Text::Output::Stdio.new
|
|
|
|
)
|
2006-09-14 07:33:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
rescue
|
|
|
|
$stderr.puts("Exploit failed: #{$!}")
|
|
|
|
$stderr.puts("Backtrace:")
|
|
|
|
$stderr.puts($!.backtrace.join("\n"))
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
2006-09-14 07:33:47 +02:00
|
|
|
when 'auxiliary'
|
|
|
|
begin
|
2007-07-03 06:18:19 +02:00
|
|
|
exploit.run_simple(
|
2006-09-14 07:33:47 +02:00
|
|
|
'Encoder' => exploit.datastore['ENCODER'],
|
|
|
|
'Action' => exploit.datastore['ACTION'],
|
|
|
|
'LocalInput' => Rex::Ui::Text::Input::Stdio.new,
|
|
|
|
'LocalOutput' => Rex::Ui::Text::Output::Stdio.new,
|
|
|
|
'ForceBlocking' => true)
|
|
|
|
rescue
|
|
|
|
$stderr.puts("Auxiliary failed: #{$!}")
|
|
|
|
$stderr.puts("Backtrace:")
|
|
|
|
$stderr.puts($!.backtrace.join("\n"))
|
|
|
|
end
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
2006-01-10 17:07:45 +01:00
|
|
|
else
|
|
|
|
usage("Invalid mode #{mode}")
|
2005-10-02 07:47:52 +02:00
|
|
|
end
|
|
|
|
|
2008-11-08 20:44:35 +01:00
|
|
|
$stdout.puts
|