lib/ronin/ui/command_line/commands/payloads.rb in ronin-exploits-0.2.1 vs lib/ronin/ui/command_line/commands/payloads.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,11 +15,10 @@ # 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/ui/command_line/command' require 'ronin/payloads' @@ -30,41 +28,98 @@ module UI module CommandLine module Commands class Payloads < Command - def defaults - @query = {} - end + desc "payloads [options]", "Lists the available Payloads" + method_option :database, :type => :string, :default => Database.config, :aliases => '-D' + method_option :name, :type => :string, :aliases => '-n' + method_option :version, :type => :string, :aliases => '-v' + method_option :describing, :stype => :string, :aliases => '-d' + method_option :license, :type => :string, :aliases => '-l' + method_option :arch, :type => :string, :aliases => '-a' + method_option :os, :type => :string, :aliases => '-o' + method_option :verbose, :type => :boolean, :aliases => '-v' - def define_options(opts) - opts.usage = '[options]' + def default + Database.setup(options[:database]) - opts.options do - opts.on('-D','--database URI','The URI for the database') do |uri| - Database.config = uri.to_s - end + payloads = Ronin::Payloads::Payload.all - opts.on('-n','--name NAME','Search for payloads with the similar NAME') do |name| - @query[:name.like] = name.to_s - end + if options[:name] + payloads = payloads.named(options[:name]) + end - opts.on('-v','--version VERSION','Search for payloads with the similar VERSION') do |version| - @query[:version.like] = version.to_s - end + if options[:version] + payloads = payloads.revision(options[:version]) end - end - def arguments(*args) - Database.setup + if options[:describing] + payloads = payloads.describing(options[:describing]) + end - payloads = Ronin::Payloads::Payload.all(@query) + 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 + if payloads.empty? - fail("could not find similar payloads") + print_error "Could not find similar payloads" + exit -1 end - payloads.each { |payload| puts " #{payload.name}" } + if options.verbose? + payloads.each { |payload| print_payload(payload) } + else + indent do + payloads.each { |payload| puts payload } + end + end + end + + protected + + def print_payload(payload) + attributes = payload.humanize_attributes( + :exclude => [:description] + ) + attributes['Arch'] = payload.arch if payload.arch + attributes['OS'] = payload.os if payload.os + + print_hash(attributes, :title => "Payload: #{payload}") + + indent do + if payload.description + puts "Description:\n\n" + indent do + payload.description.each_line { |line| puts line } + end + puts "\n" + end + + unless payload.authors.empty? + payload.authors.each do |author| + print_hash(author.humanize_attributes, :title => 'Author') + end + end + + unless payload.behaviors.empty? + print_array(payload.behaviors, :title => 'Controls') + end + + attempt { payload.load_original! } + + unless payload.params.empty? + print_array(payload.params.values, :title => 'Parameters') + end + end end end end end