lib/ronin/ui/command_line/commands/exploits.rb in ronin-exploits-0.2.1 vs lib/ronin/ui/command_line/commands/exploits.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/exploits' @@ -30,45 +28,124 @@ module UI module CommandLine module Commands class Exploits < Command - def defaults - @query = {} + desc "exploits [options]", "Lists available exploits" + 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 :status, :type => :string, :aliases => '-s' + method_option :license, :type => :string, :aliases => '-l' + method_option :arch, :type => :string, :aliases => '-a' + method_option :os, :type => :string, :aliases => '-o' + method_option :product, :type => :string, :aliases => '-p' + method_option :verbose, :type => :boolean, :aliases => '-v' + + def default + Database.setup(options[:database]) + + exploits = Ronin::Exploits::Exploit.all + + if options[:name] + exploits = exploits.named(options[:name]) + end + + if options[:version] + exploits = exploits.revision(options[:version]) + end + + if options[:describing] + exploits = exploits.describing(options[:describing]) + end + + if options[:license] + exploits = exploits.licensed_under(options[:license]) + end + + if options[:status] + exploits = exploits.all(:status => options[:status].to_sym) + end + + if options[:arch] + exploits = exploits.targeting_arch(options[:arch]) + end + + if options[:os] + exploits = exploits.targeting_os(options[:os]) + end + + if options[:product] + exploits = exploits.targeting_product(options[:product]) + end + + if exploits.empty? + print_error "Could not find similar exploits" + exit -1 + end + + if options.verbose? + exploits.each { |exploit| print_exploit(exploit) } + else + exploits.each { |exploit| puts " #{exploit}" } + end end - def define_options(opts) - opts.usage = '[options]' + protected - opts.options do - opts.on('-D','--database URI','The URI for the database') do |uri| - Database.config = uri.to_s - end + def print_exploit(exploit) + print_hash( + exploit.humanize_attributes(:exclude => [:description]), + :title => "Exploit: #{exploit}" + ) - opts.on('-n','--name NAME','Search for exploits with the similar NAME') do |name| - @query[:name.like] = name.to_s + indent do + if exploit.description + puts "Description:\n\n" + indent do + exploit.description.each_line { |line| puts line } + end + puts "\n" end - opts.on('-v','--version VERSION','Search for exploits with the similar VERSION') do |version| - @query[:version.like] = version.to_s + unless exploit.authors.empty? + exploit.authors.each do |author| + print_hash(author.humanize_attributes, :title => 'Author') + end end - opts.on('-s','--status STATUS','Search for exploits with the STATUS (potential, proven or weaponized)') do |status| - @query[:status] = status.to_sym + unless exploit.behaviors.empty? + print_array(exploit.behaviors, :title => 'Controls') end - end - end - def arguments(*args) - Database.setup + unless exploit.targets.empty? + exploit.targets.each do |target| + attributes = target.humanize_attributes(:exclude => [:data]) + attributes['Arch'] = target.arch if target.arch + attributes['OS'] = target.os if target.os + attributes['Product'] = target.product if target.product - exploits = Ronin::Exploits::Exploit.all(@query) + print_hash(attributes, :title => 'Target') - if exploits.empty? - fail("could not find similar exploits") - end + unless target.data.empty? + print_title("Target Data") - exploits.each { |exploit| puts " #{exploit}" } + indent do + target.data.each do |name,value| + puts "#{name} [#{value.inspect}]" + end + end + end + end + end + + attempt { exploit.load_original! } + + unless exploit.params.empty? + print_array(exploit.params.values, :title => 'Parameters') + end + end end end end end