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

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

Overview

Recon module command dispatcher.

Constant Summary collapse

@@auxiliary_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."                ],
  "-a" => [ true,  "The action to use.  If none is specified, ACTION is used."           ],
  "-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 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, #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, #update_prompt

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Allow modules to define their own commands


43
44
45
46
47
48
49
50
51
52
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 43

def method_missing(meth, *args)
  if (mod and mod.respond_to?(meth.to_s, true) )

    # Initialize user interaction
    mod.init_ui(driver.input, driver.output)

    return mod.send(meth.to_s, *args)
  end
  return
end

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.


201
202
203
204
205
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 201

def cmd_rcheck(*args)
  reload()

  cmd_check(*args)
end

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

Reloads an auxiliary module and executes it


187
188
189
190
191
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 187

def cmd_rerun(*args)
  if reload(true)
    cmd_run(*args)
  end
end

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

Executes an auxiliary module


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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 73

def cmd_run(*args)
  opts    = []
  action  = mod.datastore['ACTION']
  jobify  = false
  quiet   = false

  @@auxiliary_opts.parse(args) do |opt, idx, val|
    case opt
    when '-j'
      jobify = true
    when '-o'
      opts.push(val)
    when '-a'
      action = val
    when '-q'
      quiet  = true
    when '-h'
      cmd_run_help
      return false
    else
      if val[0] != '-' && val.match?('=')
        opts.push(val)
      else
        cmd_run_help
        return false
      end
    end
  end

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

  rhosts = datastore['RHOSTS']
  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.run_simple(
        'Action'         => action,
        'OptionStr'      => opts.join(','),
        'LocalInput'     => driver.input,
        'LocalOutput'    => driver.output,
        'RunAsJob'       => jobify,
        'Quiet'          => quiet
      )
    # For multi target attempts with non-scanner modules.
    else
      rhosts_opt = Msf::OptAddressRange.new('RHOSTS')
      if !rhosts_opt.valid?(rhosts)
        print_error("Auxiliary failed: option RHOSTS failed to validate.")
        return false
      end

      rhosts_range = Rex::Socket::RangeWalker.new(rhosts_opt.normalize(rhosts))
      rhosts_range.each do |rhost|
        nmod = mod.replicant
        nmod.datastore['RHOST'] = rhost
        print_status("Running module against #{rhost}")
        nmod.run_simple(
          'Action'         => action,
          'OptionStr'      => opts.join(','),
          'LocalInput'     => driver.input,
          'LocalOutput'    => driver.output,
          'RunAsJob'       => false,
          'Quiet'          => 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 ::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.job_id)
    print_status("Auxiliary module running as background job #{mod.job_id}.")
  else
    print_status("Auxiliary module execution completed")
  end
end

#cmd_run_helpObject Also known as: cmd_exploit_help


175
176
177
178
179
180
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 175

def cmd_run_help
  print_line "Usage: run [options]"
  print_line
  print_line "Launches an auxiliary module."
  print @@auxiliary_opts.usage
end

#cmd_run_tabs(str, words) ⇒ Object Also known as: cmd_exploit_tabs, cmd_rerun_tabs

Tab completion for the run command


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

def cmd_run_tabs(str, words)
  return [] if words.length > 1
  @@auxiliary_opts.fmt.keys
end

#commandsObject

Returns the hash of commands specific to auxiliary modules.


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

def commands
  super.update({
    "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.


58
59
60
# File 'lib/msf/ui/console/command_dispatcher/auxiliary.rb', line 58

def name
  "Auxiliary"
end