From 7a963e346ab66e9fbcbd9f556f0f67394ee5a4ba Mon Sep 17 00:00:00 2001 From: erwanlr Date: Fri, 3 May 2013 17:51:14 +0200 Subject: [PATCH 1/3] Ref #177 Passive detection of specific plugins (Dirty work) --- lib/common/collections/wp_items.rb | 5 ++ lib/common/collections/wp_items/detectable.rb | 16 ++++-- .../collections/wp_plugins/detectable.rb | 57 +++++++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/lib/common/collections/wp_items.rb b/lib/common/collections/wp_items.rb index be09bbf4..dc6c0b82 100755 --- a/lib/common/collections/wp_items.rb +++ b/lib/common/collections/wp_items.rb @@ -6,4 +6,9 @@ require 'common/collections/wp_items/output' class WpItems < Array extend WpItems::Detectable include WpItems::Output + + def +(other) + other.each { |item| self << item } + self + end end diff --git a/lib/common/collections/wp_items/detectable.rb b/lib/common/collections/wp_items/detectable.rb index 348c75b4..cf7fe64e 100755 --- a/lib/common/collections/wp_items/detectable.rb +++ b/lib/common/collections/wp_items/detectable.rb @@ -74,11 +74,7 @@ class WpItems < Array item_class = self.item_class type = self.to_s.gsub(/Wp/, '').downcase response = Browser.get(wp_target.url) - item_options = { - wp_content_dir: wp_target.wp_content_dir, - wp_plugins_dir: wp_target.wp_plugins_dir, - vulns_file: self.vulns_file - } + item_options = self.item_options(wp_target) regex1 = %r{(?:[^=:]+)\s?(?:=|:)\s?(?:"|')[^"']+\\?/} regex2 = %r{\\?/} @@ -96,6 +92,16 @@ class WpItems < Array protected + # @param [ WpTarget ] wp_target + # + # @return [ Hash ] + def item_options(wp_target) + { + wp_content_dir: wp_target.wp_content_dir, + wp_plugins_dir: wp_target.wp_plugins_dir, + vulns_file: self.vulns_file + } + end # The default request parameters # # @return [ Hash ] diff --git a/lib/common/collections/wp_plugins/detectable.rb b/lib/common/collections/wp_plugins/detectable.rb index 0573cea5..5ea4aa6c 100644 --- a/lib/common/collections/wp_plugins/detectable.rb +++ b/lib/common/collections/wp_plugins/detectable.rb @@ -13,5 +13,62 @@ class WpPlugins < WpItems '//plugin' end + # @param [ WpTarget ] wp_target + # @param [ Hash ] options + # + # @return [ WpPlugins ] + def passive_detection(wp_target, options = {}) + detected = super(wp_target, options) + + detected += from_header(wp_target) + detected += from_content(wp_target) + + detected.sort.uniq! + detected + end + + protected + + # X-Powered-By: W3 Total Cache/0.9.2.5 + # @param [ Typhoeus::Response ] response + # + # @return [ WpPlugins ] + def from_header(wp_target) + wp_plugins = WpPlugins.new + response = Browser.get(wp_target.url) + + if response.headers && powered_by = response.headers[:x_powered_by] + if powered_by =~ /W3 Total Cache\/([^0-9.]+)/i + wp_plugins << WpPlugin.new( + wp_target.uri, + self.item_options(wp_target).merge(name: 'w3-total-cache', version: $1) + ) + end + end + wp_plugins + end + + # + # #