mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-05 14:57:30 +01:00
Add plugin support to rpc. Fixes #2292
git-svn-id: file:///home/svn/framework3/trunk@10177 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
633f84888e
commit
9253085d13
@ -9,4 +9,5 @@ require "msf/core/rpc/module"
|
||||
require "msf/core/rpc/job"
|
||||
require "msf/core/rpc/console"
|
||||
require "msf/core/rpc/db"
|
||||
require "msf/core/rpc/plugin"
|
||||
|
||||
|
64
lib/msf/core/rpc/plugin.rb
Normal file
64
lib/msf/core/rpc/plugin.rb
Normal file
@ -0,0 +1,64 @@
|
||||
module Msf
|
||||
module RPC
|
||||
class Plugin < Base
|
||||
|
||||
def load(token,path,xopts = {})
|
||||
|
||||
authenticate(token)
|
||||
opts = {}
|
||||
|
||||
xopts.each do |k,v|
|
||||
if k.class == String
|
||||
opts[k.to_sym] = v
|
||||
end
|
||||
end
|
||||
|
||||
if (path !~ /#{File::SEPARATOR}/)
|
||||
plugin_file_name = path
|
||||
|
||||
# If the plugin isn't in the user direcotry (~/.msf3/plugins/), use the base
|
||||
path = Msf::Config.user_plugin_directory + File::SEPARATOR + plugin_file_name
|
||||
if not File.exists?( path + ".rb" )
|
||||
# If the following "path" doesn't exist it will be caught when we attempt to load
|
||||
path = Msf::Config.plugin_directory + File::SEPARATOR + plugin_file_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
begin
|
||||
if (inst = @framework.plugins.load(path, opts))
|
||||
return { "result" => "success" }
|
||||
end
|
||||
rescue ::Exception => e
|
||||
elog("Error loading plugin #{path}: #{e}\n\n#{e.backtrace.join("\n")}", src = 'core', level = 0, from = caller)
|
||||
return { "result" => "failure" }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def unload(token,name)
|
||||
authenticate(token)
|
||||
@framework.plugins.each { |plugin|
|
||||
# Unload the plugin if it matches the name we're searching for
|
||||
if (plugin.name == name)
|
||||
@framework.plugins.unload(plugin)
|
||||
return { "result" => "success" }
|
||||
end
|
||||
}
|
||||
return { "result" => "failure" }
|
||||
|
||||
end
|
||||
|
||||
def loaded(token)
|
||||
authenticate(token)
|
||||
ret = {}
|
||||
ret[:plugins] = []
|
||||
@framework.plugins.each do |plugin|
|
||||
ret[:plugins] << plugin.name
|
||||
end
|
||||
ret
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -134,7 +134,11 @@ class Plugin::XMLRPC < Msf::Plugin
|
||||
self.server.add_handler(::XMLRPC::iPIMethods("db"),
|
||||
::Msf::RPC::Db.new(*args)
|
||||
)
|
||||
|
||||
|
||||
self.server.add_handler(::XMLRPC::iPIMethods("plugin"),
|
||||
::Msf::RPC::Plugin.new(*args)
|
||||
)
|
||||
|
||||
# Set the default/catch-all handler
|
||||
self.server.set_default_handler do |name, *args|
|
||||
raise ::XMLRPC::FaultException.new(-99, "Method #{name} missing or wrong number of parameters!")
|
||||
|
Loading…
Reference in New Issue
Block a user