Class: Msf::RPC::RPC_Plugin

Inherits:
RPC_Base show all
Defined in:
lib/msf/core/rpc/v10/rpc_plugin.rb

Instance Attribute Summary

Attributes inherited from RPC_Base

#framework, #job_status_tracker, #service, #tokens, #users

Instance Method Summary collapse

Methods inherited from RPC_Base

#error, #initialize

Constructor Details

This class inherits a constructor from Msf::RPC::RPC_Base

Instance Method Details

#rpc_load(path, xopts = {}) ⇒ Hash

Loads a plugin.

Examples:

Here's how you would use this from the client:

# Load the nexpose plugin
rpc.call('plugin.load', 'nexpose')

Parameters:

  • path (String)

    The plugin filename (without the extension). It will try to find your plugin in either one of these directories:

    • msf/plugins/

    • ~/.msf4/plugins/

  • xopts (Hash) (defaults to: {})

    Options to pass to the plugin.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains the following key:

    • 'result' [String] A value that either says 'success' or 'failure'.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/msf/core/rpc/v10/rpc_plugin.rb', line 21

def rpc_load(path, xopts = {})
  opts = ActiveSupport::HashWithIndifferentAccess.new

  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 directory (~/.msf3/plugins/), use the base
    path = Msf::Config.user_plugin_directory + File::SEPARATOR + plugin_file_name
    if not File.exist?(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 self.framework.plugins.load(path, opts)
      return { "result" => "success" }
    end
  rescue ::Exception => e
    elog("Error loading plugin #{path}:", error: e)
    return { "result" => "failure" }
  end

end

#rpc_loadedHash

Returns a list of loaded plugins.

Examples:

Here's how you would use this from the client:

rpc.call('plugin.loaded')

Returns:

  • (Hash)

    All the plugins loaded. It contains the following key:

    • 'plugins' [Array<string>] A list of plugin names.



81
82
83
84
85
86
87
88
# File 'lib/msf/core/rpc/v10/rpc_plugin.rb', line 81

def rpc_loaded
  ret = {}
  ret[:plugins] = []
  self.framework.plugins.each do |plugin|
    ret[:plugins] << plugin.name
  end
  ret
end

#rpc_unload(name) ⇒ Hash

Unloads a plugin.

Examples:

Here's how you would use this from the client:

rpc.call('plugin.unload', 'nexpose')

Parameters:

  • name (String)

    The plugin filename (without the extension). For example: 'nexpose'.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains the following key:

    • 'result' [String] A value that either says 'success' or 'failure'.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/msf/core/rpc/v10/rpc_plugin.rb', line 61

def rpc_unload(name)
  # Find a plugin within the plugins array
  plugin = self.framework.plugins.find { |p| p.name == name }

  # Unload the plugin if it matches the name we're searching for
  if plugin
    self.framework.plugins.unload(plugin)
    return { "result" => "success" }
  end

  { "result" => "failure" }
end