From 4af7a19eb0e90217da57ea296666625e2c0761a1 Mon Sep 17 00:00:00 2001 From: erwanlr Date: Sat, 13 Apr 2013 22:25:34 +0200 Subject: [PATCH] Uses terminal-table to display wp_users --- Gemfile | 1 + lib/common/collections/wp_users/output.rb | 35 ++++++++++--------- lib/common/hacks.rb | 41 +++++++++++++++++++++++ lib/environment.rb | 1 + wpscan.rb | 4 ++- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 83de61a9..356d38c1 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem "typhoeus", "=0.6.2" gem "ethon", "=0.5.10" gem "nokogiri" gem "json" +gem "terminal-table" group :development, :test do gem "webmock", ">=1.9.3" diff --git a/lib/common/collections/wp_users/output.rb b/lib/common/collections/wp_users/output.rb index bff7c13e..7144a4dc 100644 --- a/lib/common/collections/wp_users/output.rb +++ b/lib/common/collections/wp_users/output.rb @@ -3,27 +3,26 @@ class WpUsers < WpItems module Output - # TODO : create a generic method to output tabs - def output(left_margin = '') - max_id_length = self.sort { |a, b| a.id.to_s.length <=> b.id.to_s.length }.last.id.to_s.length - max_login_length = self.sort { |a, b| a.login.length <=> b.login.length }.last.login.length - max_display_name_length = self.sort { |a, b| a.display_name.length <=> b.display_name.length }.last.display_name.length + # @param [ Hash ] options + # @option options[ Boolean ] :show_password Output the password column + # + # @return [ void ] + def output(options = {}) - inner_space = 2 - id_length = (max_id_length + inner_space * 2) /2 * 2 - login_length = max_login_length + inner_space * 2 - display_name_length = max_display_name_length + inner_space * 2 + rows = [] + headings = ['Id', 'Name'] + headings << 'Password' if options[:show_password] - puts left_margin + '+' * (id_length + login_length + display_name_length + 4) - puts left_margin + '|' + 'id'.center(id_length) + '|' + 'login'.center(login_length) + '|' + 'display name'.center(display_name_length) + '|' - puts left_margin + '|' + '+' * (id_length + login_length + display_name_length + 2) + '|' - - self.each do |u| - puts left_margin + '|' + u.id.to_s.center(id_length) + '|' + u.login.center(login_length) + '|' + u.display_name.center(display_name_length) + '|' - end - - puts left_margin + '+' * (id_length + login_length + display_name_length + 4) + self.each do |wp_user| + row = [wp_user.id, wp_user.display_name] + row << wp_user.password if options[:show_password] + rows << row end + puts Terminal::Table.new(headings: headings, + rows: rows, + style: { margin_left: options[:margin_left] || '' }) + end + end end diff --git a/lib/common/hacks.rb b/lib/common/hacks.rb index 2f89e844..d374517e 100644 --- a/lib/common/hacks.rb +++ b/lib/common/hacks.rb @@ -79,3 +79,44 @@ class File %x{file -i #{file_path}}[%r{charset=([^\n]+)\n}, 1] end end + +module Terminal + class Table + def render + separator = Separator.new(self) + buffer = [separator] + unless @title.nil? + buffer << Row.new(self, [title_cell_options]) + buffer << separator + end + unless @headings.cells.empty? + buffer << @headings + buffer << separator + end + buffer += @rows + buffer << separator + buffer.map { |r| style.margin_left + r.render }.join("\n") + end + alias :to_s :render + + class Style + @@defaults = { + :border_x => "-", :border_y => "|", :border_i => "+", + :padding_left => 1, :padding_right => 1, + :margin_left => '', + :width => nil, :alignment => nil + } + + attr_accessor :margin_left + attr_accessor :border_x + attr_accessor :border_y + attr_accessor :border_i + + attr_accessor :padding_left + attr_accessor :padding_right + + attr_accessor :width + attr_accessor :alignment + end + end +end diff --git a/lib/environment.rb b/lib/environment.rb index 1ed89e0e..054806f4 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -27,6 +27,7 @@ begin require 'typhoeus' require 'json' require 'nokogiri' + require 'terminal-table' # Custom libs require 'common/browser' require 'common/custom_option_parser' diff --git a/wpscan.rb b/wpscan.rb index 851aaa41..25a45fcd 100755 --- a/wpscan.rb +++ b/wpscan.rb @@ -277,7 +277,7 @@ def main puts puts green('[+]') + " We found the following #{wp_users.size} user/s :" - wp_users.output(' ' * 4) + wp_users.output(margin_left: ' ' * 4) end else @@ -307,6 +307,8 @@ def main wp_users.brute_force(wpscan_options.wordlist, show_progression: true, verbose: wpscan_options.verbose) + puts + wp_users.output(show_password: true, margin_left: ' ' * 2) else puts puts 'Brute forcing aborted'