Class: Msf::Ui::Console::CommandDispatcher::Post

Inherits:
Object
  • Object
show all
Includes:
ModuleActionCommands, ModuleCommandDispatcher, ModuleOptionTabCompletion
Defined in:
lib/msf/ui/console/command_dispatcher/post.rb

Overview

Recon module command dispatcher.

Constant Summary collapse

@@post_opts =
Rex::Parser::Arguments.new(
  "-h" => [ false, "Help banner."                                          ],
  "-j" => [ false, "Run in the context of a job."                          ],
  "-o" => [ true,  "A comma separated list of options in VAR=VAL format."  ],
  "-q" => [ false, "Run the module in quiet mode with no output"           ]
)

Instance Attribute Summary

Attributes included from Msf::Ui::Console::CommandDispatcher

#driver

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

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from ModuleOptionTabCompletion

#option_values_actions, #option_values_dispatch, #option_values_encoders, #option_values_nops, #option_values_payloads, #option_values_sessions, #option_values_target_addrs, #option_values_target_ports, #option_values_targets, #tab_complete_datastore_names, #tab_complete_option, #tab_complete_option_names, #tab_complete_option_values, #tab_complete_source_interface

Methods included from ModuleActionCommands

#action_commands, #cmd_action_help, #cmd_run_tabs, #do_action, #method_missing, #parse_run_opts

Methods included from ModuleCommandDispatcher

#check_multiple, #check_progress, #check_show_progress, #check_simple, #cmd_check, #cmd_check_help, #cmd_reload, #cmd_reload_help, #mod, #mod=, #reload, #report_vuln

Methods included from Msf::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, #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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Msf::Ui::Console::ModuleActionCommands

Instance Method Details

#cmd_rerun(*args) ⇒ Object Also known as: cmd_rexploit

Reloads a post module and executes it


56
57
58
59
60
61
# File 'lib/msf/ui/console/command_dispatcher/post.rb', line 56

def cmd_rerun(*args)
  # Stop existing job and reload the module
  if reload(true)
    cmd_run(*args)
  end
end

#cmd_run(*args, action: nil) ⇒ Object Also known as: cmd_exploit

Executes a post module


75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
115
# File 'lib/msf/ui/console/command_dispatcher/post.rb', line 75

def cmd_run(*args, action: nil)
  return false unless (args = parse_run_opts(args, action: action))
  jobify = args[:jobify]

  # Always run passive modules in the background
  if (mod.passive)
    jobify = true
  end

  begin
    mod.run_simple(
      'Action'         => args[:action],
      'OptionStr'      => args[:datastore_options].map { |k,v| "#{k}=#{v}" }.join(','),
      'LocalInput'     => driver.input,
      'LocalOutput'    => driver.output,
      'RunAsJob'       => jobify,
      'Quiet'          => args[:quiet]
    )
  rescue ::Timeout::Error
    print_error("Post triggered a timeout exception")
  rescue ::Interrupt
    print_error("Post interrupted by the console user")
  rescue ::Exception => e
    print_error("Post failed: #{e.class} #{e}")
    if (e.class.to_s != 'Msf::OptionValidateError')
      print_error("Call stack:")
      e.backtrace.each do |line|
        break if line =~ /lib.msf.base.simple/
        print_error("  #{line}")
      end
    end

    return false
  end

  if (jobify && mod.job_id)
    print_status("Post module running as background job #{mod.job_id}.")
  else
    print_status("Post module execution completed")
  end
end

#cmd_run_helpObject Also known as: cmd_exploit_help


65
66
67
68
69
70
# File 'lib/msf/ui/console/command_dispatcher/post.rb', line 65

def cmd_run_help
  print_line "Usage: run [options]"
  print_line
  print_line "Launches a post exploitation module."
  print @@auxiliary_opts.usage
end

#commandsObject

Returns the hash of commands specific to post modules.


29
30
31
32
33
34
35
36
# File 'lib/msf/ui/console/command_dispatcher/post.rb', line 29

def commands
  super.merge({
    "run"   => "Launches the post exploitation module",
    "rerun" => "Reloads and launches the module",
    "exploit"  => "This is an alias for the run command",
    "rexploit" => "This is an alias for the rerun command",
  }).merge( (mod ? mod.post_commands : {}) )
end

#nameObject

Returns the command dispatcher name.


42
43
44
# File 'lib/msf/ui/console/command_dispatcher/post.rb', line 42

def name
  "Post"
end