Module: Ronin::Controls::Behaviors

Included in:
Exploits::Exploit, Payloads::Payload
Defined in:
lib/ronin/controls/behaviors.rb

Instance Method Summary collapse

Instance Method Details

#behaviorsArray<Symbol>

Lists the behaviors to be controlled.

Examples:

behaviors
# => [:code_exec, :file_read, :file_write, :file_create]

Returns:

  • (Array<Symbol>)

    The behaviors controlled by the model.



113
114
115
# File 'lib/ronin/controls/behaviors.rb', line 113

def behaviors
  self.controls.map { |control| control.behavior.name.to_sym }
end

#control(*behaviors) ⇒ Object

Adds new behaviors to the model which are to be controlled.

Examples:

control :code_exec,
        :file_read,
        :file_write,
        :file_create

Parameters:

  • behaviors (Array<Symbol>)

    The list of behaviors to be controlled.

Since:

  • 0.3.0



93
94
95
96
97
98
99
100
101
# File 'lib/ronin/controls/behaviors.rb', line 93

def control(*behaviors)
  behaviors.each do |behavior|
    self.controls << control_model.new(
      :behavior => Vuln::Behavior[behavior]
    )

    control_helper(behavior)
  end
end

#control_helper(name) ⇒ Boolean

Attempts to load and extend the control module defined in Ronin::Controls::Helpers.

Examples:

control_helper :file_read

Parameters:

  • name (Symbol, String)

    The snake-case name of the control helper module to load.

Returns:

  • (Boolean)

    Specifies whether the control helper module was successfully loaded.

Since:

  • 0.3.0



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
# File 'lib/ronin/controls/behaviors.rb', line 43

def control_helper(name)
  name = name.to_s
  module_name = name.to_const_string

  begin
    require_within File.join('ronin','controls','helpers'), name
  rescue Gem::LoadError => e
    raise(e)
  rescue ::LoadError
    return false
  end

  unless Ronin::Controls::Helpers.const_defined?(module_name)
    return false
  end

  control_module = Ronin::Controls::Helpers.const_get(module_name)

  unless control_module.kind_of?(Module)
    return false
  end

  extend control_module
  return true
end

#control_modelModel

Returns The model used by the controls relationship.

Returns:

  • (Model)

    The model used by the controls relationship.

Since:

  • 0.3.0



75
76
77
# File 'lib/ronin/controls/behaviors.rb', line 75

def control_model
  self.class.relationships[:controls].child_model
end

#load_original!Object

Load the code from the cached file for the object. Will also attempt to load and extend any control modules for the controlled behaviors.

Since:

  • 0.3.0



124
125
126
127
128
129
130
# File 'lib/ronin/controls/behaviors.rb', line 124

def load_original!
  unless original_loaded?
    self.behaviors.each { |name| control_helper name }
  end

  super
end