Class: Msf::Plugin::MCP::McpCommandDispatcher

Inherits:
Object
  • Object
show all
Includes:
Ui::Console::CommandDispatcher
Defined in:
plugins/mcp.rb

Overview

Console command dispatcher for the ‘mcp` command and its subcommands.

Constant Summary collapse

SUBCOMMANDS =

Guard against redefinition when msfconsole’s plugin system loads the file twice

%w[status start stop restart help].freeze
VALID_OPTIONS =
%w[
  ServerHost ServerPort
  RpcHost RpcPort RpcUser RpcPass RpcSSL
  RateLimit
].freeze

Instance Attribute Summary collapse

Attributes included from Ui::Console::CommandDispatcher

#driver

Attributes included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Ui::Console::CommandDispatcher

#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #initialize, #load_config, #log_error, #remove_lines

Methods included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt

Instance Attribute Details

#pluginObject

Returns the value of attribute plugin.



32
33
34
# File 'plugins/mcp.rb', line 32

def plugin
  @plugin
end

Instance Method Details

#cmd_mcp(*args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'plugins/mcp.rb', line 42

def cmd_mcp(*args)
  subcommand = args.shift

  case subcommand
  when 'status'
    mcp_status
  when 'start'
    mcp_start(args)
  when 'stop'
    mcp_stop
  when 'restart'
    mcp_restart(args)
  else
    cmd_mcp_help
  end
end

#cmd_mcp_helpObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'plugins/mcp.rb', line 59

def cmd_mcp_help
  print_line('Usage: mcp <subcommand> [options]')
  print_line
  print_line('Subcommands:')
  print_line('  status  - Display MCP server status')
  print_line('  start   - Start the MCP server')
  print_line('  stop    - Stop the MCP server')
  print_line('  restart - Restart the MCP server')
  print_line('  help    - Show this help message')
  print_line
  print_line('Options (for start/restart):')
  print_line('  ServerHost=<host>           MCP server bind address (default: localhost)')
  print_line('  ServerPort=<port>           MCP server port (default: 3000)')
  print_line('  RpcHost=<host>              RPC server host (default: 127.0.0.1)')
  print_line('  RpcPort=<port>              RPC server port (default: 55552)')
  print_line('  RpcUser=<user>              RPC username (default: msf)')
  print_line('  RpcPass=<pass>              RPC password')
  print_line('  RpcSSL=<true|false>         Use SSL for RPC (default: false)')
  print_line('  RateLimit=<n>               Requests per minute (default: 60)')
  print_line
  print_line('Examples:')
  print_line('  mcp start')
  print_line('  mcp start ServerPort=8080')
  print_line('  mcp start RpcUser=msf RpcPass=secret')
  print_line
end

#cmd_mcp_tabs(str, words) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'plugins/mcp.rb', line 86

def cmd_mcp_tabs(str, words)
  # words[0] is always 'mcp' (the command name itself)
  # When words.length == 1, user is typing the subcommand
  # When words.length >= 2, subcommand is words[1] and user is typing options
  if words.length == 1
    return SUBCOMMANDS.select { |s| s.start_with?(str.downcase) }
  end

  subcommand = words[1]
  if %w[start restart].include?(subcommand)
    VALID_OPTIONS.map { |opt| "#{opt}=" }.select { |o| o.downcase.start_with?(str.downcase) }
  else
    []
  end
end

#commandsObject



38
39
40
# File 'plugins/mcp.rb', line 38

def commands
  { 'mcp' => 'Manage the MCP server' }
end

#nameObject



34
35
36
# File 'plugins/mcp.rb', line 34

def name
  'MCP'
end