Class: Msf::Plugin::MCP
- Inherits:
-
Msf::Plugin
- Object
- Msf::Plugin
- Msf::Plugin::MCP
- 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 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.
152 153 154 155 156 157 158 159 |
# File 'plugins/mcp.rb', line 152 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.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def auto_started_rpc @auto_started_rpc end |
#mcp_server ⇒ Object
Returns the value of attribute mcp_server.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def mcp_server @mcp_server end |
#msf_client ⇒ Object
Returns the value of attribute msf_client.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def msf_client @msf_client end |
#rate_limiter ⇒ Object
Returns the value of attribute rate_limiter.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def rate_limiter @rate_limiter end |
#server_config ⇒ Object
Returns the value of attribute server_config.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def server_config @server_config end |
#server_thread ⇒ Object
Returns the value of attribute server_thread.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def server_thread @server_thread end |
#started_at ⇒ Object
Returns the value of attribute started_at.
149 150 151 |
# File 'plugins/mcp.rb', line 149 def started_at @started_at end |
Instance Method Details
#cleanup ⇒ Object
Cleans up resources when the plugin is unloaded.
178 179 180 181 182 183 184 185 186 |
# File 'plugins/mcp.rb', line 178 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.
171 172 173 |
# File 'plugins/mcp.rb', line 171 def desc 'Manages the Metasploit MCP server from within msfconsole' end |
#name ⇒ Object
Returns ‘mcp’
164 165 166 |
# File 'plugins/mcp.rb', line 164 def name 'mcp' end |
#print_mcp_status ⇒ Object
Public interface for the command dispatcher to control the server.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'plugins/mcp.rb', line 192 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
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'plugins/mcp.rb', line 239 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 print_error("Failed to restart MCP server: #{e.}") end |
#start_server(opts = {}) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'plugins/mcp.rb', line 210 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 print_error("Failed to start MCP server: #{e.}") end |
#stop_server ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'plugins/mcp.rb', line 229 def stop_server unless @mcp_server print_error('MCP server is already stopped') return end stop_mcp_server print_status('MCP server stopped') end |