# # 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) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 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/model/targets_arch' require 'ronin/model/targets_os' require 'ronin/model/targets_product' require 'ronin/model' require 'dm-types/yaml' module Ronin module Exploits class Target include Model include Model::TargetsArch include Model::TargetsOS include Model::TargetsProduct # Primary key property :id, Serial # Target comments property :description, String # 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 # # @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 # # Searches for target data with the matching name. # # @param [Symbol, String] name # The name to search for. # # @return [Boolean] # Specifies whether the target contains data with the matching name. # def has?(name) self.data.has_key?(name.to_sym) end # # 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 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 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 end end end