# # 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/vuln/behavior' module Ronin module Controls module Behaviors # # Attempts to load and extend the control module defined in # Ronin::Controls::Helpers. # # @param [Symbol, String] name # The snake-case name of the control helper module to load. # # @return [Boolean] # Specifies whether the control helper module was successfully # loaded. # # @example # control_helper :file_read # # @since 0.3.0 # def control_helper(name) name = name.to_s module_name = name.to_const_string begin require_within File.join('ronin','controls','helpers'), name rescue Gem::LoadError => e raise(e) rescue ::LoadError return false end unless Ronin::Controls::Helpers.const_defined?(module_name) return false end control_module = Ronin::Controls::Helpers.const_get(module_name) unless control_module.kind_of?(Module) return false end extend control_module return true end # # @return [Model] # The model used by the +controls+ relationship. # # @since 0.3.0 # def control_model self.class.relationships[:controls].child_model end # # Adds new behaviors to the model which are to be controlled. # # @param [Array] behaviors # The list of behaviors to be controlled. # # @example # control :code_exec, # :file_read, # :file_write, # :file_create # # @since 0.3.0 # def control(*behaviors) behaviors.each do |behavior| self.controls << control_model.new( :behavior => Vuln::Behavior[behavior] ) control_helper(behavior) end end # # Lists the behaviors to be controlled. # # @return [Array] # The behaviors controlled by the model. # # @example # behaviors # # => [:code_exec, :file_read, :file_write, :file_create] # def behaviors self.controls.map { |control| control.behavior.name.to_sym } end # # Load the code from the cached file for the object. Will also # attempt to load and extend any control modules for the controlled # behaviors. # # @since 0.3.0 # def load_original! unless original_loaded? self.behaviors.each { |name| control_helper name } end super end end end end