2010-03-26 01:21:01 +00:00
|
|
|
module Msf
|
2006-01-24 03:59:44 +00:00
|
|
|
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.
|
2009-11-12 05:56:52 +00:00
|
|
|
#
|
2006-01-24 03:59:44 +00:00
|
|
|
def self.run_simple(mod, opts = {})
|
2006-03-09 17:28:37 +00:00
|
|
|
|
2012-02-29 07:34:29 +00:00
|
|
|
# Clone the module to prevent changes to the original instance
|
|
|
|
mod = mod.replicant
|
|
|
|
|
2006-04-03 00:33:06 +00:00
|
|
|
# Import options from the OptionStr or Option hash.
|
|
|
|
mod._import_extra_options(opts)
|
2009-09-26 22:34:48 +00:00
|
|
|
|
|
|
|
mod.datastore['ACTION'] = opts['Action'] if opts['Action']
|
2009-11-12 05:56:52 +00:00
|
|
|
|
2006-04-03 00:33:06 +00:00
|
|
|
# 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
|
2010-03-08 04:47:40 +00:00
|
|
|
if ! opts['Quiet']
|
|
|
|
mod.init_ui(opts['LocalInput'] || mod.user_input, opts['LocalOutput'] || mod.user_output)
|
2008-11-16 20:54:41 +00:00
|
|
|
else
|
|
|
|
mod.init_ui(nil, nil)
|
|
|
|
end
|
2006-04-03 00:33:06 +00:00
|
|
|
|
2010-07-01 22:02:46 +00:00
|
|
|
ctx = [ mod ]
|
2008-11-16 20:54:41 +00:00
|
|
|
if(mod.passive? or opts['RunAsJob'])
|
2010-03-12 02:39:02 +00:00
|
|
|
mod.job_id = mod.framework.jobs.start_bg_job(
|
2009-11-12 05:56:52 +00:00
|
|
|
"Auxiliary: #{mod.refname}",
|
2010-07-01 22:02:46 +00:00
|
|
|
ctx,
|
|
|
|
Proc.new { |ctx_| self.job_run_proc(ctx_) },
|
|
|
|
Proc.new { |ctx_| self.job_cleanup_proc(ctx_) }
|
2006-04-03 00:33:06 +00:00
|
|
|
)
|
2008-11-16 20:54:41 +00:00
|
|
|
else
|
2010-07-01 22:02:46 +00:00
|
|
|
self.job_run_proc(ctx)
|
|
|
|
self.job_cleanup_proc(ctx)
|
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 = {})
|
2009-11-12 05:56:52 +00:00
|
|
|
Msf::Simple::Auxiliary.run_simple(self, opts)
|
2006-01-24 03:59:44 +00:00
|
|
|
end
|
|
|
|
|
2006-04-03 00:33:06 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
#
|
|
|
|
# Job run proc, sets up the module and kicks it off.
|
|
|
|
#
|
2010-07-01 22:02:46 +00:00
|
|
|
def self.job_run_proc(ctx)
|
|
|
|
mod = ctx[0]
|
2006-04-03 00:33:06 +00:00
|
|
|
begin
|
|
|
|
mod.setup
|
2010-01-15 00:32:48 +00:00
|
|
|
mod.framework.events.on_module_run(mod)
|
2006-04-03 00:33:06 +00:00
|
|
|
mod.run
|
2010-04-06 02:05:50 +00:00
|
|
|
rescue ::Timeout::Error => e
|
|
|
|
mod.error = e
|
|
|
|
mod.print_error("Auxiliary triggered a timeout exception")
|
|
|
|
mod.cleanup
|
|
|
|
return
|
|
|
|
rescue ::Interrupt => e
|
|
|
|
mod.error = e
|
2009-11-12 05:56:52 +00:00
|
|
|
mod.print_error("Auxiliary interrupted by the console user")
|
|
|
|
mod.cleanup
|
|
|
|
return
|
2008-11-07 22:54:49 +00:00
|
|
|
rescue ::Exception => e
|
2010-03-26 01:18:10 +00:00
|
|
|
mod.error = e
|
2008-11-07 22:54:49 +00:00
|
|
|
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.
|
|
|
|
#
|
2010-07-01 22:02:46 +00:00
|
|
|
def self.job_cleanup_proc(ctx)
|
|
|
|
mod = ctx[0]
|
2010-03-16 19:32:54 +00:00
|
|
|
mod.framework.events.on_module_complete(mod)
|
2006-04-03 00:33:06 +00:00
|
|
|
# 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
|
2009-11-12 05:56:52 +00:00
|
|
|
|