Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/plugins/msgrpc.rb
Views: 11705
#1# This plugin provides an msf daemon interface that spawns a listener on a2# defined port (default 55552) and gives each connecting client its own3# console interface. These consoles all share the same framework instance.4# Be aware that the console instance that spawns on the port is entirely5# unauthenticated, so realize that you have been warned.6#78require 'msf/core/rpc/v10/service'9require 'fileutils'1011module Msf12###13#14# This class implements the msfd plugin interface.15#16###17class Plugin::MSGRPC < Msf::Plugin1819#20# The default local hostname that the server listens on.21#22DefaultHost = '127.0.0.1'.freeze2324#25# The default local port that the server listens on.26#27DefaultPort = 555522829#30# ServerPort31#32# The local port to listen on for connections. The default is 5555233#34def initialize(framework, opts)35super3637host = opts['ServerHost'] || DefaultHost38port = opts['ServerPort'] || DefaultPort39ssl = (opts['SSL'] && opts['SSL'].to_s =~ /^[ty]/i) ? true : false40cert = opts['SSLCert']4142user = opts['User'] || 'msf'43pass = opts['Pass'] || ::Rex::Text.rand_text_alphanumeric(8)44uri = opts['URI'] || '/api'45timeout = opts['TokenTimeout'] || 3004647print_status("MSGRPC Service: #{host}:#{port} #{ssl ? ' (SSL)' : ''}")48print_status("MSGRPC Username: #{user}")49print_status("MSGRPC Password: #{pass}")5051self.server = ::Msf::RPC::Service.new(framework, {52host: host,53port: port,54ssl: ssl,55cert: cert,56uri: uri,57tokens: {},58token_timeout: timeout59})6061server.add_user(user, pass)6263# If the run in foreground flag is not specified, then go ahead and fire64# it off in a worker thread.65unless opts['RunInForeground'] == true66# Store a handle to the thread so we can kill it during67# cleanup when we get unloaded.68self.thread = Thread.new { run }69framework.threads.register(thread, 'MetasploitRPCServer', true)70end71end7273#74# Returns 'msgrpc'75#76def name77'msgrpc'78end7980#81# Returns the plugin description.82#83def desc84'Provides a MessagePack interface over HTTP'85end8687#88# The meat of the plugin, sets up handlers for requests89#90def run91# Start the actual service92server.start9394# Register95framework.threads.register(Thread.current, 'MetasploitRPCServer', true)9697# Wait for the service to complete98server.wait99end100101#102# Closes the listener service.103#104def cleanup105server.stop if server106thread.kill if thread107self.server = nil108super109end110111#112# The MSGRPC instance.113#114attr_accessor :server115attr_accessor :thread, :users, :tokens116117end118end119120121