Class: Msf::MCP::Tools::ModuleExecute
- Inherits:
-
MCP::Tool
- Object
- MCP::Tool
- Msf::MCP::Tools::ModuleExecute
- Extended by:
- ToolHelper
- Defined in:
- lib/msf/core/mcp/tools/module_execute.rb
Overview
MCP Tool: Execute a Metasploit Module
Invokes the Metasploit Framework ‘module.execute` RPC endpoint to start an exploit, auxiliary, post, payload, or evasion module. Returns the job_id and run UUID, which can later be polled via ModuleResults.
Constant Summary collapse
- EXECUTE_SUPPORTED_TYPES =
Module types accepted by module.execute.
%w[exploit auxiliary post payload evasion].freeze
Constants included from ToolHelper
ToolHelper::DANGEROUS_MODE_DISABLED_MESSAGE
Class Method Summary collapse
-
.call(type:, name:, options:, server_context:) ⇒ MCP::Tool::Response
Execute module run.
Methods included from ToolHelper
dangerous_mode_required!, tool_error_response, with_tool_context
Class Method Details
.call(type:, name:, options:, server_context:) ⇒ MCP::Tool::Response
Execute module run
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/msf/core/mcp/tools/module_execute.rb', line 89 def call(type:, name:, options:, server_context:) with_tool_context(server_context, 'module_execute', dangerous: true) do |msf_client| Msf::MCP::Security::InputValidator.validate_parameter!('Module type', type, EXECUTE_SUPPORTED_TYPES) Msf::MCP::Security::InputValidator.validate_module_name!(name) Msf::MCP::Security::InputValidator.() # MCP deep-symbolizes JSON input; the Metasploit datastore is keyed by Strings. = .transform_keys(&:to_s) raw_result, elapsed = Rex::Stopwatch.elapsed_time do msf_client.module_execute(type, name, ) end data = { job_id: raw_result['job_id'], uuid: raw_result['uuid'] } = { query_time: elapsed.round(3) } ::MCP::Tool::Response.new( [{ type: 'text', text: JSON.generate(metadata: , data: data) }], structured_content: { metadata: , data: data } ) end end |