Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/ui/console/module_action_commands.rb
Views: 11783
# -*- coding: binary -*-1require 'msf/ui/console/command_dispatcher'2require 'msf/ui/console/module_argument_parsing'34module Msf5module Ui6module Console78###9#10# A mixin to enable the ModuleCommandDispatcher to leverage module ACTIONs as commands.11#12###13module ModuleActionCommands14include Msf::Ui::Console::ModuleArgumentParsing1516#17# Returns the hash of commands specific to auxiliary modules.18#19def action_commands20return {} unless mod.respond_to?(:actions)2122mod.actions.map { |action| [action.name.downcase, action.description] }.to_h23end2425def commands26super.merge(action_commands) { |k, old_val, new_val| old_val}27end2829#30# Allow modules to define their own commands31# Note: A change to this method will most likely require a corresponding change to respond_to_missing?32#33def method_missing(meth, *args)34if mod && mod.respond_to?(meth.to_s, true)3536# Initialize user interaction37mod.init_ui(driver.input, driver.output)3839return mod.send(meth.to_s, *args)40end4142action = meth.to_s.delete_prefix('cmd_').delete_suffix('_tabs')43if mod && mod.kind_of?(Msf::Module::HasActions) && mod.actions.map(&:name).any? { |a| a.casecmp?(action) }44return cmd_run_tabs(*args) if meth.end_with?('_tabs')45return do_action(action, *args)46end4748super49end5051#52# Note: A change to this method will most likely require a corresponding change to method_missing53#54def respond_to_missing?(meth, _include_private = true)55if mod && mod.respond_to?(meth.to_s, true)56return true57end5859action = meth.to_s.delete_prefix('cmd_').delete_suffix('_tabs')60if mod && mod.kind_of?(Msf::Module::HasActions) && mod.actions.map(&:name).any? { |a| a.casecmp?(action) }61return true62end6364super65end6667#68# Execute the module with a set action69#70def do_action(meth, *args)71action = mod.actions.find { |action| action.name.casecmp?(meth) }72raise Msf::MissingActionError.new(meth) if action.nil?7374cmd_run(*args, action: action.name)75end7677def cmd_action_help(action)78print_module_run_or_check_usage(command: action.downcase, description: 'Launches a specific module action')79end8081#82# Tab completion for the run command83#84# @param str [String] the string currently being typed before tab was hit85# @param words [Array<String>] the previously completed words on the command line. words is always86# at least 1 when tab completion has reached this stage since the command itself has been completed87#88def cmd_run_tabs(str, words)89flags = @@module_opts_with_action_support.option_keys90options = tab_complete_option(active_module, str, words)91flags + options92end9394end95end96end97end9899100