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:



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

def evasion
  @evasion
end

#force_wait_for_sessionObject

:nodoc:



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

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.



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

def job_id
  @job_id
end

#payloadObject

:nodoc:



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

def payload
  @payload
end

#semaphoreObject

To synchronize threads cleaning up the evasion



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

def semaphore
  @semaphore
end

#sessionObject

:nodoc:



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

def session
  @session
end

#use_jobObject

:nodoc:



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

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
43
# File 'lib/msf/core/evasion_driver.rb', line 40

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.



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

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.



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

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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)

  # 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



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