# #-- # 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/exploits/product' require 'ronin/model/targets_arch' require 'ronin/model/targets_os' require 'ronin/model' require 'dm-types/yaml' module Ronin module Exploits class Target include Model include Model::TargetsArch include Model::TargetsOS # 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_. # 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. # # target.product # # => nil # # target.product(:name => 'Apache', :version => '1.3.3.7') # # => # # 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_. # def [](name) self.data[name.to_sym] end # # Sets the target data with the specified _name_ and _value_. # def []=(name,value) self.data[name.to_sym] = value end protected # # Provides transparent access to the target data Hash. # 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