Class: Ronin::Exploits::Target

Inherits:
Object
  • Object
show all
Includes:
Model, Model::TargetsArch, Model::TargetsOS, Model::TargetsProduct
Defined in:
lib/ronin/exploits/target.rb

Instance Method Summary collapse

Methods included from Model::TargetsProduct

included

Methods included from Model::TargetsOS

included

Methods included from Model::TargetsArch

included

Constructor Details

#initialize(attributes = {}) {|target| ... } ⇒ Target

Creates a new ExploitTarget object

Parameters:

  • attributes (Hash) (defaults to: {})

    Additional attributes to create the target with.

Yields:

  • (target)

    If a block is given, it will be passed the new target object.

Yield Parameters:

  • target (Target)

    The newly created target object.



63
64
65
66
67
# File 'lib/ronin/exploits/target.rb', line 63

def initialize(attributes={},&block)
  super(attributes)

  block.call(self) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object (protected)

Provides transparent access to the target data Hash.

Examples:

target.ip
# => 0xff8025a0
target.ip = 0x41414141

Raises:

  • (TargetDataMissing)

    The target does not have data associated with the specified name.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ronin/exploits/target.rb', line 123

def method_missing(name,*arguments,&block)
  unless block
    name = name.to_s

    if (name[-1..-1] == '=' && arguments.length == 1)
      return self[name.chop] = arguments.first
    elsif arguments.length == 0
      unless has?(name)
        raise(TargetDataMissing,"the target is missing data for #{name.dump}",caller)
      end

      return self[name]
    end
  end

  super(name,*arguments,&block)
end

Instance Method Details

#[](name) ⇒ Object?

Returns the target data with the matching name.

Parameters:

  • name (Symbol, String)

    The name of the target data to retrieve.

Returns:

  • (Object, nil)

    The target data.



91
92
93
# File 'lib/ronin/exploits/target.rb', line 91

def [](name)
  self.data[name.to_sym]
end

#[]=(name, value) ⇒ Object

Sets the target data with the matching name.

Parameters:

  • name (Symbol, String)

    The name of the target data to set.

  • value (Object)

    The value to set for the target data.



104
105
106
# File 'lib/ronin/exploits/target.rb', line 104

def []=(name,value)
  self.data[name.to_sym] = value
end

#has?(name) ⇒ Boolean

Searches for target data with the matching name.

Parameters:

  • name (Symbol, String)

    The name to search for.

Returns:

  • (Boolean)

    Specifies whether the target contains data with the matching name.



78
79
80
# File 'lib/ronin/exploits/target.rb', line 78

def has?(name)
  self.data.has_key?(name.to_sym)
end