Class: Msf::Ui::Console::CommandDispatcher::Auxiliary

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

Overview

Recon module command dispatcher.

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_module_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, #respond_to_missing?

Methods included from ModuleArgumentParsing

#append_datastore_option, #parse_check_opts, #parse_exploit_opts, #parse_opts, #parse_run_opts, #print_module_run_or_check_usage, #quote_whitespaced_value, #resembles_datastore_assignment?, #resembles_rhost_value?

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, 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

Dynamic Method Handling

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

Instance Method Details

#cmd_rcheck(*args) ⇒ Object Also known as: cmd_recheck

Reloads an auxiliary module and checks the target to see if it’s vulnerable.



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 158

def cmd_rcheck(*args)
  opts = {}
  if args.include?('-r') || args.include?('--reload-libs')
    driver.run_single('reload_lib -a')
    opts[:previously_reloaded] = true
  end

  reload()

  cmd_check(*args, opts: opts)
end

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

Reloads an auxiliary module and executes it



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 138

def cmd_rerun(*args)
  opts = {}
  if args.include?('-r') || args.include?('--reload-libs')
    driver.run_single('reload_lib -a')
    opts[:previously_reloaded] = true
  end

  if reload(true)
    cmd_run(*args, opts: opts)
  end
end

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

Executes an auxiliary module



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
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
116
117
118
119
120
121
122
123
124
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 44

def cmd_run(*args, action: nil, opts: {})
  if (args.include?('-r') || args.include?('--reload-libs')) && !opts[:previously_reloaded]
    driver.run_single('reload_lib -a')
  end

  return false unless (args = parse_run_opts(args, action: action))
  jobify = args[:jobify]

  # Always run passive modules in the background
  if mod.is_a?(Msf::Module::HasActions) &&
      (mod.passive || mod.passive_action?(args[:action] || mod.default_action))
    jobify = true
  end

  mod_with_opts = mod.replicant
  mod_with_opts.datastore.import_options_from_hash(args[:datastore_options])
  rhosts = mod_with_opts.datastore['RHOSTS']
  rhosts_walker = Msf::RhostsWalker.new(rhosts, mod_with_opts.datastore)

  begin
    mod_with_opts.validate
  rescue ::Msf::OptionValidateError => e
    ::Msf::Ui::Formatter::OptionValidateError.print_error(mod_with_opts, e)
    return false
  end

  begin
    # Check if this is a scanner module or doesn't target remote hosts
    if rhosts.blank? || mod.class.included_modules.include?(Msf::Auxiliary::Scanner)
      mod_with_opts.run_simple(
        'Action'         => args[:action],
        'LocalInput'     => driver.input,
        'LocalOutput'    => driver.output,
        'RunAsJob'       => jobify,
        'Quiet'          => args[:quiet]
      )
    # For multi target attempts with non-scanner modules.
    else
      rhosts_walker.each do |datastore|
        mod_with_opts = mod.replicant
        mod_with_opts.datastore.merge!(datastore)
        print_status("Running module against #{datastore['RHOSTS']}")
        mod_with_opts.run_simple(
          'Action'         => args[:action],
          'LocalInput'     => driver.input,
          'LocalOutput'    => driver.output,
          'RunAsJob'       => false,
          'Quiet'          => args[:quiet]
        )
      end
    end
  rescue ::Timeout::Error
    print_error("Auxiliary triggered a timeout exception")
    print_error("Call stack:")
    e.backtrace.each do |line|
      break if line =~ /lib.msf.base.simple/
      print_error("  #{line}")
    end
  rescue ::Interrupt
    print_error("Auxiliary interrupted by the console user")
  rescue ::Msf::OptionValidateError => e
    ::Msf::Ui::Formatter::OptionValidateError.print_error(running_mod, e)
  rescue ::Exception => e
    print_error("Auxiliary 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_with_opts.job_id)
    print_status("Auxiliary module running as background job #{mod_with_opts.job_id}.")
  else
    print_status("Auxiliary module execution completed")
  end
end

#cmd_run_helpObject Also known as: cmd_exploit_help



129
130
131
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 129

def cmd_run_help
  print_module_run_or_check_usage(command: :run, options: @@module_opts)
end

#commandsObject

Returns the hash of commands specific to auxiliary modules.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 21

def commands
  super.merge({
    "run"      => "Launches the auxiliary module",
    "rcheck"   => "Reloads the module and checks if the target is vulnerable",
    "rerun"    => "Reloads and launches the auxiliary module",
    "exploit"  => "This is an alias for the run command",
    "recheck"  => "This is an alias for the rcheck command",
    "rexploit" => "This is an alias for the rerun command",
    "reload"   => "Reloads the auxiliary module"
  }).merge( (mod ? mod.auxiliary_commands : {}) )
end

#nameObject

Returns the command dispatcher name.



37
38
39
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 37

def name
  "Auxiliary"
end