lib/ronin/exploits/target.rb in ronin-exploits-0.2.1 vs lib/ronin/exploits/target.rb in ronin-exploits-0.3.0

- old
+ new

@@ -1,7 +1,6 @@ # -#-- # Ronin Exploits - A Ruby library for Ronin that provides exploitation and # payload crafting functionality. # # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com) # @@ -16,17 +15,16 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#++ # require 'ronin/exploits/exceptions/target_data_missing' -require 'ronin/exploits/product' require 'ronin/model/targets_arch' require 'ronin/model/targets_os' +require 'ronin/model/targets_product' require 'ronin/model' require 'dm-types/yaml' module Ronin @@ -34,81 +32,94 @@ class Target include Model include Model::TargetsArch include Model::TargetsOS + include Model::TargetsProduct # Primary key property :id, Serial # Target comments property :description, String - # Targeted product - belongs_to :product - # The exploit the target belongs to belongs_to :exploit # The extra target data to use for the exploit property :data, Yaml, :default => {} # - # Creates a new ExploitTarget object with the given _attributes_ - # and the given _block_. + # Creates a new ExploitTarget object # + # @param [Hash] attributes + # Additional attributes to create the target with. + # + # @yield [target] + # If a block is given, it will be passed the new target object. + # + # @yieldparam [Target] target + # The newly created target object. + # def initialize(attributes={},&block) super(attributes) block.call(self) if block end # - # Returns the Product if no _arguments_ are given. If _arguments_ are - # given, a new Product object will be created from the given - # _arguments_ and associated with the target. + # Searches for target data with the matching name. # - # target.product - # # => nil + # @param [Symbol, String] name + # The name to search for. # - # target.product(:name => 'Apache', :version => '1.3.3.7') - # # => #<Ronin::Product type=Ronin::Product id=nil name="Apache" - # # version="1.3.3.7" vendor="Apache"> + # @return [Boolean] + # Specifies whether the target contains data with the matching name. # - def product(*arguments) - unless arguments.empty? - return self.product = Product.first_or_create(*arguments) - else - return product_association - end - end - - # - # Returns +true+ if the target contains data with the specified - # _name_, returns +false+ otherwise. - # def has?(name) self.data.has_key?(name.to_sym) end # - # Returns the target data with the specified _name_. + # Returns the target data with the matching name. # + # @param [Symbol, String] name + # The name of the target data to retrieve. + # + # @return [Object, nil] + # The target data. + # def [](name) self.data[name.to_sym] end # - # Sets the target data with the specified _name_ and _value_. + # Sets the target data with the matching name. # + # @param [Symbol, String] name + # The name of the target data to set. + # + # @param [Object] value + # The value to set for the target data. + # def []=(name,value) self.data[name.to_sym] = value end protected # # Provides transparent access to the target data Hash. + # + # @raise [TargetDataMissing] + # The target does not have data associated with the specified name. + # + # @example + # target.ip + # # => 0xff8025a0 + # + # @example + # target.ip = 0x41414141 # def method_missing(name,*arguments,&block) unless block name = name.to_s