Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/base/simple/evasion.rb
Views: 11784
# -*- coding: binary -*-12module Msf3module Simple45module Evasion67include Module89def self.run_simple(oevasion, opts, &block)10evasion = oevasion.replicant11# Trap and print errors here (makes them UI-independent)12begin13# Clone the module to prevent changes to the original instance1415Msf::Simple::Framework.simplify_module(evasion)16yield(evasion) if block_given?1718# Import options from the OptionStr or Option hash.19evasion._import_extra_options(opts)2021# Make sure parameters are valid.22if (opts['Payload'] == nil)23raise MissingPayloadError.new, 'A payload has not been selected.', caller24end2526# Verify the options27evasion.options.validate(evasion.datastore)2829# Start it up30driver = EvasionDriver.new(evasion.framework)3132# Initialize the driver instance33driver.evasion = evasion34driver.payload = evasion.framework.payloads.create(opts['Payload'])3536# Was the payload valid?37if (driver.payload == nil)38raise MissingPayloadError,39"You specified an invalid payload: #{opts['Payload']}", caller40end4142# Use the supplied encoder, if any. If one was not specified, then43# nil will be assigned causing the evasion to default to picking the44# best encoder.45evasion.datastore['ENCODER'] = opts['Encoder'] if opts['Encoder']4647# Use the supplied NOP generator, if any. If one was not specified, then48# nil will be assigned causing the evasion to default to picking a49# compatible NOP generator.50evasion.datastore['NOP'] = opts['Nop'] if opts['Nop']5152# Force the payload to share the evasion's datastore53driver.payload.share_datastore(driver.evasion.datastore)5455# Verify the payload options56driver.payload.options.validate(driver.payload.datastore)5758# Set the target and then work some magic to derive index59evasion.datastore['TARGET'] = opts['Target'] if opts['Target']60target_idx = evasion.target_index6162if (target_idx == nil or target_idx < 0)63raise MissingTargetError,64"You must select a target.", caller65end6667driver.target_idx = target_idx6869# Set the payload and evasion's subscriber values70if ! opts['Quiet']71driver.evasion.init_ui(opts['LocalInput'] || evasion.user_input, opts['LocalOutput'] || evasion.user_output)72driver.payload.init_ui(opts['LocalInput'] || evasion.user_input, opts['LocalOutput'] || evasion.user_output)73else74driver.evasion.init_ui(nil, nil)75driver.payload.init_ui(nil, nil)76end7778if (opts['RunAsJob'])79driver.use_job = true80end8182# Let's rock this party83driver.run8485# Save the job identifier this evasion is running as86evasion.job_id = driver.job_id8788# Propagate this back to the caller for console mgmt89oevasion.job_id = evasion.job_id90rescue ::Interrupt91evasion.error = $!92raise $!93rescue ::Msf::OptionValidateError => e94evasion.error = e95::Msf::Ui::Formatter::OptionValidateError.print_error(evasion, e)96rescue ::Exception => e97evasion.error = e98evasion.print_error("evasion failed: #{e}")99elog("Evasion failed (#{evasion.refname})", error: e)100end101102nil103end104105def run_simple(opts, &block)106Msf::Simple::Evasion.run_simple(self, opts, &block)107end108109end110111end112end113114115116