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/core/evasion_driver.rb
Views: 11780
# -*- coding: binary -*-12module Msf34class EvasionDriver56#7# Initializes the evasion driver using the supplied framework instance.8#9def initialize(framework)10self.payload = nil11self.evasion = nil12self.use_job = false13self.job_id = nil14self.force_wait_for_session = false15self.semaphore = Mutex.new16end1718def target_idx=(target_idx)19if (target_idx)20# Make sure the target index is valid21if (target_idx >= evasion.targets.length)22raise Rex::ArgumentError, "Invalid target index.", caller23end24end2526# Set the active target27@target_idx = target_idx28end2930def target_idx31@target_idx32end333435#36# Checks to see if the supplied payload is compatible with the37# current evasion module. Assumes that target_idx is valid.38#39def compatible_payload?(payload)40!evasion.compatible_payloads.find { |refname, _| refname == payload.refname }.nil?41end4243def validate44if (payload == nil)45raise MissingPayloadError, "A payload has not been selected.", caller46end4748# Make sure the payload is compatible after all49unless compatible_payload?(payload)50raise IncompatiblePayloadError.new(payload.refname), "#{payload.refname} is not a compatible payload.", caller51end5253# Associate the payload instance with the evasion54payload.assoc_exploit = evasion5556# Finally, validate options on the evasion module to ensure that things57# are ready to operate as they should.58evasion.options.validate(evasion.datastore)5960# Validate the payload's options. The payload's datastore is61# most likely shared against the evasion's datastore, but in case it62# isn't.63payload.options.validate(payload.datastore)6465return true66end6768def run69# First thing's first -- validate the state. Make sure all requirement70# parameters are set, including those that are derived from the71# datastore.72validate()7374# Explicitly clear the module's job_id in case it was set in a previous75# run76evasion.job_id = nil7778# Generate the encoded version of the supplied payload on the79# evasion module instance80evasion.generate_payload(payload)8182# No need to copy since we aren't creating a job. We wait until83# they're finished running to do anything else with them, so84# nothing should be able to modify their datastore or other85# settings until after they're done.86ctx = [ evasion, payload ]8788job_run_proc(ctx)89job_cleanup_proc(ctx)9091end9293attr_accessor :evasion # :nodoc:94attr_accessor :payload # :nodoc:95attr_accessor :use_job # :nodoc:96#97# The identifier of the job this evasion module is launched as, if it's run as a98# job.99#100attr_accessor :job_id101attr_accessor :force_wait_for_session # :nodoc:102attr_accessor :session # :nodoc:103104# To synchronize threads cleaning up the evasion105attr_accessor :semaphore106107protected108109#110# Job run proc, sets up the eevasion and kicks it off.111#112def job_run_proc(ctx)113evasion, payload = ctx114evasion.setup115evasion.framework.events.on_module_run(evasion)116117# Launch the evasion module118evasion.run119end120121#122# Clean up the evasion after the job completes.123#124def job_cleanup_proc(ctx)125evasion, payload = ctx126evasion.framework.events.on_module_complete(evasion)127semaphore.synchronize { evasion.cleanup }128end129130end131132end133134135136