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.


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

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:


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

def evasion
  @evasion
end

#force_wait_for_sessionObject

:nodoc:


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

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.


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

def job_id
  @job_id
end

#payloadObject

:nodoc:


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

def payload
  @payload
end

#semaphoreObject

To synchronize threads cleaning up the evasion


108
109
110
# File 'lib/msf/core/evasion_driver.rb', line 108

def semaphore
  @semaphore
end

#sessionObject

:nodoc:


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

def session
  @session
end

#use_jobObject

:nodoc:


98
99
100
# File 'lib/msf/core/evasion_driver.rb', line 98

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)

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

def compatible_payload?(payload)
  evasion_platform = evasion.targets[target_idx].platform || evasion.platform
  return ((payload.platform & evasion_platform).empty? == false)
end

#job_cleanup_proc(ctx) ⇒ Object (protected)

Clean up the evasion after the job completes.


127
128
129
130
131
# File 'lib/msf/core/evasion_driver.rb', line 127

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.


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

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


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

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


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

#validateObject


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

def validate
  if (payload == nil)
    raise MissingPayloadError, "A payload has not been selected.", caller
  end

  # Make sure the payload is compatible after all
  if (compatible_payload?(payload) == false)
    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