Class: Msf::EvasionDriver
- Inherits:
-
Object
- Object
- Msf::EvasionDriver
- Defined in:
- lib/msf/core/evasion_driver.rb
Instance Attribute Summary collapse
-
#evasion ⇒ Object
:nodoc:.
-
#force_wait_for_session ⇒ Object
:nodoc:.
-
#job_id ⇒ Object
The identifier of the job this evasion module is launched as, if it’s run as a job.
-
#job_listener ⇒ Object
Returns the value of attribute job_listener.
-
#payload ⇒ Object
:nodoc:.
-
#run_uuid ⇒ Object
The run UUID generated for the most recent #run invocation.
-
#semaphore ⇒ Object
To synchronize threads cleaning up the evasion.
-
#session ⇒ Object
:nodoc:.
-
#use_job ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#compatible_payload?(payload) ⇒ Boolean
Checks to see if the supplied payload is compatible with the current evasion module.
-
#initialize(framework, job_listener: Msf::Simple::NoopJobListener.instance) ⇒ EvasionDriver
constructor
Initializes the evasion driver using the supplied framework instance.
-
#job_cleanup_proc(ctx) ⇒ Object
protected
Clean up the evasion after the job completes.
-
#job_run_proc(ctx) ⇒ Object
protected
Job run proc, sets up the eevasion and kicks it off.
- #run ⇒ Object
- #target_idx ⇒ Object
- #target_idx=(target_idx) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(framework, job_listener: Msf::Simple::NoopJobListener.instance) ⇒ EvasionDriver
Initializes the evasion driver using the supplied framework instance.
10 11 12 13 14 15 16 17 18 |
# File 'lib/msf/core/evasion_driver.rb', line 10 def initialize(framework, job_listener: Msf::Simple::NoopJobListener.instance) self.payload = nil self.evasion = nil self.use_job = false self.job_id = nil self.force_wait_for_session = false self.semaphore = Mutex.new self.job_listener = job_listener end |
Instance Attribute Details
#evasion ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/msf/core/evasion_driver.rb', line 100 def evasion @evasion end |
#force_wait_for_session ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/msf/core/evasion_driver.rb', line 114 def force_wait_for_session @force_wait_for_session end |
#job_id ⇒ Object
The identifier of the job this evasion module is launched as, if it’s run as a job.
107 108 109 |
# File 'lib/msf/core/evasion_driver.rb', line 107 def job_id @job_id end |
#job_listener ⇒ Object
Returns the value of attribute job_listener.
120 121 122 |
# File 'lib/msf/core/evasion_driver.rb', line 120 def job_listener @job_listener end |
#payload ⇒ Object
:nodoc:
101 102 103 |
# File 'lib/msf/core/evasion_driver.rb', line 101 def payload @payload end |
#run_uuid ⇒ Object
The run UUID generated for the most recent #run invocation. Used by the job listener and reported back to RPC clients via the module attribute of the same name.
113 114 115 |
# File 'lib/msf/core/evasion_driver.rb', line 113 def run_uuid @run_uuid end |
#semaphore ⇒ Object
To synchronize threads cleaning up the evasion
118 119 120 |
# File 'lib/msf/core/evasion_driver.rb', line 118 def semaphore @semaphore end |
#session ⇒ Object
:nodoc:
115 116 117 |
# File 'lib/msf/core/evasion_driver.rb', line 115 def session @session end |
#use_job ⇒ Object
:nodoc:
102 103 104 |
# File 'lib/msf/core/evasion_driver.rb', line 102 def use_job @use_job end |
Instance Method Details
#compatible_payload?(payload) ⇒ Boolean
Checks to see if the supplied payload is compatible with the current evasion module. Assumes that target_idx is valid.
41 42 43 |
# File 'lib/msf/core/evasion_driver.rb', line 41 def compatible_payload?(payload) !evasion.compatible_payloads.find { |refname, _| refname == payload.refname }.nil? end |
#job_cleanup_proc(ctx) ⇒ Object (protected)
Clean up the evasion after the job completes.
147 148 149 150 151 |
# File 'lib/msf/core/evasion_driver.rb', line 147 def job_cleanup_proc(ctx) evasion, payload = ctx evasion.framework.events.on_module_complete(evasion) semaphore.synchronize { evasion.cleanup } end |
#job_run_proc(ctx) ⇒ Object (protected)
Job run proc, sets up the eevasion and kicks it off.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/msf/core/evasion_driver.rb', line 127 def job_run_proc(ctx) evasion, payload, run_uuid, job_listener = ctx job_listener ||= self.job_listener begin job_listener.start run_uuid evasion.setup evasion.framework.events.on_module_run(evasion) # Launch the evasion module result = evasion.run job_listener.completed(run_uuid, result, evasion) rescue ::Exception => e job_listener.failed(run_uuid, e, evasion) raise end end |
#run ⇒ Object
70 71 72 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 |
# File 'lib/msf/core/evasion_driver.rb', line 70 def run # First thing's first -- validate the state. Make sure all requirement # parameters are set, including those that are derived from the # datastore. validate() # Explicitly clear the module's job_id in case it was set in a previous # run evasion.job_id = nil # Generate the encoded version of the supplied payload on the # evasion module instance evasion.generate_payload(payload) self.run_uuid = Rex::Text.rand_text_alphanumeric(24) evasion.run_uuid = self.run_uuid self.job_listener.waiting self.run_uuid # No need to copy since we aren't creating a job. We wait until # they're finished running to do anything else with them, so # nothing should be able to modify their datastore or other # settings until after they're done. ctx = [ evasion, payload, self.run_uuid, self.job_listener ] job_run_proc(ctx) job_cleanup_proc(ctx) nil end |
#target_idx ⇒ Object
32 33 34 |
# File 'lib/msf/core/evasion_driver.rb', line 32 def target_idx @target_idx end |
#target_idx=(target_idx) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/msf/core/evasion_driver.rb', line 20 def target_idx=(target_idx) if (target_idx) # Make sure the target index is valid if (target_idx >= evasion.targets.length) raise Rex::ArgumentError, "Invalid target index.", caller end end # Set the active target @target_idx = target_idx end |
#validate ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/msf/core/evasion_driver.rb', line 45 def validate if (payload == nil) raise MissingPayloadError, "A payload has not been selected.", caller end # Make sure the payload is compatible after all unless compatible_payload?(payload) raise IncompatiblePayloadError.new(payload.refname), "#{payload.refname} is not a compatible payload.", caller end # Associate the payload instance with the evasion payload.assoc_exploit = evasion # Finally, validate options on the evasion module to ensure that things # are ready to operate as they should. evasion..validate(evasion.datastore) # Validate the payload's options. The payload's datastore is # most likely shared against the evasion's datastore, but in case it # isn't. payload..validate(payload.datastore) return true end |