2011-05-14 20:38:44 +02:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
|
|
|
# This plugin provides an msf daemon interface that spawns a listener on a
|
2011-05-22 05:50:14 +02:00
|
|
|
# defined port (default 55552) and gives each connecting client its own
|
2011-05-14 20:38:44 +02:00
|
|
|
# console interface. These consoles all share the same framework instance.
|
|
|
|
# Be aware that the console instance that spawns on the port is entirely
|
|
|
|
# unauthenticated, so realize that you have been warned.
|
|
|
|
#
|
|
|
|
|
2011-05-22 05:50:14 +02:00
|
|
|
require "msf/core/rpc/v10/service"
|
2011-05-14 20:38:44 +02:00
|
|
|
require "fileutils"
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements the msfd plugin interface.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Plugin::MSGRPC < Msf::Plugin
|
|
|
|
|
2013-09-30 20:47:53 +02:00
|
|
|
#
|
|
|
|
# The default local hostname that the server listens on.
|
|
|
|
#
|
|
|
|
DefaultHost = "127.0.0.1"
|
|
|
|
|
|
|
|
#
|
|
|
|
# The default local port that the server listens on.
|
|
|
|
#
|
|
|
|
DefaultPort = 55552
|
|
|
|
|
|
|
|
#
|
|
|
|
# ServerPort
|
|
|
|
#
|
|
|
|
# The local port to listen on for connections. The default is 55553
|
|
|
|
#
|
|
|
|
def initialize(framework, opts)
|
|
|
|
super
|
|
|
|
|
|
|
|
host = opts['ServerHost'] || DefaultHost
|
|
|
|
port = opts['ServerPort'] || DefaultPort
|
2015-02-28 21:07:26 +01:00
|
|
|
ssl = (opts['SSL'] && opts['SSL'].to_s =~ /^[ty]/i) ? true : false
|
2013-09-30 20:47:53 +02:00
|
|
|
cert = opts['SSLCert']
|
|
|
|
|
|
|
|
user = opts['User'] || "msf"
|
|
|
|
pass = opts['Pass'] || ::Rex::Text.rand_text_alphanumeric(8)
|
|
|
|
uri = opts['URI'] || "/api"
|
2015-05-01 22:04:55 +02:00
|
|
|
timeout = opts['TokenTimeout'] || 300
|
2013-09-30 20:47:53 +02:00
|
|
|
|
|
|
|
print_status("MSGRPC Service: #{host}:#{port} #{ssl ? " (SSL)" : ""}")
|
|
|
|
print_status("MSGRPC Username: #{user}")
|
|
|
|
print_status("MSGRPC Password: #{pass}")
|
|
|
|
|
|
|
|
self.server = ::Msf::RPC::Service.new(framework, {
|
|
|
|
:host => host,
|
|
|
|
:port => port,
|
|
|
|
:ssl => ssl,
|
|
|
|
:cert => cert,
|
|
|
|
:uri => uri,
|
2015-05-01 22:04:55 +02:00
|
|
|
:tokens => { },
|
|
|
|
:token_timeout => timeout
|
2013-09-30 20:47:53 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
self.server.add_user(user, pass)
|
|
|
|
|
|
|
|
# If the run in foreground flag is not specified, then go ahead and fire
|
|
|
|
# it off in a worker thread.
|
2015-03-09 06:16:56 +01:00
|
|
|
unless opts['RunInForeground'] == true
|
2013-09-30 20:47:53 +02:00
|
|
|
# Store a handle to the thread so we can kill it during
|
|
|
|
# cleanup when we get unloaded.
|
|
|
|
self.thread = Thread.new { run }
|
|
|
|
framework.threads.register(self.thread, "MetasploitRPCServer", true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns 'msgrpc'
|
|
|
|
#
|
|
|
|
def name
|
|
|
|
"msgrpc"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the plugin description.
|
|
|
|
#
|
|
|
|
def desc
|
|
|
|
"Provides a MessagePack interface over HTTP"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The meat of the plugin, sets up handlers for requests
|
|
|
|
#
|
|
|
|
def run
|
|
|
|
# Start the actual service
|
|
|
|
self.server.start
|
|
|
|
|
|
|
|
# Register
|
|
|
|
framework.threads.register(Thread.current, "MetasploitRPCServer", true)
|
|
|
|
|
|
|
|
# Wait for the service to complete
|
|
|
|
self.server.wait
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes the listener service.
|
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
self.server.stop if self.server
|
|
|
|
self.thread.kill if self.thread
|
|
|
|
self.server = nil
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The MSGRPC instance.
|
|
|
|
#
|
|
|
|
attr_accessor :server
|
|
|
|
attr_accessor :thread
|
|
|
|
attr_accessor :users
|
|
|
|
attr_accessor :tokens
|
2011-05-14 20:38:44 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|