diff --git a/.gitignore b/.gitignore
index 9932d837..c0cf4aea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,6 @@ doc/
# Old files from v2
cache/
data/
+
+# Profiling reports
+bin/memprof*.report
diff --git a/app/finders/config_backups/known_filenames.rb b/app/finders/config_backups/known_filenames.rb
index deace44f..50b68e20 100644
--- a/app/finders/config_backups/known_filenames.rb
+++ b/app/finders/config_backups/known_filenames.rb
@@ -5,7 +5,7 @@ module WPScan
module ConfigBackups
# Config Backup finder
class KnownFilenames < CMSScanner::Finders::Finder
- include CMSScanner::Finders::Finder::Enumerator
+ include Finders::Finder::Enumerator
# @param [ Hash ] opts
# @option opts [ String ] :list
@@ -16,17 +16,20 @@ module WPScan
found = []
enumerate(potential_urls(opts), opts) do |res|
- # Might need to improve that
- next unless res.body =~ /define/i && res.body !~ /<\s?html/i
-
- found << Model::ConfigBackup.new(res.request.url,
- found_by: DIRECT_ACCESS,
- confidence: 100)
+ found << Model::ConfigBackup.new(res.request.url, found_by: DIRECT_ACCESS, confidence: 100)
end
found
end
+ def valid_response?(res, _exclude_content = nil)
+ return unless res.code == 200
+
+ full_res = Browser.get(res.effective_url)
+
+ full_res.body =~ /define/i && full_res.body !~ /<\s?html/i
+ end
+
# @param [ Hash ] opts
# @option opts [ String ] :list Mandatory
#
diff --git a/app/finders/db_exports/known_locations.rb b/app/finders/db_exports/known_locations.rb
index 6da23395..886cef3d 100644
--- a/app/finders/db_exports/known_locations.rb
+++ b/app/finders/db_exports/known_locations.rb
@@ -6,7 +6,9 @@ module WPScan
# DB Exports finder
# See https://github.com/wpscanteam/wpscan-v3/issues/62
class KnownLocations < CMSScanner::Finders::Finder
- include CMSScanner::Finders::Finder::Enumerator
+ include Finders::Finder::Enumerator
+
+ SQL_PATTERN = /(?:DROP|(?:UN)?LOCK|CREATE) TABLE|INSERT INTO/.freeze
# @param [ Hash ] opts
# @option opts [ String ] :list
@@ -17,16 +19,21 @@ module WPScan
found = []
enumerate(potential_urls(opts), opts) do |res|
- next unless res.code == 200 && res.body =~ /INSERT INTO/
-
- found << Model::DbExport.new(res.request.url,
- found_by: DIRECT_ACCESS,
- confidence: 100)
+ found << Model::DbExport.new(res.request.url, found_by: DIRECT_ACCESS, confidence: 100)
end
found
end
+ def valid_response?(res, _exclude_content = nil)
+ return false unless res.code == 200
+
+ return true if res.effective_url.end_with?('.zip') &&
+ res.headers['Content-Type'] =~ %r{\Aapplication/zip}i
+
+ Browser.get(res.effective_url, headers: { 'Range' => 'bytes=0-3000' }).body =~ SQL_PATTERN ? true : false
+ end
+
# @param [ Hash ] opts
# @option opts [ String ] :list Mandatory
#
diff --git a/app/finders/interesting_findings/tmm_db_migrate.rb b/app/finders/interesting_findings/tmm_db_migrate.rb
index c1008dda..cc309db1 100644
--- a/app/finders/interesting_findings/tmm_db_migrate.rb
+++ b/app/finders/interesting_findings/tmm_db_migrate.rb
@@ -9,7 +9,7 @@ module WPScan
def aggressive(_opts = {})
path = 'wp-content/uploads/tmm_db_migrate/tmm_db_migrate.zip'
url = target.url(path)
- res = Browser.get(url)
+ res = browser.forge_request(url, target.head_or_get_request_params).run
return unless res.code == 200 && res.headers['Content-Type'] =~ %r{\Aapplication/zip}i
diff --git a/app/finders/interesting_findings/upload_sql_dump.rb b/app/finders/interesting_findings/upload_sql_dump.rb
index 94a1d2cd..19185d8a 100644
--- a/app/finders/interesting_findings/upload_sql_dump.rb
+++ b/app/finders/interesting_findings/upload_sql_dump.rb
@@ -5,24 +5,25 @@ module WPScan
module InterestingFindings
# UploadSQLDump finder
class UploadSQLDump < CMSScanner::Finders::Finder
- SQL_PATTERN = /(?:(?:(?:DROP|CREATE) TABLE)|INSERT INTO)/.freeze
+ SQL_PATTERN = /(?:DROP|CREATE|(?:UN)?LOCK) TABLE|INSERT INTO/.freeze
# @return [ InterestingFinding ]
def aggressive(_opts = {})
- url = dump_url
- res = Browser.get(url)
+ head_res = browser.forge_request(dump_url, target.head_or_get_request_params).run
- return unless res.code == 200 && res.body =~ SQL_PATTERN
+ return unless head_res.code == 200
+
+ return unless Browser.get(dump_url, headers: { 'Range' => 'bytes=0-3000' }).body =~ SQL_PATTERN
Model::UploadSQLDump.new(
- url,
+ dump_url,
confidence: 100,
found_by: DIRECT_ACCESS
)
end
def dump_url
- target.url('wp-content/uploads/dump.sql')
+ @dump_url ||= target.url('wp-content/uploads/dump.sql')
end
end
end
diff --git a/app/finders/timthumbs/known_locations.rb b/app/finders/timthumbs/known_locations.rb
index ba995157..1d40075e 100644
--- a/app/finders/timthumbs/known_locations.rb
+++ b/app/finders/timthumbs/known_locations.rb
@@ -24,15 +24,13 @@ module WPScan
end
# @param [ Typhoeus::Response ] res
- # @param [ Regexp,nil ] exclude_content
+ # @param [ Regexp, nil ] exclude_content
#
# @return [ Boolean ]
def valid_response?(res, _exclude_content = nil)
return false unless res.code == 400
- full_res = Browser.get(res.effective_url, cache_ttl: 0)
-
- full_res.body =~ /no image specified/i ? true : false
+ Browser.get(res.effective_url).body =~ /no image specified/i ? true : false
end
# @param [ Hash ] opts
diff --git a/app/finders/users/rss_generator.rb b/app/finders/users/rss_generator.rb
index 1ee05361..062cc432 100644
--- a/app/finders/users/rss_generator.rb
+++ b/app/finders/users/rss_generator.rb
@@ -19,20 +19,20 @@ module WPScan
begin
res.xml.xpath('//item/dc:creator').each do |node|
- potential_username = node.text.to_s
+ username = node.text.to_s
# Ignoring potential username longer than 60 characters and containing accents
# as they are considered invalid. See https://github.com/wpscanteam/wpscan/issues/1215
- next if potential_username.length > 60 || potential_username =~ /[^\x00-\x7F]/
+ next if username.strip.empty? || username.length > 60 || username =~ /[^\x00-\x7F]/
- potential_usernames << potential_username
+ potential_usernames << username
end
rescue Nokogiri::XML::XPath::SyntaxError
next
end
- potential_usernames.uniq.each do |potential_username|
- found << Model::User.new(potential_username, found_by: found_by, confidence: 50)
+ potential_usernames.uniq.each do |username|
+ found << Model::User.new(username, found_by: found_by, confidence: 50)
end
break
diff --git a/app/finders/users/wp_json_api.rb b/app/finders/users/wp_json_api.rb
index 4affa32c..aa6af0b7 100644
--- a/app/finders/users/wp_json_api.rb
+++ b/app/finders/users/wp_json_api.rb
@@ -55,7 +55,15 @@ module WPScan
# @return [ String ] The URL of the API listing the Users
def api_url
- @api_url ||= target.url('wp-json/wp/v2/users/')
+ return @api_url if @api_url
+
+ target.in_scope_urls(target.homepage_res, "//link[@rel='https://api.w.org/']/@href").each do |url, _tag|
+ uri = Addressable::URI.parse(url.strip)
+
+ return @api_url = uri.join('wp/v2/users/').to_s if uri.path.include?('wp-json')
+ end
+
+ @api_url = target.url('wp-json/wp/v2/users/')
end
end
end
diff --git a/app/models/wp_version.rb b/app/models/wp_version.rb
index 3cca1df3..94e12bda 100644
--- a/app/models/wp_version.rb
+++ b/app/models/wp_version.rb
@@ -26,13 +26,12 @@ module WPScan
@all_numbers = []
DB::Fingerprints.wp_fingerprints.each_value do |fp|
- fp.each_value do |versions|
- versions.each do |version|
- @all_numbers << version unless @all_numbers.include?(version)
- end
- end
+ @all_numbers << fp.values
end
+ # @all_numbers.flatten.uniq.sort! {} doesn't produce the same result here.
+ @all_numbers.flatten!
+ @all_numbers.uniq!
@all_numbers.sort! { |a, b| Gem::Version.new(b) <=> Gem::Version.new(a) }
end
diff --git a/bin/wpscan-memprof b/bin/wpscan-memprof
new file mode 100755
index 00000000..2397ce7e
--- /dev/null
+++ b/bin/wpscan-memprof
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+require 'memory_profiler' # https://github.com/SamSaffron/memory_profiler
+require 'wpscan'
+
+report = MemoryProfiler.report(top: 15) do
+ WPScan::Scan.new do |s|
+ s.controllers <<
+ WPScan::Controller::CustomDirectories.new <<
+ WPScan::Controller::InterestingFindings.new <<
+ WPScan::Controller::WpVersion.new <<
+ WPScan::Controller::MainTheme.new <<
+ WPScan::Controller::Enumeration.new <<
+ WPScan::Controller::PasswordAttack.new <<
+ WPScan::Controller::Aliases.new
+
+ s.run
+ end
+end
+
+report.pretty_print(scale_bytes: true, to_file: 'memprof.report')
diff --git a/bin/wpscan-stackprof b/bin/wpscan-stackprof
new file mode 100755
index 00000000..8e25adc6
--- /dev/null
+++ b/bin/wpscan-stackprof
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require 'stackprof' # https://github.com/tmm1/stackprof
+require 'wpscan'
+
+# The object mode produces a segfault currently: https://github.com/jfelchner/ruby-progressbar/issues/153
+# StackProf.run(mode: :object, out: '/tmp/stackprof-object.dump') do
+# StackProf.run(mode: :wall, out: '/tmp/stackprof-wall.dump') do
+StackProf.run(mode: :cpu, out: '/tmp/stackprof-cpu.dump', interval: 500) do
+ # Couldn't we just load the ./wpscan here ?
+ # require_relative 'wpscan' doesn't work
+ WPScan::Scan.new do |s|
+ s.controllers <<
+ WPScan::Controller::CustomDirectories.new <<
+ WPScan::Controller::InterestingFindings.new <<
+ WPScan::Controller::WpVersion.new <<
+ WPScan::Controller::MainTheme.new <<
+ WPScan::Controller::Enumeration.new <<
+ WPScan::Controller::PasswordAttack.new <<
+ WPScan::Controller::Aliases.new
+
+ s.run
+ end
+end
diff --git a/lib/wpscan/db/dynamic_finders/plugin.rb b/lib/wpscan/db/dynamic_finders/plugin.rb
index 9aaf8379..2e5671b2 100644
--- a/lib/wpscan/db/dynamic_finders/plugin.rb
+++ b/lib/wpscan/db/dynamic_finders/plugin.rb
@@ -62,7 +62,7 @@ module WPScan
# @param [ String ] slug
# @return [ Constant ]
- def self.maybe_create_modudle(slug)
+ def self.maybe_create_module(slug)
# What about slugs such as js_composer which will be done as JsComposer, just like js-composer
constant_name = classify_slug(slug)
@@ -75,10 +75,7 @@ module WPScan
def self.create_versions_finders
versions_finders_configs.each do |slug, finders|
- # Kind of an issue here, module is created even if there is no valid classes
- # Could put the #maybe_ directly in the #send() BUT it would be checked everytime,
- # which is kind of a waste
- mod = maybe_create_modudle(slug)
+ mod = maybe_create_module(slug)
finders.each do |finder_class, config|
klass = config['class'] || finder_class
diff --git a/lib/wpscan/finders.rb b/lib/wpscan/finders.rb
index 224920bd..f3a20fb2 100644
--- a/lib/wpscan/finders.rb
+++ b/lib/wpscan/finders.rb
@@ -41,9 +41,6 @@ module WPScan
#
# @yield [ Typhoeus::Response, String ]
def enumerate(urls, opts = {})
- determine_request_params(urls, opts)
- # determine_valid_response_codes(opts)
-
create_progress_bar(opts.merge(total: urls.size))
urls.each do |url, slug|
@@ -61,6 +58,11 @@ module WPScan
hydra.run
end
+ # @return [ Hash ]
+ def request_params
+ @request_params ||= target.head_or_get_request_params.merge(cache_ttl: 0)
+ end
+
# @param [ Typhoeus::Response ] res
# @param [ Regexp,nil ] exclude_content
#
@@ -73,7 +75,9 @@ module WPScan
# Perform a full get to check if homepage or custom 404
if res.code == 200
- full_res = Browser.get(res.effective_url, cache_ttl: 0)
+ # The cache is not disabled to avoid additional request/s when checking
+ # for directory listing
+ full_res = Browser.get(res.effective_url)
return false if target.homepage_or_404?(full_res) ||
exclude_content && full_res.body.match(exclude_content)
@@ -83,23 +87,6 @@ module WPScan
end
# rubocop:enable Metrics/PerceivedComplexity
- # @return [ Hash ]
- def request_params
- @request_params ||= { cache_ttl: 0 }
- end
-
- # @param [ Hash ] urls
- # @param [ Hash ] opts
- def determine_request_params(urls, _opts)
- head_res = Browser.head(urls.first[0], cache_ttl: 0)
-
- @request_params = if head_res.code == 405
- { method: :get, maxfilesize: 1, cache_ttl: 0 }
- else
- { method: :head, cache_ttl: 0 }
- end
- end
-
# @return [ Array