2008-12-02 22:09:34 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
2010-05-03 17:13:09 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
2008-12-02 22:09:34 +00:00
|
|
|
# This user interface listens on a port and provides clients that connect to
|
2011-07-29 23:58:05 +00:00
|
|
|
# it with an RPC interface to the Metasploit Framework.
|
2008-12-02 22:09:34 +00:00
|
|
|
#
|
2010-05-03 17:13:09 +00:00
|
|
|
# $Revision$
|
|
|
|
#
|
2008-12-02 22:09:34 +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-12-02 22:09:34 +00:00
|
|
|
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
|
2011-11-21 20:18:57 +00:00
|
|
|
require 'fastlib'
|
|
|
|
|
2011-11-24 05:10:43 +00:00
|
|
|
|
2011-11-21 20:18:57 +00:00
|
|
|
|
2008-12-02 22:09:34 +00:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
|
|
|
|
2010-10-21 05:08:01 +00:00
|
|
|
require 'rex/parser/arguments'
|
2008-12-02 22:09:34 +00:00
|
|
|
|
|
|
|
# Declare the argument parser for msfrpcd
|
|
|
|
arguments = Rex::Parser::Arguments.new(
|
2009-01-06 16:06:56 +00:00
|
|
|
"-a" => [ true, "Bind to this IP address" ],
|
2008-12-02 22:09:34 +00:00
|
|
|
"-p" => [ true, "Bind to this port instead of 55553" ],
|
|
|
|
"-U" => [ true, "Specify the username to access msfrpcd" ],
|
|
|
|
"-P" => [ true, "Specify the password to access msfrpcd" ],
|
2011-07-29 23:58:05 +00:00
|
|
|
"-t" => [ true, "Server type, [Basic|Web|Msg]" ],
|
2009-12-02 00:00:11 +00:00
|
|
|
"-u" => [ true, "URI for Web server" ],
|
2011-07-29 23:58:05 +00:00
|
|
|
"-S" => [ false, "Disable SSL on the RPC socket" ],
|
2008-12-02 22:09:34 +00:00
|
|
|
"-f" => [ false, "Run the daemon in the foreground" ],
|
2011-01-17 22:37:12 +00:00
|
|
|
"-n" => [ false, "Disable database" ],
|
2008-12-02 22:09:34 +00:00
|
|
|
"-h" => [ false, "Help banner" ])
|
|
|
|
|
2010-05-03 17:13:09 +00:00
|
|
|
opts = {
|
2008-12-02 22:09:34 +00:00
|
|
|
'RunInForeground' => true,
|
|
|
|
'SSL' => true,
|
|
|
|
'ServerHost' => '0.0.0.0',
|
2009-12-02 00:00:11 +00:00
|
|
|
'ServerPort' => 55553,
|
|
|
|
'ServerType' => 'Basic'
|
2008-12-02 22:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreground = false
|
2011-01-17 22:37:12 +00:00
|
|
|
frameworkOpts = {}
|
2008-12-02 22:09:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Parse command line arguments.
|
|
|
|
arguments.parse(ARGV) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-a"
|
|
|
|
opts['ServerHost'] = val
|
|
|
|
when "-S"
|
|
|
|
opts['SSL'] = false
|
|
|
|
when "-p"
|
|
|
|
opts['ServerPort'] = val
|
|
|
|
when '-U'
|
|
|
|
opts['User'] = val
|
|
|
|
when '-P'
|
|
|
|
opts['Pass'] = val
|
|
|
|
when "-f"
|
|
|
|
foreground = true
|
2009-12-02 00:00:11 +00:00
|
|
|
when "-t"
|
2010-05-03 17:13:09 +00:00
|
|
|
opts['ServerType'] = val
|
2009-12-02 00:00:11 +00:00
|
|
|
when "-u"
|
2010-05-03 17:13:09 +00:00
|
|
|
opts['URI'] = val
|
2011-01-17 22:37:12 +00:00
|
|
|
when "-n"
|
|
|
|
frameworkOpts['DisableDatabase'] = true
|
2008-12-02 22:09:34 +00:00
|
|
|
when "-h"
|
|
|
|
print("\nUsage: #{File.basename(__FILE__)} <options>\n" + arguments.usage)
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
if(not opts['Pass'])
|
2009-03-11 00:10:27 +00:00
|
|
|
$stderr.puts "[-] Error: a password must be specified (-P)"
|
2008-12-02 22:09:34 +00:00
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
$0 = "msfrpcd"
|
|
|
|
|
2011-07-29 23:58:05 +00:00
|
|
|
rpctype = 'XML'
|
|
|
|
rpctype = 'MSG' if opts['ServerType'].downcase == 'msg'
|
|
|
|
|
|
|
|
$stderr.puts "[*] #{rpctype}RPC starting on #{opts['ServerHost']}:#{opts['ServerPort']} (#{opts['SSL'] ? "SSL" : "NO SSL"}):#{opts['ServerType']}..."
|
2009-12-02 00:00:11 +00:00
|
|
|
|
|
|
|
$stderr.puts "[*] URI: #{opts['URI']}" if(opts['URI'])
|
2008-12-02 22:09:34 +00:00
|
|
|
|
2010-10-21 05:08:01 +00:00
|
|
|
require 'msf/base'
|
|
|
|
require 'msf/ui'
|
|
|
|
|
2010-09-03 15:47:31 +00:00
|
|
|
|
2008-12-02 22:09:34 +00:00
|
|
|
# Fork into the background if requested
|
|
|
|
begin
|
2011-04-13 17:02:45 +00:00
|
|
|
if foreground
|
2011-07-29 23:58:05 +00:00
|
|
|
$stdout.puts "[*] #{rpctype}RPC ready at #{Time.now}."
|
2011-04-13 17:02:45 +00:00
|
|
|
else
|
2011-07-29 23:58:05 +00:00
|
|
|
$stderr.puts "[*] #{rpctype}RPC backgrounding at #{Time.now}..."
|
2008-12-02 22:09:34 +00:00
|
|
|
exit(0) if Process.fork()
|
|
|
|
end
|
|
|
|
rescue ::NotImplementedError
|
2009-03-11 00:10:27 +00:00
|
|
|
$stderr.puts "[-] Background mode is not available on this platform"
|
2008-12-02 22:09:34 +00:00
|
|
|
end
|
|
|
|
|
2011-05-02 02:55:26 +00:00
|
|
|
# Create an instance of the framework
|
|
|
|
$framework = Msf::Simple::Framework.create(frameworkOpts)
|
|
|
|
|
2011-01-17 22:37:12 +00:00
|
|
|
$framework.db.sink.restart if RUBY_PLATFORM !~ /cygwin/ and not frameworkOpts['DisableDatabase']
|
2010-08-31 23:24:54 +00:00
|
|
|
|
2008-12-02 22:09:34 +00:00
|
|
|
# Run the plugin instance in the foreground.
|
2010-12-30 18:11:25 +00:00
|
|
|
begin
|
2011-07-29 23:58:05 +00:00
|
|
|
$framework.plugins.load("#{rpctype.downcase}rpc", opts).run
|
2010-12-30 18:11:25 +00:00
|
|
|
rescue ::Interrupt
|
|
|
|
$stderr.puts "[*] Shutting down"
|
|
|
|
end
|