lib/ronin/exploits/helpers/format_string.rb in ronin-exploits-0.2.1 vs lib/ronin/exploits/helpers/format_string.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,59 +15,69 @@ # 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/targets/format_string' require 'ronin/exploits/helpers/binary' +require 'ronin/payloads/shellcode' module Ronin module Exploits module Helpers module FormatString - def self.included(base) - base.module_eval do - include Ronin::Exploits::Helpers::Binary - - has n, :targets, - :class_name => 'Ronin::Exploits::Targets::FormatString' - - # The built format string - attr_reader :format_string - end - end - def self.extended(obj) obj.instance_eval do extend Ronin::Exploits::Helpers::Binary - - # - # Returns the format string of the exploit. - # - def format_string - @format_string - end end end # - # Adds a new Targets::FormatString with the given _attributes_ - # and _block_. + # @return [String] + # The format string of the exploit. # + def format_string + @format_string ||= '' + end + + # + # Adds a new target to the exploit. + # + # @param [Hash] attributes + # Additioanl attributes to create the target with. + # + # @yield [target] + # If a block is given, it will be passed the newly created target. + # + # @yieldparam [Targets::FormatString] target + # The newly created target. + # def targeting(attributes={},&block) self.targets << Targets::FormatString.new(attributes,&block) end + # + # @return [Payloads::Shellcode] + # The model which will be searched for acceptable payloads. + # + # @since 0.3.0 + # + def use_payload_class + Payload::Shellcode + end + protected # # Builds a format string using the current target and payload to # be used in the format string exploit. # + # @return [String] + # The built format string. + # def build_format_string verify_target! buffer = pack(target.overwrite) + pack(target.overwrite + (target.arch.address_length / 2)) @@ -94,10 +103,11 @@ buffer << encoded_payload return buffer end # - # The default builder method, simply calls build_format_string. + # The default builder method which simply calls build_format_string + # and sets the +@format_string+ instance variable. # def build @format_string = build_format_string end end