Class: Ronin::PostExploitation::Resource

Inherits:
Object
  • Object
show all
Includes:
UI::Printing
Defined in:
lib/ronin/post_exploitation/resource.rb

Overview

A base-class for all Post-Exploitation Resources.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Resource

Creates a new Resource.

Since:

  • 1.0.0


45
46
47
# File 'lib/ronin/post_exploitation/resource.rb', line 45

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controllerObject (readonly)

The object providing control of the Resource

Since:

  • 1.0.0


37
38
39
# File 'lib/ronin/post_exploitation/resource.rb', line 37

def controller
  @controller
end

Class Method Details

.resource_method(method_name, control_methods = []) ⇒ Object (protected)

Specifies that a Resource method requires certain methods define by the controller object.

Since:

  • 1.0.0


124
125
126
# File 'lib/ronin/post_exploitation/resource.rb', line 124

def self.resource_method(method_name,control_methods=[])
  resource_methods[method_name.to_sym] = control_methods.map(&:to_sym)
end

.resource_methodsHash{Symbol => Array<Symbol>} (protected)

The defined Resource methods.

Since:

  • 1.0.0


108
109
110
# File 'lib/ronin/post_exploitation/resource.rb', line 108

def self.resource_methods
  @resource_methods ||= {}
end

Instance Method Details

#consoleObject

Allows resources to spawn interactive consoles.

Raises:

  • (NotImplementedError)

    The console method is not implemented by default.

Since:

  • 1.0.0


94
95
96
# File 'lib/ronin/post_exploitation/resource.rb', line 94

def console
  raise(NotImplementedError,"#{self.class} does not provide a console")
end

#requires_method!(name) ⇒ true (protected)

Requires that the controlling object define the given method.

Raises:

  • (NotImplementedError)

    The method is not defined by the controlling object.

Since:

  • 1.0.0


140
141
142
143
144
145
146
# File 'lib/ronin/post_exploitation/resource.rb', line 140

def requires_method!(name)
  unless @controller.respond_to?(name)
    raise(NotImplementedError,"#{@controller.inspect} does not define #{name}")
  end

  return true
end

#supportsArray<Symbol>

Determines which Resource methods are supported by the controlling object.

Since:

  • 1.0.0


82
83
84
85
86
# File 'lib/ronin/post_exploitation/resource.rb', line 82

def supports
  self.class.resource_methods.keys.select do |method_name|
    supports?(method_name)
  end
end

#supports?(*method_names) ⇒ Boolean

Determines whether the controller object supports the Resource method(s).

Examples:

fs.supports?(:read, :write)
# => true

Since:

  • 1.0.0


64
65
66
67
68
69
70
71
72
73
# File 'lib/ronin/post_exploitation/resource.rb', line 64

def supports?(*method_names)
  method_names.all? do |method_name|
    method_name        = method_name.to_sym
    controller_methods = self.class.resource_methods[method_name]

    controller_methods && controller_methods.all? { |control_method|
      @controller.respond_to?(control_method)
    }
  end
end