Class: Msf::MCP::Tools::ModuleExecute

Inherits:
MCP::Tool
  • Object
show all
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

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

Parameters:

  • type (String)

    Module type (exploit/auxiliary/post/payload/evasion)

  • name (String)

    Module path/name

  • options (Hash)

    Datastore options forwarded unchanged to module.execute

  • server_context (Hash)

    Server context with msf_client, rate_limiter

Returns:

  • (MCP::Tool::Response)

    Structured response with job_id and uuid



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.validate_module_options!(options)

    # MCP deep-symbolizes JSON input; the Metasploit datastore is keyed by Strings.
    stringified_options = options.transform_keys(&:to_s)

    raw_result, elapsed = Rex::Stopwatch.elapsed_time do
      msf_client.module_execute(type, name, stringified_options)
    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