Class: Msf::EvasionDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/evasion_driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework) ⇒ EvasionDriver

Initializes the evasion driver using the supplied framework instance.



10
11
12
13
14
15
16
17
# File 'lib/msf/core/evasion_driver.rb', line 10

def initialize(framework)
  self.payload                = nil
  self.evasion                = nil
  self.use_job                = false
  self.job_id                 = nil
  self.force_wait_for_session = false
  self.semaphore              = Mutex.new
end

Instance Attribute Details

#evasionObject

:nodoc:



94
95
96
# File 'lib/msf/core/evasion_driver.rb', line 94

def evasion
  @evasion
end

#force_wait_for_sessionObject

:nodoc:



102
103
104
# File 'lib/msf/core/evasion_driver.rb', line 102

def force_wait_for_session
  @force_wait_for_session
end

#job_idObject

The identifier of the job this evasion module is launched as, if it’s run as a job.



101
102
103
# File 'lib/msf/core/evasion_driver.rb', line 101

def job_id
  @job_id
end

#payloadObject

:nodoc:



95
96
97
# File 'lib/msf/core/evasion_driver.rb', line 95

def payload
  @payload
end

#semaphoreObject

To synchronize threads cleaning up the evasion



106
107
108
# File 'lib/msf/core/evasion_driver.rb', line 106

def semaphore
  @semaphore
end

#sessionObject

:nodoc:



103
104
105
# File 'lib/msf/core/evasion_driver.rb', line 103

def session
  @session
end

#use_jobObject

:nodoc:



96
97
98
# File 'lib/msf/core/evasion_driver.rb', line 96

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.

Returns:

  • (Boolean)


40
41
42
# File 'lib/msf/core/evasion_driver.rb', line 40

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.



125
126
127
128
129
# File 'lib/msf/core/evasion_driver.rb', line 125

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.



113
114
115
116
117
118
119
120
# File 'lib/msf/core/evasion_driver.rb', line 113

def job_run_proc(ctx)
  evasion, payload = ctx
  evasion.setup
  evasion.framework.events.on_module_run(evasion)

  # Launch the evasion module
  evasion.run
end

#runObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/msf/core/evasion_driver.rb', line 69

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)

  # 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 ]

  job_run_proc(ctx)
  job_cleanup_proc(ctx)

end

#target_idxObject



31
32
33
# File 'lib/msf/core/evasion_driver.rb', line 31

def target_idx
  @target_idx
end

#target_idx=(target_idx) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/msf/core/evasion_driver.rb', line 19

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

#validateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/msf/core/evasion_driver.rb', line 44

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.options.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.options.validate(payload.datastore)

  return true
end