Module: Msf::Simple::Evasion

Includes:
Module
Defined in:
lib/msf/base/simple/evasion.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Module

#_import_extra_options, #init_simplified, #inspect, #load_config, #save_config

Class Method Details

.run_simple(oevasion, opts, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
99
100
101
102
103
104
# File 'lib/msf/base/simple/evasion.rb', line 10

def self.run_simple(oevasion, opts, &block)
  evasion = oevasion.replicant
  # Trap and print errors here (makes them UI-independent)
  begin
    # Clone the module to prevent changes to the original instance

    Msf::Simple::Framework.simplify_module(evasion)
    yield(evasion) if block_given?

    # Import options from the OptionStr or Option hash.
    evasion._import_extra_options(opts)

    # Make sure parameters are valid.
    if (opts['Payload'] == nil)
      raise MissingPayloadError.new, 'A payload has not been selected.', caller
    end

    # Verify the options
    evasion.options.validate(evasion.datastore)

    # Start it up
    driver = EvasionDriver.new(evasion.framework)

    # Initialize the driver instance
    driver.evasion = evasion
    driver.payload = evasion.framework.payloads.create(opts['Payload'])

    # Was the payload valid?
    if (driver.payload == nil)
      raise MissingPayloadError,
        "You specified an invalid payload: #{opts['Payload']}", caller
    end

    # Use the supplied encoder, if any.  If one was not specified, then
    # nil will be assigned causing the evasion to default to picking the
    # best encoder.
    evasion.datastore['ENCODER'] = opts['Encoder'] if opts['Encoder']

    # Use the supplied NOP generator, if any.  If one was not specified, then
    # nil will be assigned causing the evasion to default to picking a
    # compatible NOP generator.
    evasion.datastore['NOP'] = opts['Nop'] if opts['Nop']

    # Force the payload to share the evasion's datastore
    driver.payload.share_datastore(driver.evasion.datastore)

    # Verify the payload options
    driver.payload.options.validate(driver.payload.datastore)

    # Set the target and then work some magic to derive index
    evasion.datastore['TARGET'] = opts['Target'] if opts['Target']
    target_idx = evasion.target_index

    if (target_idx == nil or target_idx < 0)
      raise MissingTargetError,
        "You must select a target.", caller
    end

    driver.target_idx = target_idx

    # Set the payload and evasion's subscriber values
    if ! opts['Quiet']
      driver.evasion.init_ui(opts['LocalInput'] || evasion.user_input, opts['LocalOutput'] || evasion.user_output)
      driver.payload.init_ui(opts['LocalInput'] || evasion.user_input, opts['LocalOutput'] || evasion.user_output)
    else
      driver.evasion.init_ui(nil, nil)
      driver.payload.init_ui(nil, nil)
    end

    if (opts['RunAsJob'])
      driver.use_job = true
    end

    # Let's rock this party
    driver.run

    # Save the job identifier this evasion is running as
    evasion.job_id  = driver.job_id

    # Propagate this back to the caller for console mgmt
    oevasion.job_id = evasion.job_id
  rescue ::Interrupt
    evasion.error = $!
    raise $!
  rescue ::Msf::OptionValidateError => e
    evasion.error = e
    ::Msf::Ui::Formatter::OptionValidateError.print_error(evasion, e)
  rescue ::Exception => e
    evasion.error = e
    evasion.print_error("evasion failed: #{e}")
    elog("Evasion failed (#{evasion.refname})", error: e)
  end

  nil
end

Instance Method Details

#run_simple(opts, &block) ⇒ Object



106
107
108
# File 'lib/msf/base/simple/evasion.rb', line 106

def run_simple(opts, &block)
  Msf::Simple::Evasion.run_simple(self, opts, &block)
end