# # 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/payloads' require 'ronin/ui/command_line/command' require 'ronin/database' require 'parameters/parser' module Ronin module UI module CommandLine module Commands class Payload < Command desc "payload [NAME] [options]", "Builds the specified Payload" method_option :database, :type => :string, :default => Database.config, :aliases => '-D' method_option :params, :type => :array, :default => [], :aliases => '-p' method_option :host, :type => :string method_option :port, :type => :numeric method_option :local_host, :type => :string method_option :local_port, :type => :numeric method_option :file, :type => :string, :aliases => '-f' method_option :describing, :type => :string, :aliases => '-d' method_option :version, :type => :string, :aliases => '-V' method_option :license, :type => :string, :aliases => '-l' method_option :arch, :type => :string, :aliases => '-a' method_option :os, :type => :string, :aliases => '-o' method_option :raw, :type => :boolean, :aliases => '-r' def default(name=nil) UI::Output.silent = true if options.raw? Database.setup(options[:database]) # Load the payload if options[:file] load_payload! else find_payload!(name) end unless @payload print_error "Could not find the specified payload" exit -1 end params = Parameters::Parser.parse(options[:params]) params[:host] = options[:host] if options[:host] params[:port] = options[:port] if options[:port] params[:local_host] = options[:local_host] if options[:local_host] params[:local_port] = options[:local_port] if options[:local_port] begin # Build the payload @payload.build!(params) rescue Parameters::MissingParam, Payloads::Exception => e print_error(e.message) end raw_payload = @payload.raw_payload if options.raw? # Write the raw payload STDOUT.write(raw_payload) else # Dump the built payload puts raw_payload.dump end end protected def load_payload! @payload = Payloads::Payload.load_from(options[:file]) end def find_payload!(name=nil) @payload = Payloads::Payload.load_first do |payloads| if name payloads = payloads.named(name) end if options[:describing] payloads = payloads.describing(options[:describing]) end if options[:version] payloads = payloads.revision(options[:version]) end if options[:license] payloads = payloads.licensed_under(options[:license]) end if options[:arch] payloads = payloads.targeting_arch(options[:arch]) end if options[:os] payloads = payloads.targeting_os(options[:os]) end payloads end end end end end end end