Class: Msf::Plugin::MCP
- Inherits:
-
Msf::Plugin
- Object
- Msf::Plugin
- Msf::Plugin::MCP
- Includes:
- Exploit::Retry
- Defined in:
- plugins/mcp.rb
Overview
This plugin manages the lifecycle of the Metasploit MCP (Model Context Protocol) server from within the msfconsole session.
Defined Under Namespace
Classes: McpCommandDispatcher
Instance Attribute Summary collapse
-
#auto_started_rpc ⇒ Object
Returns the value of attribute auto_started_rpc.
-
#mcp_server ⇒ Object
Returns the value of attribute mcp_server.
-
#msf_client ⇒ Object
Returns the value of attribute msf_client.
-
#rate_limiter ⇒ Object
Returns the value of attribute rate_limiter.
-
#server_config ⇒ Object
Returns the value of attribute server_config.
-
#server_thread ⇒ Object
Returns the value of attribute server_thread.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
Attributes inherited from Msf::Plugin
Attributes included from Framework::Offspring
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleans up resources when the plugin is unloaded.
-
#desc ⇒ Object
Returns the plugin description.
-
#initialize(framework, opts) ⇒ MCP
constructor
A new instance of MCP.
-
#name ⇒ Object
Returns ‘mcp’.
-
#print_mcp_status ⇒ Object
Public interface for the command dispatcher to control the server.
- #restart_server(opts = {}) ⇒ Object
- #start_server(opts = {}) ⇒ Object
- #stop_server ⇒ Object
Methods included from Exploit::Retry
#poll_until_truthy, #retry_until_truthy
Methods inherited from Msf::Plugin
#add_console_dispatcher, create, #flush, #input, #output, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #remove_console_dispatcher
Constructor Details
#initialize(framework, opts) ⇒ MCP
Returns a new instance of MCP.
157 158 159 160 161 162 163 164 |
# File 'plugins/mcp.rb', line 157 def initialize(framework, opts) super @server_config = nil @auto_started_rpc = false register_dispatcher print_status("MCP plugin loaded. Use #{Msf::Ui::Tip.highlight('mcp start')} to start the server.") end |
Instance Attribute Details
#auto_started_rpc ⇒ Object
Returns the value of attribute auto_started_rpc.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def auto_started_rpc @auto_started_rpc end |
#mcp_server ⇒ Object
Returns the value of attribute mcp_server.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def mcp_server @mcp_server end |
#msf_client ⇒ Object
Returns the value of attribute msf_client.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def msf_client @msf_client end |
#rate_limiter ⇒ Object
Returns the value of attribute rate_limiter.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def rate_limiter @rate_limiter end |
#server_config ⇒ Object
Returns the value of attribute server_config.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def server_config @server_config end |
#server_thread ⇒ Object
Returns the value of attribute server_thread.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def server_thread @server_thread end |
#started_at ⇒ Object
Returns the value of attribute started_at.
154 155 156 |
# File 'plugins/mcp.rb', line 154 def started_at @started_at end |
Instance Method Details
#cleanup ⇒ Object
Cleans up resources when the plugin is unloaded.
183 184 185 186 187 188 189 190 191 |
# File 'plugins/mcp.rb', line 183 def cleanup if @mcp_server stop_mcp_server print_status('MCP server stopped') end deregister_dispatcher unload_auto_started_rpc super end |
#desc ⇒ Object
Returns the plugin description.
176 177 178 |
# File 'plugins/mcp.rb', line 176 def desc 'Manages the Metasploit MCP server from within msfconsole' end |
#name ⇒ Object
Returns ‘mcp’
169 170 171 |
# File 'plugins/mcp.rb', line 169 def name 'mcp' end |
#print_mcp_status ⇒ Object
Public interface for the command dispatcher to control the server.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'plugins/mcp.rb', line 197 def print_mcp_status unless @server_config print_status('MCP server status: stopped (not configured)') print_status(" Use #{Msf::Ui::Tip.highlight('mcp start')} to configure and start the server") return end mcp_config = @server_config[:mcp] if @mcp_server print_status('MCP server status: running') print_status(" Listening: http://#{Rex::Socket.(mcp_config[:host], mcp_config[:port])}") print_status(" Uptime: #{format_uptime}") else print_status('MCP server status: stopped') end end |
#restart_server(opts = {}) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'plugins/mcp.rb', line 246 def restart_server(opts = {}) stop_mcp_server if @mcp_server unload_auto_started_rpc (opts) @server_config = resolve_config(opts) @server_config[:rpc] = resolve_rpc_config(opts) rpc = @server_config[:rpc] start_mcp_server(rpc, @server_config) rescue StandardError => e # Ensure server is left in a clean stopped state on failure stop_mcp_server unload_auto_started_rpc # Prevent stale config from making status report a "stopped" server @server_config = nil print_error("Failed to restart MCP server: #{e.}") end |
#start_server(opts = {}) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'plugins/mcp.rb', line 215 def start_server(opts = {}) if @mcp_server print_error('MCP server is already running') return end (opts) @server_config = resolve_config(opts) @server_config[:rpc] = resolve_rpc_config(opts) rpc = @server_config[:rpc] start_mcp_server(rpc, @server_config) rescue StandardError => e # Ensure server is left in a clean stopped state on failure stop_mcp_server unload_auto_started_rpc # Prevent stale config from making status report a "stopped" server @server_config = nil print_error("Failed to start MCP server: #{e.}") end |
#stop_server ⇒ Object
236 237 238 239 240 241 242 243 244 |
# File 'plugins/mcp.rb', line 236 def stop_server unless @mcp_server print_error('MCP server is already stopped') return end stop_mcp_server print_status('MCP server stopped') end |