# #-- # 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/exploit_not_built' require 'ronin/exploits/exceptions/restricted_char' require 'ronin/exploits/exploit_target' require 'ronin/exploits/exploit' require 'ronin/chars/char_set' require 'ronin/formatting/binary' module Ronin module Exploits class BinaryExploit < Exploit objectify :ronin_binary_exploit # Targets of the exploit has n, :targets, :class_name => 'ExploitTarget' # Target index to use parameter :target_index, :value => 0, :description => 'default target index' # Custom target to use parameter :custom_target, :description => 'custom target' # String to pad extra space with parameter :pad, :value => 'A', :description => 'padding string' # Restricted characters that may not occurr in the built exploit attr_accessor :restricted # The built exploit attr_accessor :exploit # # Creates a new BinaryExploit object with the given _attributes_. # def initialize(attributes={}) super(attributes) @restricted = Chars::CharSet.new(attributes[:restricted] || []) end # # Adds an ExploitTarget with the given _attributes_. If a _block_ is # given, it will be passed the ExploitTarget. # def target(attributes={},&block) @targets << ExploitTarget.first_or_create(attributes,&block) end # # Returns the selected target. # def selected_target (@custom_target || @targets[@target_index]) end # # Creates a padded buffer of the specified _length_ using the # specified _padding_ data. # def pad_buffer(padding,length) padding = padding.to_s buffer = (padding * (length / padding.length)) pad_remaining = (length % padding.length) unless pad_remaining==0 buffer += padding[0,pad_remaining] end return buffer end # # Adds the given _chars_ to the restricted list of characters. # # restrict 0x00, "\n" # # => # # def restrict(*chars) @restricted += pattern end def build @exploit = '' return super end # # Verifies that the exploit is built and does not contain any # restricted characters. # def verify unless @exploit raise(ExploitNotBuilt,"cannot verify an unbuilt exploit",caller) end @restricted.each do |char| if @exploit.include?(char) raise(RestrictedChar,"Restricted character '#{char}' was found in the built exploit",caller) end end return super end end end end