2006-01-24 03:59:44 +00:00
|
|
|
module Msf
|
|
|
|
module Simple
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
2009-01-09 02:16:02 +00:00
|
|
|
# A simplified auxiliary wrapper.
|
2006-01-24 03:59:44 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
module Auxiliary
|
|
|
|
|
|
|
|
include Module
|
|
|
|
|
|
|
|
#
|
2006-04-03 00:33:06 +00:00
|
|
|
# Wraps the auxiliary process in a simple single method. The options
|
|
|
|
# hash can have the following values passed in it:
|
2006-01-24 03:59:44 +00:00
|
|
|
#
|
2006-04-03 00:33:06 +00:00
|
|
|
# Action
|
|
|
|
#
|
|
|
|
# The selected action name.
|
|
|
|
#
|
|
|
|
# OptionStr
|
|
|
|
#
|
|
|
|
# A string of comma separated option values that should be imported into
|
|
|
|
# the datastore.
|
|
|
|
#
|
2007-02-24 21:42:13 +00:00
|
|
|
# Options
|
2006-04-03 00:33:06 +00:00
|
|
|
#
|
|
|
|
# A hash of values to be imported directly into the datastore.
|
|
|
|
#
|
|
|
|
# LocalInput
|
|
|
|
#
|
|
|
|
# The local input handle that data can be read in from.
|
|
|
|
#
|
|
|
|
# LocalOutput
|
|
|
|
#
|
|
|
|
# The local output through which data can be displayed.
|
|
|
|
#
|
|
|
|
# RunAsJob
|
|
|
|
#
|
|
|
|
# Whether or not the exploit should be run in the context of a background
|
|
|
|
# job.
|
|
|
|
#
|
2006-01-24 03:59:44 +00:00
|
|
|
def self.run_simple(mod, opts = {})
|
2006-03-09 17:28:37 +00:00
|
|
|
|
2006-04-03 00:33:06 +00:00
|
|
|
# Import options from the OptionStr or Option hash.
|
|
|
|
mod._import_extra_options(opts)
|
|
|
|
|
|
|
|
# Verify the ACTION
|
2006-08-12 08:31:38 +00:00
|
|
|
if (mod.actions.length > 0 and not mod.action)
|
2006-03-09 17:28:37 +00:00
|
|
|
raise MissingActionError, "You must specify a valid Action", caller
|
|
|
|
end
|
|
|
|
|
2006-04-03 00:33:06 +00:00
|
|
|
# Verify the options
|
|
|
|
mod.options.validate(mod.datastore)
|
|
|
|
|
2006-01-24 03:59:44 +00:00
|
|
|
# Initialize user interaction
|
2008-11-16 20:54:41 +00:00
|
|
|
if(not opts['Quiet'])
|
|
|
|
mod.init_ui(opts['LocalInput'],opts['LocalOutput'])
|
|
|
|
else
|
|
|
|
mod.init_ui(nil, nil)
|
|
|
|
end
|
2006-04-03 00:33:06 +00:00
|
|
|
|
2008-11-16 20:54:41 +00:00
|
|
|
if(mod.passive? or opts['RunAsJob'])
|
2007-07-03 04:20:50 +00:00
|
|
|
mod.framework.jobs.start_bg_job(
|
2006-04-03 00:33:06 +00:00
|
|
|
"Auxiliary: #{mod.refname}",
|
|
|
|
mod,
|
|
|
|
Proc.new { |mod| self.job_run_proc(mod) },
|
2007-07-03 04:20:50 +00:00
|
|
|
Proc.new { |mod| self.job_cleanup_proc(mod) }
|
2006-04-03 00:33:06 +00:00
|
|
|
)
|
2008-11-16 20:54:41 +00:00
|
|
|
else
|
|
|
|
self.job_run_proc(mod)
|
|
|
|
self.job_cleanup_proc(mod)
|
2006-04-03 00:33:06 +00:00
|
|
|
end
|
2006-01-24 03:59:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Calls the class method.
|
|
|
|
#
|
|
|
|
def run_simple(opts = {})
|
|
|
|
Msf::Simple::Auxiliary.run_simple(self, opts)
|
|
|
|
end
|
|
|
|
|
2006-04-03 00:33:06 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
#
|
|
|
|
# Job run proc, sets up the module and kicks it off.
|
|
|
|
#
|
|
|
|
def self.job_run_proc(mod)
|
|
|
|
begin
|
|
|
|
mod.setup
|
|
|
|
mod.run
|
2008-11-07 22:54:49 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
mod.print_error("Auxiliary failed: #{e.class} #{e}")
|
|
|
|
if(e.class.to_s != 'Msf::OptionValidateError')
|
|
|
|
mod.print_error("Call stack:")
|
|
|
|
e.backtrace.each do |line|
|
|
|
|
break if line =~ /lib.msf.base.simple.auxiliary.rb/
|
|
|
|
mod.print_error(" #{line}")
|
|
|
|
end
|
|
|
|
end
|
2008-11-16 20:54:41 +00:00
|
|
|
|
2008-11-07 22:54:49 +00:00
|
|
|
elog("Auxiliary failed: #{e.class} #{e}", 'core', LEV_0)
|
2006-04-03 00:33:06 +00:00
|
|
|
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3)
|
|
|
|
|
|
|
|
mod.cleanup
|
|
|
|
|
2008-07-22 21:03:59 +00:00
|
|
|
return
|
2006-04-03 00:33:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Clean up the module after the job completes.
|
|
|
|
#
|
|
|
|
def self.job_cleanup_proc(mod)
|
|
|
|
# Allow the exploit to cleanup after itself, that messy bugger.
|
|
|
|
mod.cleanup
|
|
|
|
end
|
|
|
|
|
2006-01-24 03:59:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-11-07 22:54:49 +00:00
|
|
|
end
|