Files
metasploit-gs/msfrpcd
T

117 lines
3.1 KiB
Ruby
Raw Normal View History

#!/usr/bin/env ruby
# -*- coding: binary -*-
#
2010-05-03 17:13:09 +00:00
# $Id$
#
# This user interface listens on a port and provides clients that connect to
# it with an RPC interface to the Metasploit Framework.
#
2010-05-03 17:13:09 +00:00
# $Revision$
#
msfbase = __FILE__
while File.symlink?(msfbase)
2013-09-30 13:47:53 -05:00
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
2012-02-04 00:32:37 -06:00
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
2012-04-15 23:35:38 -05:00
require 'msfenv'
2011-11-23 23:10:43 -06:00
$:.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(
2013-09-30 13:47:53 -05:00
"-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" ],
"-t" => [ true, "Token Timeout (default 300 seconds" ],
"-S" => [ false, "Disable SSL on the RPC socket" ],
2013-09-30 13:47:53 -05:00
"-f" => [ false, "Run the daemon in the foreground" ],
"-n" => [ false, "Disable database" ],
2013-09-30 13:47:53 -05:00
"-h" => [ false, "Help banner" ])
2010-05-03 17:13:09 +00:00
opts = {
2013-09-30 13:47:53 -05:00
'RunInForeground' => true,
'SSL' => true,
'ServerHost' => '0.0.0.0',
'ServerPort' => 55553,
'ServerType' => 'Msg',
'TokenTimeout' => 300,
}
foreground = false
2011-01-17 22:37:12 +00:00
frameworkOpts = {}
# Parse command line arguments.
arguments.parse(ARGV) { |opt, idx, val|
2013-09-30 13:47:53 -05:00
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 "-t"
opts['TokenTimeout'] = val.to_i
2013-09-30 13:47:53 -05:00
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
}
unless opts['Pass']
2013-09-30 13:47:53 -05:00
$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
2013-09-30 13:47:53 -05:00
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
2013-09-30 13:47:53 -05:00
$stderr.puts "[-] Background mode is not available on this platform"
end
# Create an instance of the framework
$framework = Msf::Simple::Framework.create(frameworkOpts)
# Run the plugin instance in the foreground.
2010-12-30 18:11:25 +00:00
begin
2013-09-30 13:47:53 -05:00
$framework.plugins.load("#{rpctype.downcase}rpc", opts).run
2010-12-30 18:11:25 +00:00
rescue ::Interrupt
2013-09-30 13:47:53 -05:00
$stderr.puts "[*] Shutting down"
2010-12-30 18:11:25 +00:00
end