Class: Msf::RPC::RPC_Core

Inherits:
RPC_Base show all
Defined in:
lib/msf/core/rpc/v10/rpc_core.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_add_module_path(path) ⇒ Hash

Adds a new local file system path (local to the server) as a module path. The module must be accessible to the user running the Metasploit service, and contain a top-level directory for each module type such as: exploits, nop, encoder, payloads, auxiliary, post, evasion. Also note that this will not unload modules that were deleted from the file system that were previously loaded.

Examples:

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

rpc.call('core.add_module_path', '/tmp/modules/')

Parameters:

  • path (String)

    The new path to load.

Returns:

  • (Hash)

    Module stats that contain the following keys:

    • 'exploits' [Integer] The number of exploits loaded.

    • 'auxiliary' [Integer] The number of auxiliary modules loaded.

    • 'post' [Integer] The number of post modules loaded.

    • 'encoders' [Integer] The number of encoders loaded.

    • 'nops' [Integer] The number of NOP modules loaded.

    • 'payloads' [Integer] The number of payloads loaded.

    • 'evasions' [Integer] The number of evasion modules loaded.



123
124
125
126
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 123

def rpc_add_module_path(path)
  framework.modules.add_module_path(path)
  rpc_module_stats()
end

#rpc_getg(var) ⇒ Hash

Returns a global datastore option.

Examples:

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

rpc.call('core.getg', 'GlobalSetting')

Parameters:

  • var (String)

    The name of the global datastore.

Returns:

  • (Hash)

    The global datastore option. If the option is not set, then the value is empty.



39
40
41
42
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 39

def rpc_getg(var)
  val = framework.datastore[var]
  { var.to_s => val.to_s }
end

#rpc_module_statsHash

Returns the module stats.

Examples:

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

rpc.call('core.module_stats')

Returns:

  • (Hash)

    Module stats that contain the following keys:

    • 'exploits' [Integer] The number of exploits.

    • 'auxiliary' [Integer] The number of auxiliary modules.

    • 'post' [Integer] The number of post modules.

    • 'encoders' [Integer] The number of encoders.

    • 'nops' [Integer] The number of NOP modules.

    • 'payloads' [Integer] The number of payloads.

    • 'evasions' [Integer] The number of evasion modules.



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 141

def rpc_module_stats
  {
    'exploits'  => framework.stats.num_exploits,
    'auxiliary' => framework.stats.num_auxiliary,
    'post'      => framework.stats.num_post,
    'encoders'  => framework.stats.num_encoders,
    'nops'      => framework.stats.num_nops,
    'payloads'  => framework.stats.num_payloads,
    'evasions'  => framework.stats.num_evasion
  }
end

#rpc_reload_modulesHash

Reloads framework modules. This will take some time to complete.

Examples:

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

rpc.call('core.reload_modules')

Returns:

  • (Hash)

    Module stats that contain the following keys:

    • 'exploits' [Integer] The number of exploits reloaded.

    • 'auxiliary' [Integer] The number of auxiliary modules reloaded.

    • 'post' [Integer] The number of post modules reloaded.

    • 'encoders' [Integer] The number of encoders reloaded.

    • 'nops' [Integer] The number of NOP modules reloaded.

    • 'payloads' [Integer] The number of payloads reloaded.

    • 'evasions' [Integer] The number of evasion modules reloaded.



101
102
103
104
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 101

def rpc_reload_modules
  framework.modules.reload_modules
  rpc_module_stats()
end

#rpc_saveHash

Saves current framework settings.

Examples:

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

rpc.call('core.save')

Returns:

  • (Hash)

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

    • 'result' [String] The successful message: 'success'



83
84
85
86
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 83

def rpc_save
  framework.save_config
  { "result" => "success" }
end

#rpc_setg(var, val) ⇒ Hash

Sets a global datastore option.

Examples:

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

rpc.call('core.setg', 'MyGlobal', 'foobar')

Parameters:

  • var (String)

    The hash key of the global datastore option.

  • val (String)

    The value of the global datastore option.

Returns:

  • (Hash)

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

    • 'result' [String] The successful message: 'success'



53
54
55
56
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 53

def rpc_setg(var, val)
  framework.datastore[var] = val
  { "result" => "success" }
end

#rpc_stopvoid

This method returns an undefined value.

Stops the RPC service.

Examples:

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

rpc.call('core.stop')


28
29
30
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 28

def rpc_stop
  self.service.stop
end

#rpc_thread_kill(tid) ⇒ Hash

Kills a framework thread.

Examples:

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

rpc.call('core.thread_kill', 10)

Parameters:

  • tid (Integer)

    The thread ID to kill.

Returns:

  • (Hash)

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

    • 'result' [String] A successful message: 'success'



187
188
189
190
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 187

def rpc_thread_kill(tid)
  framework.threads.kill(tid.to_i) rescue nil
  { "result" => "success" }
end

#rpc_thread_listHash

Returns a list of framework threads.

Examples:

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

# You will get something like this:
# {0=>{"status"=>"sleep", "critical"=>false, "name"=>"StreamServerListener", "started"=>"2015-04-21 15:25:49 -0500"}}
rpc.call('core.thread_list')

Returns:

  • (Hash)

    A collection of threads. Each key is the thread ID, and the value is another hash that contains the following:

    • 'status' [String] Thread status.

    • 'critical' [Boolean] Thread is critical.

    • 'name' [String] Thread name.

    • 'started' [String] Timestamp of when the thread started.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 165

def rpc_thread_list
  res = {}
  framework.threads.each_index do |i|
    t = framework.threads[i]
    next if not t
    res[i] = {
      :status   => (t.status || "dead"),
      :critical => t[:tm_crit] ? true : false,
      :name     => t[:tm_name].to_s,
      :started  => t[:tm_time].to_s
    }
  end
  res
end

#rpc_unsetg(var) ⇒ Hash

Unsets a global datastore option.

Examples:

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

rpc.call('core.unsetg', 'MyGlobal')

Parameters:

  • var (String)

    The global datastore option.

Returns:

  • (Hash)

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

    • 'result' [String] The successful message: 'success'



66
67
68
69
70
71
72
73
74
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 66

def rpc_unsetg(var)
  if framework.datastore.is_a?(Msf::DataStoreWithFallbacks)
    framework.datastore.unset(var)
  else
    framework.datastore.delete(var)
  end

  { "result" => "success" }
end

#rpc_versionHash

Returns the RPC service versions.

Examples:

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

rpc.call('core.version')

Returns:

  • (Hash)

    A hash that includes the version information:

    • 'version' [String] Framework version

    • 'ruby' [String] Ruby version

    • 'api' [String] API version



14
15
16
17
18
19
20
# File 'lib/msf/core/rpc/v10/rpc_core.rb', line 14

def rpc_version
  {
    "version" => ::Msf::Framework::Version,
    "ruby"    => "#{RUBY_VERSION} #{RUBY_PLATFORM} #{RUBY_RELEASE_DATE}",
    "api"     => API_VERSION
  }
end