1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-10-29 18:07:27 +01:00
metasploit-framework/msfrpcd
Luke Imhoff b863978028
Remove fastlib
MSP-11368
MSP-11143

Remove fastlib as it slows down the code loading process.  From the
previous commit, the mean loading for
`METASPLOIT_FRAMEWORK_PROFILE=true msfconsole -q -x exit` was
27.9530±0.3485 seconds (N=10).  The mean after removal of fastlib
was 17.9820±0.6497 seconds (N=10).  This means an average 35.67%
reduction in boot time.
2014-09-18 15:24:21 -05:00

115 lines
3.0 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# -*- coding: binary -*-
#
# $Id$
#
# This user interface listens on a port and provides clients that connect to
# it with an RPC interface to the Metasploit Framework.
#
# $Revision$
#
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
require 'rex/parser/arguments'
# Declare the argument parser for msfrpcd
arguments = Rex::Parser::Arguments.new(
"-a" => [ true, "Bind to this IP address" ],
"-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" ],
"-u" => [ true, "URI for Web server" ],
"-S" => [ false, "Disable SSL on the RPC socket" ],
"-f" => [ false, "Run the daemon in the foreground" ],
"-n" => [ false, "Disable database" ],
"-h" => [ false, "Help banner" ])
opts = {
'RunInForeground' => true,
'SSL' => true,
'ServerHost' => '0.0.0.0',
'ServerPort' => 55553,
'ServerType' => 'Msg'
}
foreground = false
frameworkOpts = {}
# 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
when "-u"
opts['URI'] = val
when "-n"
frameworkOpts['DisableDatabase'] = true
when "-h"
print("\nUsage: #{File.basename(__FILE__)} <options>\n" + arguments.usage)
exit
end
}
if(not opts['Pass'])
$stderr.puts "[-] Error: a password must be specified (-P)"
exit(0)
end
$0 = "msfrpcd"
rpctype = 'MSG'
$stderr.puts "[*] #{rpctype}RPC starting on #{opts['ServerHost']}:#{opts['ServerPort']} (#{opts['SSL'] ? "SSL" : "NO SSL"}):#{opts['ServerType']}..."
$stderr.puts "[*] URI: #{opts['URI']}" if(opts['URI'])
require 'msf/base'
require 'msf/ui'
# Fork into the background if requested
begin
if foreground
$stdout.puts "[*] #{rpctype}RPC ready at #{Time.now}."
else
$stderr.puts "[*] #{rpctype}RPC backgrounding at #{Time.now}..."
exit(0) if Process.fork()
end
rescue ::NotImplementedError
$stderr.puts "[-] Background mode is not available on this platform"
end
# Create an instance of the framework
$framework = Msf::Simple::Framework.create(frameworkOpts)
$framework.db.sink.restart if RUBY_PLATFORM !~ /cygwin/ and not frameworkOpts['DisableDatabase']
# Run the plugin instance in the foreground.
begin
$framework.plugins.load("#{rpctype.downcase}rpc", opts).run
rescue ::Interrupt
$stderr.puts "[*] Shutting down"
end