language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
Ruby | wpscan/lib/wpscan/db/fingerprints.rb | # frozen_string_literal: true
module WPScan
module DB
# Fingerprints class
class Fingerprints
# @param [ Hash ] data
#
# @return [ Hash ] the unique fingerprints in the data argument given
# Format returned:
# {
# file_path_1: {
# md5_hash_1: version_1,
# md5_hash_2: version_2
# },
# file_path_2: {
# md5_hash_3: version_1,
# md5_hash_4: version_3
# }
# }
def self.unique_fingerprints(data)
unique_fingerprints = {}
data.each do |file_path, fingerprints|
fingerprints.each do |md5sum, versions|
next unless versions.size == 1
unique_fingerprints[file_path] ||= {}
unique_fingerprints[file_path][md5sum] = versions.first
end
end
unique_fingerprints
end
# @return [ String ]
def self.wp_fingerprints_path
@wp_fingerprints_path ||= DB_DIR.join('wp_fingerprints.json').to_s
end
# @return [ Hash ]
def self.wp_fingerprints
@wp_fingerprints ||= read_json_file(wp_fingerprints_path)
end
# @return [ Hash ]
def self.wp_unique_fingerprints
@wp_unique_fingerprints ||= unique_fingerprints(wp_fingerprints)
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/plugin.rb | # frozen_string_literal: true
module WPScan
module DB
# Plugin DB
class Plugin < WpItem
# @return [ Hash ]
def self.metadata
@metadata ||= super['plugins'] || {}
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/plugins.rb | # frozen_string_literal: true
module WPScan
module DB
# WP Plugins
class Plugins < WpItems
# @return [ JSON ]
def self.metadata
Plugin.metadata
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/sponsor.rb | # frozen_string_literal: true
module WPScan
module DB
class Sponsor
# @return [ Hash ]
def self.text
@text ||= file_path.exist? ? File.read(file_path).chomp : ''
end
def self.file_path
@file_path ||= DB_DIR.join('sponsor.txt')
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/theme.rb | # frozen_string_literal: true
module WPScan
module DB
# Theme DB
class Theme < WpItem
# @return [ Hash ]
def self.metadata
@metadata ||= super['themes'] || {}
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/themes.rb | # frozen_string_literal: true
module WPScan
module DB
# WP Themes
class Themes < WpItems
# @return [ JSON ]
def self.metadata
Theme.metadata
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/updater.rb | # frozen_string_literal: true
module WPScan
module DB
# Class used to perform DB updates
# :nocov:
class Updater
# /!\ Might want to also update the Enumeration#cli_options when some filenames are changed here
FILES = %w[
metadata.json wp_fingerprints.json
timthumbs-v3.txt config_backups.txt db_exports.txt
dynamic_finders.yml LICENSE sponsor.txt
].freeze
OLD_FILES = %w[
wordpress.db user-agents.txt dynamic_finders_01.yml
wordpresses.json plugins.json themes.json
].freeze
attr_reader :repo_directory
def initialize(repo_directory)
@repo_directory = Pathname.new(repo_directory).expand_path
FileUtils.mkdir_p(repo_directory.to_s) unless Dir.exist?(repo_directory.to_s)
# When --no-update is passed, return to avoid raising an error if the directory is not writable
# Mainly there for Homebrew: https://github.com/wpscanteam/wpscan/pull/1455
return if ParsedCli.update == false
unless repo_directory.writable?
raise "#{repo_directory} is not writable (uid: #{Process.uid}, gid: #{Process.gid})"
end
delete_old_files
end
# Removes DB files which are no longer used
# this doesn't raise errors if they don't exist
def delete_old_files
OLD_FILES.each do |old_file|
FileUtils.remove_file(local_file_path(old_file), true)
end
end
# @return [ Time, nil ]
def last_update
Time.parse(File.read(last_update_file))
rescue ArgumentError, Errno::ENOENT
nil # returns nil if the file does not exist or contains invalid time data
end
# @return [ String ]
def last_update_file
@last_update_file ||= repo_directory.join('.last_update').to_s
end
# @return [ Boolean ]
def outdated?
date = last_update
date.nil? || date < 5.days.ago
end
# @return [ Boolean ]
def missing_files?
FILES.each do |file|
return true unless File.exist?(repo_directory.join(file))
end
false
end
# @return [ Hash ] The params for Typhoeus::Request
# @note Those params can't be overriden by CLI options
def request_params
@request_params ||= Browser.instance.default_request_params.merge(
timeout: 600,
connecttimeout: 300,
accept_encoding: 'gzip, deflate',
cache_ttl: 0,
headers: { 'User-Agent' => Browser.instance.default_user_agent }
)
end
# @return [ String ] The raw file URL associated with the given filename
def remote_file_url(filename)
"https://data.wpscan.org/#{filename}"
end
# @return [ String ] The checksum of the associated remote filename
def remote_file_checksum(filename)
url = "#{remote_file_url(filename)}.sha512"
res = Typhoeus.get(url, request_params)
raise Error::Download, res if res.timed_out? || res.code != 200
res.body.chomp
end
# @return [ String ]
def local_file_path(filename)
repo_directory.join(filename.to_s).to_s
end
def local_file_checksum(filename)
Digest::SHA512.file(local_file_path(filename)).hexdigest
end
# @return [ String ]
def backup_file_path(filename)
repo_directory.join("#{filename}.back").to_s
end
def create_backup(filename)
return unless File.exist?(local_file_path(filename))
FileUtils.cp(local_file_path(filename), backup_file_path(filename))
end
def restore_backup(filename)
return unless File.exist?(backup_file_path(filename))
FileUtils.cp(backup_file_path(filename), local_file_path(filename))
end
def delete_backup(filename)
FileUtils.rm(backup_file_path(filename))
end
# @return [ String ] The checksum of the downloaded file
def download(filename)
file_path = local_file_path(filename)
file_url = remote_file_url(filename)
res = Typhoeus.get(file_url, request_params)
raise Error::Download, res if res.timed_out? || res.code != 200
File.binwrite(file_path, res.body)
local_file_checksum(filename)
end
# @return [ Array<String> ] The filenames updated
def update
updated = []
FILES.each do |filename|
db_checksum = remote_file_checksum(filename)
# Checking if the file needs to be updated
next if File.exist?(local_file_path(filename)) && db_checksum == local_file_checksum(filename)
create_backup(filename)
dl_checksum = download(filename)
raise Error::ChecksumsMismatch, filename unless dl_checksum == db_checksum
updated << filename
rescue StandardError => e
restore_backup(filename)
raise e
ensure
delete_backup(filename) if File.exist?(backup_file_path(filename))
end
File.write(last_update_file, Time.now)
updated
end
end
end
# :nocov:
end |
Ruby | wpscan/lib/wpscan/db/vuln_api.rb | # frozen_string_literal: true
module WPScan
module DB
# WPVulnDB API
class VulnApi
NON_ERROR_CODES = [200, 403].freeze
class << self
attr_accessor :token
end
# @return [ Addressable::URI ]
def self.uri
@uri ||= Addressable::URI.parse('https://wpscan.com/api/v3/')
end
# @param [ String ] path
# @param [ Hash ] params
#
# @return [ Hash ]
def self.get(path, params = {})
return {} unless token
return {} if path.end_with?('/latest') # Remove this when api/v4 is up
# Typhoeus.get is used rather than Browser.get to avoid merging irrelevant params from the CLI
res = Typhoeus.get(uri.join(path), default_request_params.merge(params))
return {} if res.code == 404 || res.code == 429
return JSON.parse(res.body) if NON_ERROR_CODES.include?(res.code)
raise Error::HTTP, res
rescue Error::HTTP => e
retries ||= 0
if (retries += 1) <= 3
@default_request_params[:headers]['X-Retry'] = retries
sleep(1)
retry
end
{ 'http_error' => e }
end
# @return [ Hash ]
def self.plugin_data(slug)
get("plugins/#{slug}")&.dig(slug) || {}
end
# @return [ Hash ]
def self.theme_data(slug)
get("themes/#{slug}")&.dig(slug) || {}
end
# @return [ Hash ]
def self.wordpress_data(version_number)
get("wordpresses/#{version_number.tr('.', '')}")&.dig(version_number) || {}
end
# @return [ Hash ]
def self.status
json = get('status', params: { version: WPScan::VERSION }, cache_ttl: 0)
json['requests_remaining'] = 'Unlimited' if json['requests_remaining'] == -1
json
end
# @return [ Hash ]
# @note Those params can not be overriden by CLI options
def self.default_request_params
@default_request_params ||= Browser.instance.default_request_params.merge(
headers: {
'User-Agent' => Browser.instance.default_user_agent,
'Authorization' => "Token token=#{token}"
}
)
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/wp_item.rb | # frozen_string_literal: true
module WPScan
module DB
# WpItem - super DB class for Plugin, Theme and Version
class WpItem
# @param [ String ] identifier The plugin/theme slug or version number
#
# @return [ Hash ] The JSON data from the metadata associated to the identifier
def self.metadata_at(identifier)
metadata[identifier] || {}
end
# @return [ JSON ]
def self.metadata
@metadata ||= read_json_file(metadata_file)
end
# @return [ String ]
def self.metadata_file
@metadata_file ||= DB_DIR.join('metadata.json').to_s
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/wp_items.rb | # frozen_string_literal: true
module WPScan
module DB
# WP Items
class WpItems
# @return [ Array<String> ] The slug of all items
def self.all_slugs
metadata.keys
end
# @return [ Array<String> ] The slug of all popular items
def self.popular_slugs
metadata.select { |_key, item| item['popular'] == true }.keys
end
# @return [ Array<String> ] The slug of all vulnerable items
def self.vulnerable_slugs
metadata.select { |_key, item| item['vulnerabilities'] == true }.keys
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/wp_version.rb | # frozen_string_literal: true
module WPScan
module DB
# WP Version
class Version < WpItem
# @return [ Hash ]
def self.metadata
@metadata ||= super['wordpress'] || {}
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/dynamic_finders/base.rb | # frozen_string_literal: true
module WPScan
module DB
module DynamicFinders
class Base
# @return [ String ]
def self.df_file
@df_file ||= DB_DIR.join('dynamic_finders.yml').to_s
end
# @return [ Hash ]
def self.all_df_data
@all_df_data ||= if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('4.0.0')
YAML.safe_load(File.read(df_file), permitted_classes: [Regexp])
else
YAML.safe_load(File.read(df_file), [Regexp])
end
end
# @return [ Array<Symbol> ]
def self.allowed_classes
# The Readme is not put in there as it's not a Real DF, but rather using the DF system
# to get the list of potential filenames for a given slug
@allowed_classes ||= %i[Comment Xpath HeaderPattern BodyPattern JavascriptVar QueryParameter ConfigParser]
end
# @param [ Symbol ] sym
def self.method_missing(sym)
super unless sym =~ /\A(passive|aggressive)_(.*)_finder_configs\z/i
finder_class = Regexp.last_match[2].camelize.to_sym
raise "#{finder_class} is not allowed as a Dynamic Finder" unless allowed_classes.include?(finder_class)
finder_configs(
finder_class,
aggressive: Regexp.last_match[1] == 'aggressive'
)
end
def self.respond_to_missing?(sym, *_args)
sym =~ /\A(passive|aggressive)_(.*)_finder_configs\z/i
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/dynamic_finders/plugin.rb | # frozen_string_literal: true
module WPScan
module DB
module DynamicFinders
class Plugin < Base
# @return [ Hash ]
def self.df_data
@df_data ||= all_df_data['plugins'] || {}
end
def self.version_finder_module
Finders::PluginVersion
end
# @param [ Symbol ] finder_class
# @param [ Boolean ] aggressive
# @return [ Hash ]
def self.finder_configs(finder_class, aggressive: false)
configs = {}
return configs unless allowed_classes.include?(finder_class)
df_data.each do |slug, finders|
# Quite sure better can be done with some kind of logic statement in the select
fs = if aggressive
finders.reject { |_f, c| c['path'].nil? }
else
finders.select { |_f, c| c['path'].nil? }
end
fs.each do |finder_name, config|
klass = config['class'] || finder_name
next unless klass.to_sym == finder_class
configs[slug] ||= {}
configs[slug][finder_name] = config
end
end
configs
end
# @return [ Hash ]
def self.versions_finders_configs
return @versions_finders_configs if @versions_finders_configs
@versions_finders_configs = {}
df_data.each do |slug, finders|
finders.each do |finder_name, config|
next unless config.key?('version')
@versions_finders_configs[slug] ||= {}
@versions_finders_configs[slug][finder_name] = config
end
end
@versions_finders_configs
end
# @param [ String ] slug
# @return [ Constant ]
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)
unless version_finder_module.constants.include?(constant_name)
version_finder_module.const_set(constant_name, Module.new)
end
version_finder_module.const_get(constant_name)
end
# Create the dynamic finders related to the given slug, and return the created classes
#
# @param [ String ] slug
#
# @return [ Array<Class> ] The created classes
def self.create_versions_finders(slug)
created = []
mod = maybe_create_module(slug)
versions_finders_configs[slug]&.each do |finder_class, config|
klass = config['class'] || finder_class
# Instead of raising exceptions, skip unallowed/already defined finders
# So that, when new DF configs are put in the .yml
# users with old version of WPScan will still be able to scan blogs
# when updating the DB but not the tool
next unless allowed_classes.include?(klass.to_sym)
created << if mod.constants.include?(finder_class.to_sym)
mod.const_get(finder_class.to_sym)
else
version_finder_super_class(klass).create_child_class(mod, finder_class.to_sym, config)
end
end
created
end
# The idea here would be to check if the class exist in
# the Finders::DynamicFinders::Plugins/Themes::klass or WpItemVersion::klass
# and return the related constant when one has been found.
#
# So far, the Finders::DynamicFinders::WPItemVersion is enought
# as nothing else is used
#
# @param [ String, Symbol ] klass
# @return [ Constant ]
def self.version_finder_super_class(klass)
"WPScan::Finders::DynamicFinder::WpItemVersion::#{klass}".constantize
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/dynamic_finders/theme.rb | # frozen_string_literal: true
module WPScan
module DB
module DynamicFinders
class Theme < Plugin
# @return [ Hash ]
def self.df_data
@df_data ||= all_df_data['themes'] || {}
end
def self.version_finder_module
Finders::ThemeVersion
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/db/dynamic_finders/wordpress.rb | # frozen_string_literal: true
module WPScan
module DB
module DynamicFinders
class Wordpress < Base
# @return [ Hash ]
def self.df_data
@df_data ||= all_df_data['wordpress'] || {}
end
# @return [ Constant ]
def self.version_finder_module
Finders::WpVersion
end
# @return [ Array<Symbol> ]
def self.allowed_classes
@allowed_classes ||= %i[
Comment Xpath HeaderPattern BodyPattern JavascriptVar QueryParameter WpItemQueryParameter
]
end
# @param [ Symbol ] finder_class
# @param [ Boolean ] aggressive
# @return [ Hash ]
def self.finder_configs(finder_class, aggressive: false)
configs = {}
return configs unless allowed_classes.include?(finder_class)
finders = if aggressive
df_data.reject { |_f, c| c['path'].nil? }
else
df_data.select { |_f, c| c['path'].nil? }
end
finders.each do |finder_name, config|
klass = config['class'] || finder_name
next unless klass.to_sym == finder_class
configs[finder_name] = config
end
configs
end
# @return [ Hash ]
def self.versions_finders_configs
@versions_finders_configs ||= df_data.select { |_finder_name, config| config.key?('version') }
end
def self.create_versions_finders
versions_finders_configs.each do |finder_class, config|
klass = config['class'] || finder_class
# Instead of raising exceptions, skip unallowed/already defined finders
# So that, when new DF configs are put in the .yml
# users with old version of WPScan will still be able to scan blogs
# when updating the DB but not the tool
next if version_finder_module.constants.include?(finder_class.to_sym) ||
!allowed_classes.include?(klass.to_sym)
version_finder_super_class(klass).create_child_class(version_finder_module, finder_class.to_sym, config)
end
end
# @param [ String, Symbol ] klass
# @return [ Constant ]
def self.version_finder_super_class(klass)
"WPScan::Finders::DynamicFinder::WpVersion::#{klass}".constantize
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/errors/enumeration.rb | # frozen_string_literal: true
module WPScan
module Error
class PluginsThresholdReached < Standard
def to_s
"The number of plugins detected reached the threshold of #{ParsedCli.plugins_threshold} " \
'which might indicate False Positive. It would be recommended to use the --exclude-content-based ' \
'option to ignore the bad responses.'
end
end
class ThemesThresholdReached < Standard
def to_s
"The number of themes detected reached the threshold of #{ParsedCli.themes_threshold} " \
'which might indicate False Positive. It would be recommended to use the --exclude-content-based ' \
'option to ignore the bad responses.'
end
end
end
end |
Ruby | wpscan/lib/wpscan/errors/http.rb | # frozen_string_literal: true
module WPScan
module Error
# HTTP Error
class HTTP < Standard
attr_reader :response
# @param [ Typhoeus::Response ] res
def initialize(response)
@response = response
end
def failure_details
msg = response.effective_url
msg += if response.code.zero? || response.timed_out?
" (#{response.return_message})"
else
" (status: #{response.code})"
end
msg
end
def to_s
"HTTP Error: #{failure_details}"
end
end
# Used in the Updater
class Download < HTTP
def to_s
"Unable to get #{failure_details}"
end
end
end
end |
Ruby | wpscan/lib/wpscan/errors/update.rb | # frozen_string_literal: true
module WPScan
module Error
# Error raised when there is a missing DB file and --no-update supplied
class MissingDatabaseFile < Standard
def to_s
'Update required, you can not run a scan if a database file is missing.'
end
end
class ChecksumsMismatch < Standard
attr_reader :db_file
def initialize(db_file)
@db_file = db_file
end
def to_s
"#{db_file}: checksums do not match. Please try again in a few minutes."
end
end
end
end |
Ruby | wpscan/lib/wpscan/errors/vuln_api.rb | # frozen_string_literal: true
module WPScan
module Error
# Error raised when the token given via --api-token is invalid
class InvalidApiToken < Standard
def to_s
'The API token provided is invalid'
end
end
# Error raised when the number of API requests has been reached
# currently not implemented on the API side
class ApiLimitReached < Standard
def to_s
'Your API limit has been reached'
end
end
end
end |
Ruby | wpscan/lib/wpscan/errors/wordpress.rb | # frozen_string_literal: true
module WPScan
module Error
# WordPress hosted (*.wordpress.com)
class WordPressHosted < Standard
def to_s
'The target appears to be hosted on WordPress.com. Scanning such site is not supported.'
end
end
# Not WordPress Error
class NotWordPress < Standard
def to_s
'The remote website is up, but does not seem to be running WordPress.'
end
end
# Invalid Wp Version (used in the WpVersion#new)
class InvalidWordPressVersion < Standard
def to_s
'The WordPress version is invalid'
end
end
class WpContentDirNotDetected < Standard
def to_s
'Unable to identify the wp-content dir, please supply it with --wp-content-dir,' \
' use the --scope option or make sure the --url value given is the correct one'
end
end
class NoLoginInterfaceDetected < Standard
def to_s
'Could not find a login interface to perform the password attack against'
end
end
end
end |
Ruby | wpscan/lib/wpscan/errors/xmlrpc.rb | # frozen_string_literal: true
module WPScan
module Error
# XML-RPC Not Detected
class XMLRPCNotDetected < Standard
def to_s
'The XML-RPC Interface was not detected.'
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/finder.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
# To be used as a base when creating a dynamic finder
class Finder < CMSScanner::Finders::Finder
# @param [ Array ] args
def self.child_class_constant(*args)
args.each do |arg|
if arg.is_a?(Hash)
child_class_constants.merge!(arg)
else
child_class_constants[arg] = nil
end
end
end
# Needed to have inheritance of the @child_class_constants
# If inheritance is not needed, then the #child_class_constant can be used in the class definition, ie
# child_class_constant :FILES, PATTERN: /aaa/i
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= { PATH: nil }
end
# @param [ Constant ] mod
# @param [ Constant ] klass
# @param [ Hash ] config
def self.create_child_class(mod, klass, config)
# Can't use the #child_class_constants directly in the Class.new(self) do; end below
class_constants = child_class_constants
mod.const_set(
klass, Class.new(self) do
class_constants.each do |key, value|
const_set(key, config[key.downcase.to_s] || value)
end
end
)
end
# This method has to be overriden in child classes
#
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Mixed: nil, Object, Array ]
def find(_response, _opts = {})
raise NoMethodError
end
# @param [ Hash ] opts
# @return [ Mixed ] See #find
def passive(opts = {})
return if self.class::PATH
homepage_result = find(target.homepage_res, opts)
unless homepage_result.nil? || (homepage_result.is_a?(Array) && homepage_result&.empty?)
return homepage_result
end
find(target.error_404_res, opts)
end
# @param [ Hash ] opts
# @return [ Mixed ] See #find
def aggressive(opts = {})
return unless self.class::PATH
find(Browser.get(target.url(self.class::PATH)), opts)
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/wp_item_version.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module WpItemVersion
class BodyPattern < Finders::DynamicFinder::Version::BodyPattern
end
class Comment < Finders::DynamicFinder::Version::Comment
end
class ConfigParser < Finders::DynamicFinder::Version::ConfigParser
end
class HeaderPattern < Finders::DynamicFinder::Version::HeaderPattern
end
class JavascriptVar < Finders::DynamicFinder::Version::JavascriptVar
end
class QueryParameter < Finders::DynamicFinder::Version::QueryParameter
# @return [ Regexp ]
def path_pattern
# TODO: consider the target.blog.themes_dir if the target is a Theme (maybe implement a WpItem#item_dir ?)
@path_pattern ||= %r{
#{Regexp.escape(target.blog.plugins_dir)}/
#{Regexp.escape(target.slug)}/
(?:#{self.class::FILES.join('|')})\z
}ix
end
def xpath
@xpath ||= self.class::XPATH ||
"//link[contains(@href,'#{target.slug}')]/@href" \
"|//script[contains(@src,'#{target.slug}')]/@src"
end
end
class Xpath < Finders::DynamicFinder::Version::Xpath
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/wp_version.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module WpVersion
module Finder
def create_version(number, finding_opts)
return unless Model::WpVersion.valid?(number)
Model::WpVersion.new(number, version_finding_opts(finding_opts))
end
end
class BodyPattern < Finders::DynamicFinder::Version::BodyPattern
include Finder
end
class Comment < Finders::DynamicFinder::Version::Comment
include Finder
end
class HeaderPattern < Finders::DynamicFinder::Version::HeaderPattern
include Finder
end
class JavascriptVar < Finders::DynamicFinder::Version::JavascriptVar
include Finder
end
class QueryParameter < Finders::DynamicFinder::Version::QueryParameter
include Finder
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(PATTERN: /ver=(?<v>\d+\.[.\d]+)/i)
end
end
# This one has been disabled from the DF.yml as it was causing FPs when a plugin had numerous
# files matching a known WP version.
class WpItemQueryParameter < QueryParameter
def xpath
@xpath ||=
self.class::XPATH ||
"//link[contains(@href,'#{target.plugins_dir}') or contains(@href,'#{target.themes_dir}')]/@href" \
"|//script[contains(@src,'#{target.plugins_dir}') or contains(@src,'#{target.themes_dir}')]/@src"
end
def path_pattern
@path_pattern ||= %r{
(?:#{Regexp.escape(target.plugins_dir)}|#{Regexp.escape(target.themes_dir)})/
[^/]+/
.*\.(?:css|js)\z
}ix
end
end
class Xpath < WPScan::Finders::DynamicFinder::Version::Xpath
include Finder
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/body_pattern.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder using Body Pattern method. Typically used when the response is not
# an HTML doc and Xpath can't be used
class BodyPattern < Finders::DynamicFinder::Version::Finder
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(PATTERN: nil, CONFIDENCE: 60)
end
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Version ]
def find(response, _opts = {})
return unless response.code != 404 && response.body =~ self.class::PATTERN
create_version(
Regexp.last_match[:v],
interesting_entries: ["#{response.effective_url}, Match: '#{Regexp.last_match}'"]
)
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/comment.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder in Comment, which is basically an Xpath one with a default
# Xpath of //comment()
class Comment < Finders::DynamicFinder::Version::Xpath
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(PATTERN: nil, XPATH: '//comment()')
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/config_parser.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder using by parsing config files, such as composer.json
# and so on
class ConfigParser < Finders::DynamicFinder::Version::Finder
ALLOWED_PARSERS = [JSON, YAML].freeze
def self.child_class_constants
@child_class_constants ||= super.merge(
PARSER: nil, KEY: nil, PATTERN: /(?<v>\d+\.[.\d]+)/, CONFIDENCE: 70
)
end
# @param [ String ] body
# @return [ Hash, nil ] The parsed body, with an available parser, if possible
def parse(body)
parsers = ALLOWED_PARSERS.include?(self.class::PARSER) ? [self.class::PARSER] : ALLOWED_PARSERS
parsers.each do |parser|
parsed = parser.respond_to?(:safe_load) ? parser.safe_load(body) : parser.load(body)
return parsed if parsed.is_a?(Hash) || parsed.is_a?(Array)
rescue StandardError
next
end
nil # Make sure nil is returned in case none of the parsers managed to parse the body correctly
end
# No Passive way
def passive(opts = {}); end
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Version ]
def find(response, _opts = {})
parsed_body = parse(response.body)
# Create indexes for the #dig, digits are converted to integers
indexes = self.class::KEY.split(':').map { |e| e == e.to_i.to_s ? e.to_i : e }
return unless (data = parsed_body&.dig(*indexes)) && data =~ self.class::PATTERN
create_version(
Regexp.last_match[:v],
interesting_entries: ["#{response.effective_url}, Match: '#{Regexp.last_match}'"]
)
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/finder.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# To be used as a base when creating
# a dynamic finder to find the version of a WP Item (such as theme/plugin)
class Finder < Finders::DynamicFinder::Finder
protected
# @param [ String ] number
# @param [ Hash ] finding_opts
# @return [ Model::Version ]
def create_version(number, finding_opts)
Model::Version.new(number, version_finding_opts(finding_opts))
end
# @param [ Hash ] opts
# @retutn [ Hash ]
def version_finding_opts(opts)
opts[:found_by] ||= found_by
opts[:confidence] ||= self.class::CONFIDENCE
opts
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/header_pattern.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder using Header Pattern method
class HeaderPattern < Finders::DynamicFinder::Version::Finder
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(HEADER: nil, PATTERN: nil, CONFIDENCE: 60)
end
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Version ]
def find(response, _opts = {})
return unless response.headers && response.headers[self.class::HEADER]
return unless response.headers[self.class::HEADER].to_s =~ self.class::PATTERN
create_version(
Regexp.last_match[:v],
interesting_entries: ["#{response.effective_url}, Match: '#{Regexp.last_match}'"]
)
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/javascript_var.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder using JavaScript Variable method
class JavascriptVar < Finders::DynamicFinder::Version::Finder
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(
XPATH: '//script[not(@src)]', VERSION_KEY: nil,
PATTERN: nil, CONFIDENCE: 60
)
end
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Version ]
def find(response, _opts = {})
target.xpath_pattern_from_page(
self.class::XPATH, self.class::PATTERN, response
) do |match_data, _node|
next unless (version_number = version_number_from_match_data(match_data))
# If the text to be output in the interesting_entries is > 50 chars,
# get 20 chars before and after (when possible) the detected version instead
match = match_data.to_s
match = match[/.*?(.{,20}#{Regexp.escape(version_number)}.{,20}).*/, 1] if match.size > 50
return create_version(
version_number,
interesting_entries: ["#{response.effective_url}, Match: '#{match.strip}'"]
)
end
nil
end
# @param [ MatchData ] match_data
# @return [ String ]
def version_number_from_match_data(match_data)
if self.class::VERSION_KEY
begin
json = JSON.parse("{#{match_data[:json].strip.chomp(',').tr("'", '"')}}")
rescue JSON::ParserError
return
end
json.dig(*self.class::VERSION_KEY.split(':'))
else
match_data[:v]
end
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/query_parameter.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder using QueryParameter method
class QueryParameter < Finders::DynamicFinder::Version::Finder
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(
XPATH: nil, FILES: nil, PATTERN: /(?:v|ver|version)=(?<v>\d+\.[.\d]+)/i, CONFIDENCE_PER_OCCURENCE: 10
)
end
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Array<Version>, nil ]
def find(response, _opts = {})
found = []
scan_response(response).each do |version_number, occurences|
found << create_version(
version_number,
confidence: self.class::CONFIDENCE_PER_OCCURENCE * occurences.size,
interesting_entries: occurences
)
end
found.compact
end
# @param [ Typhoeus::Response ] response
# @return [ Hash ]
def scan_response(response)
found = {}
target.in_scope_uris(response, xpath) do |uri|
next unless uri.path =~ path_pattern && uri.query&.match(self.class::PATTERN)
version = Regexp.last_match[:v].to_s
found[version] ||= []
found[version] << uri.to_s
end
found
end
# @return [ String ]
def xpath
@xpath ||= self.class::XPATH || '//link[@href]/@href|//script[@src]/@src'
end
# @return [ Regexp ]
def path_pattern
@path_pattern ||= %r{/(?:#{self.class::FILES.join('|')})\z}i
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/version/xpath.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module Version
# Version finder using Xpath method
class Xpath < Finders::DynamicFinder::Version::Finder
# @return [ Hash ]
def self.child_class_constants
@child_class_constants ||= super().merge(
XPATH: nil, PATTERN: /\A(?<v>\d+\.[.\d]+)/, CONFIDENCE: 60
)
end
# @param [ Typhoeus::Response ] response
# @param [ Hash ] opts
# @return [ Version ]
def find(response, _opts = {})
target.xpath_pattern_from_page(
self.class::XPATH, self.class::PATTERN, response
) do |match_data, _node|
next unless match_data[:v]
return create_version(
match_data[:v],
interesting_entries: ["#{response.effective_url}, Match: '#{match_data}'"]
)
end
nil
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/dynamic_finder/wp_items/finder.rb | # frozen_string_literal: true
module WPScan
module Finders
module DynamicFinder
module WpItems
# Not really a dynamic finder in itself (hence not a child class of DynamicFinder::Finder)
# but will use the dynamic finder DB configs to find collections of
# WpItems (such as Plugins and Themes)
#
# Also used to factorise some code used between such finders.
# The #process_response should be implemented in each child class, or the
# #passive and #aggressive overriden
class Finder < CMSScanner::Finders::Finder
# @return [ Hash ] The related dynamic finder passive configurations
# for the current class (all its usefullness comes from child classes)
def passive_configs
# So far only the Plugins have dynamic finders so using DB:: DynamicFinders::Plugin
# is ok. However, when Themes have some, will need to create other child classes for them
method = "passive_#{self.class.to_s.demodulize.underscore}_finder_configs".to_sym
DB::DynamicFinders::Plugin.public_send(method)
end
# @param [ Hash ] opts
#
# @return [ Array<Plugin>, Array<Theme> ]
def passive(opts = {})
found = []
passive_configs.each do |slug, configs|
configs.each do |klass, config|
[target.homepage_res, target.error_404_res].each do |page_res|
item = process_response(opts, page_res, slug, klass, config)
if item.is_a?(Model::WpItem)
found << item
break # No need to check the other page if detected in the current
end
end
end
end
found
end
# @return [ Hash ] The related dynamic finder passive configurations
# for the current class (all its usefullness comes from child classes)
def aggressive_configs
# So far only the Plugins have dynamic finders so using DB:: DynamicFinders::Plugin
# is ok. However, when Themes have some, will need to create other child classes for them
method = "aggressive_#{self.class.to_s.demodulize.underscore}_finder_configs".to_sym
DB::DynamicFinders::Plugin.public_send(method)
end
# @param [ Hash ] opts
#
# @return [ Array<Plugin>, Array<Theme> ]
def aggressive(_opts = {})
# Disable this as it would make quite a lot of extra requests just to find plugins/themes
# Kept the original method below for future implementation
end
# @param [ Hash ] opts
#
# @return [ Array<Plugin>, Array<Theme> ]
def aggressive_(opts = {})
found = []
aggressive_configs.each do |slug, configs|
configs.each do |klass, config|
path = aggressive_path(slug, config)
response = Browser.get(target.url(path))
item = process_response(opts, response, slug, klass, config)
found << item if item.is_a?(Model::WpItem)
end
end
found
end
# @param [ String ] slug
# @param [ Hash ] config from the YAML file with he 'path' key
#
# @return [ String ] The path related to the aggresive configuration
# ie config['path'] if it's an absolute path (like /file.txt)
# or the path from inside the related plugin directory
def aggressive_path(slug, config)
return config['path'] if config['path'][0] == '/'
# No need to set the correct plugins dir, it will be handled by target.url()
"wp-content/plugins/#{slug}/#{config['path']}"
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/finders/finder/wp_version/smart_url_checker.rb | # frozen_string_literal: true
module WPScan
module Finders
class Finder
module WpVersion
# SmartURLChecker specific for the WP Version
module SmartURLChecker
include CMSScanner::Finders::Finder::SmartURLChecker
def create_version(number, opts = {})
Model::WpVersion.new(
number,
found_by: opts[:found_by] || found_by,
confidence: opts[:confidence] || 80,
interesting_entries: opts[:entries]
)
rescue WPScan::Error::InvalidWordPressVersion
nil # Invalid Version returned as nil and will be ignored by Finders
end
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/target/platform/wordpress.rb | # frozen_string_literal: true
%w[custom_directories].each do |required|
require "wpscan/target/platform/wordpress/#{required}"
end
module WPScan
class Target < CMSScanner::Target
module Platform
# Some WordPress specific implementation
module WordPress
include CMSScanner::Target::Platform::PHP
WORDPRESS_PATTERN = %r{/(?:(?:wp-content/(?:themes|(?:mu-)?plugins|uploads))|wp-includes)/}i.freeze
WORDPRESS_HOSTED_PATTERN = %r{https?://s\d\.wp\.com#{WORDPRESS_PATTERN}}i.freeze
WP_JSON_OEMBED_PATTERN = %r{/wp-json/oembed/}i.freeze
WP_ADMIN_AJAX_PATTERN = %r{\\?/wp-admin\\?/admin-ajax\.php}i.freeze
# These methods are used in the associated interesting_findings finders
# to keep the boolean state of the finding rather than re-check the whole thing again
attr_accessor :multisite, :registration_enabled, :mu_plugins
alias multisite? multisite
alias registration_enabled? registration_enabled
alias mu_plugins? mu_plugins
# @param [ Symbol ] detection_mode
#
# @return [ Boolean ] Whether or not the target is running WordPress
def wordpress?(detection_mode)
[homepage_res, error_404_res].each do |page_res|
return true if wordpress_from_meta_comments_or_scripts?(page_res)
end
if %i[mixed aggressive].include?(detection_mode)
%w[wp-admin/install.php wp-login.php].each do |path|
res = Browser.get_and_follow_location(url(path))
next unless res.code == 200
in_scope_uris(res, '//link/@href|//script/@src') do |uri|
return true if WORDPRESS_PATTERN.match?(uri.path)
end
end
end
false
end
# @param [ Typhoeus::Response ] response
# @return [ Boolean ]
def wordpress_from_meta_comments_or_scripts?(response)
in_scope_uris(response, '//link/@href|//script/@src') do |uri|
return true if WORDPRESS_PATTERN.match?(uri.path) || WP_JSON_OEMBED_PATTERN.match?(uri.path)
end
return true if response.html.css('meta[name="generator"]').any? do |node|
/wordpress/i.match?(node['content'])
end
return true unless comments_from_page(/wordpress/i, response).empty?
return true if response.html.xpath('//script[not(@src)]').any? do |node|
WP_ADMIN_AJAX_PATTERN.match?(node.text)
end
false
end
COOKIE_PATTERNS = {
'vjs' => /createCookie\('vjs','(?<c_value>\d+)',\d+\);/i
}.freeze
# Sometimes there is a mechanism in place on the blog, which requires a specific
# cookie and value to be added to requests. Lets try to detect and add them
def maybe_add_cookies
COOKIE_PATTERNS.each do |cookie_key, pattern|
next unless homepage_res.body =~ pattern
browser = Browser.instance
cookie_string = "#{cookie_key}=#{Regexp.last_match[:c_value]}"
cookie_string += "; #{browser.cookie_string}" if browser.cookie_string
browser.cookie_string = cookie_string
# Force recheck of the homepage when retying wordpress?
# No need to clear the cache, as the request (which will contain the cookies)
# will be different
@homepage_res = nil
@homepage_url = nil
break
end
end
# @return [ String ]
def registration_url
multisite? ? url('wp-signup.php') : url('wp-login.php?action=register')
end
# @return [ Boolean ] Whether or not the target is hosted on wordpress.com
def wordpress_hosted?
return true if /\.wordpress\.com$/i.match?(uri.host)
unless content_dir
uris_from_page(homepage_res, '(//@href|//@src)[contains(., "wp.com")]') do |uri|
return true if uri.to_s.match?(WORDPRESS_HOSTED_PATTERN)
end
end
false
end
# @param [ String ] username
# @param [ String ] password
#
# @return [ Typhoeus::Response ]
def do_login(username, password)
login_request(username, password).run
end
# @param [ String ] username
# @param [ String ] password
#
# @return [ Typhoeus::Request ]
def login_request(username, password)
Browser.instance.forge_request(
login_url,
method: :post,
cache_ttl: 0,
body: { log: username, pwd: password }
)
end
# The login page is checked for a potential redirection (from http to https)
# the first time the method is called, and the effective_url is then used
# if suitable, otherwise the default wp-login will be.
#
# If the login_uri CLI option has been provided, it will be returne w/o redirection check.
#
# @return [ String, false ] The URL to the login page or false if not detected
def login_url
return @login_url unless @login_url.nil?
return @login_url = url(ParsedCli.login_uri) if ParsedCli.login_uri
@login_url = url('wp-login.php')
res = Browser.get_and_follow_location(@login_url)
@login_url = res.effective_url if res.effective_url =~ /wp-login\.php\z/i && in_scope?(res.effective_url)
@login_url = false if res.code == 404
@login_url
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/target/platform/wordpress/custom_directories.rb | # frozen_string_literal: true
module WPScan
class Target < CMSScanner::Target
module Platform
# wp-content & plugins directory implementation
module WordPress
def content_dir=(dir)
@content_dir = dir.chomp('/')
end
def plugins_dir=(dir)
@plugins_dir = dir.chomp('/')
end
# @return [ String ] The wp-content directory
def content_dir
unless @content_dir
# scope_url_pattern is from CMSScanner::Target
pattern = %r{#{scope_url_pattern}([\w\s\-/]+?)\\?/(?:themes|plugins|uploads|cache)\\?/}i
[homepage_res, error_404_res].each do |page_res|
in_scope_uris(page_res, '//link/@href|//script/@src|//img/@src') do |uri|
return @content_dir = Regexp.last_match[1] if uri.to_s.match(pattern)
end
# Checks for the pattern in raw JS code, as well as @content attributes of meta tags
xpath_pattern_from_page('//script[not(@src)]|//meta/@content', pattern, page_res) do |match|
return @content_dir = match[1]
end
end
return @content_dir = 'wp-content' if default_content_dir_exists?
end
@content_dir
end
def default_content_dir_exists?
# url('wp-content') can't be used here as the folder has not yet been identified
# and the method would try to replace it by nil which would raise an error
[200, 401, 403].include?(Browser.forge_request(uri.join('wp-content/').to_s, head_or_get_params).run.code)
end
# @return [ Addressable::URI ]
def content_uri
uri.join("#{content_dir}/")
end
# @return [ String ]
def content_url
content_uri.to_s
end
# @return [ String ]
def plugins_dir
@plugins_dir ||= "#{content_dir}/plugins"
end
# @return [ Addressable::URI ]
def plugins_uri
uri.join("#{plugins_dir}/")
end
# @return [ String ]
def plugins_url
plugins_uri.to_s
end
# @param [ String ] slug
#
# @return [ String ]
def plugin_url(slug)
plugins_uri.join("#{Addressable::URI.encode(slug)}/").to_s
end
# @return [ String ]
def themes_dir
@themes_dir ||= "#{content_dir}/themes"
end
# @return [ Addressable::URI ]
def themes_uri
uri.join("#{themes_dir}/")
end
# @return [ String ]
def themes_url
themes_uri.to_s
end
# @param [ String ] slug
#
# @return [ String ]
def theme_url(slug)
themes_uri.join("#{Addressable::URI.encode(slug)}/").to_s
end
# @return [ String, False ] String of the sub_dir found, false otherwise
# @note: nil can not be returned here, otherwise if there is no sub_dir
# the check would be done each time, which would make enumeration of
# long list of items very slow to generate
def sub_dir
return @sub_dir unless @sub_dir.nil?
# url_pattern is from CMSScanner::Target
pattern = %r{#{url_pattern}(.+?)/(?:xmlrpc\.php|wp-includes/)}i
xpath = '(//@src|//@href|//@data-src)[contains(., "xmlrpc.php") or contains(., "wp-includes/")]'
[homepage_res, error_404_res].each do |page_res|
in_scope_uris(page_res, xpath) do |uri|
return @sub_dir = Regexp.last_match[1] if uri.to_s.match(pattern)
end
end
@sub_dir = false
end
# Override of the WebSite#url to consider the custom WP directories
#
# @param [ String ] path Optional path to merge with the uri
#
# @return [ String ]
def url(path = nil)
return @uri.to_s unless path
if %r{wp-content/plugins}i.match?(path)
new_path = path.gsub('wp-content/plugins', plugins_dir)
elsif /wp-content/i.match?(path)
new_path = path.gsub('wp-content', content_dir)
elsif path[0] != '/' && sub_dir
new_path = "#{sub_dir}/#{path}"
end
super(new_path || path)
end
end
end
end
end |
Ruby | wpscan/lib/wpscan/typhoeus/response.rb | # frozen_string_literal: true
module Typhoeus
# Custom Response class
class Response
# @note: Ignores requests done to the /status endpoint of the API
#
# @return [ Boolean ]
def from_vuln_api?
effective_url.start_with?(WPScan::DB::VulnApi.uri.to_s) &&
!effective_url.start_with?(WPScan::DB::VulnApi.uri.join('status').to_s)
end
end
end |
Ruby | wpscan/spec/shared_examples.rb | # frozen_string_literal: true
require 'shared_examples/views/vuln_api'
require 'shared_examples/views/wp_version'
require 'shared_examples/views/main_theme'
require 'shared_examples/views/enumeration'
require 'shared_examples/target/platform/wordpress'
require 'shared_examples/finders/wp_items/urls_in_page'
require 'shared_examples/references'
require 'shared_examples/dynamic_finders/wp_items' |
Ruby | wpscan/spec/spec_helper.rb | # frozen_string_literal: true
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'simplecov' # More config is defined in ./.simplecov
require 'rspec/its'
require 'webmock/rspec'
# See http://betterspecs.org/
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
# For --only-failures / --next-failure
config.example_status_persistence_file_path = '/tmp/rspec_examples.txt'
end
def redefine_constant(constant, value)
WPScan.send(:remove_const, constant)
WPScan.const_set(constant, value)
end
# Dynamic Finders Helpers
def df_expected_all
YAML.safe_load(File.read(DYNAMIC_FINDERS_FIXTURES.join('expected.yml')))
end
def df_tested_class_constant(type, finder_class, slug = nil)
if slug
"WPScan::Finders::#{type}::#{classify_slug(slug)}::#{classify_slug(finder_class)}".constantize
else
"WPScan::Finders::#{type}::#{classify_slug(finder_class)}".constantize
end
end
def df_stubbed_response(fixture, finder_super_class)
if finder_super_class == 'HeaderPattern'
{ headers: JSON.parse(File.read(fixture)) }
else
{ body: File.read(fixture, mode: 'rb') }
end
end
def vuln_api_data_for(path)
JSON.parse(File.read(FIXTURES.join('db', 'vuln_api', "#{path}.json")))
end
require 'wpscan'
require 'shared_examples'
def rspec_parsed_options(args)
controllers = WPScan::Controller.constants.reject { |c| c == :Base }.reduce(WPScan::Controllers.new) do |a, sym|
a << WPScan::Controller.const_get(sym).new
end
controllers.option_parser.results(args.split)
end
# TODO: remove when https://github.com/bblimke/webmock/issues/552 fixed
# Also remove from CMSScanner
# rubocop:disable all
module WebMock
module HttpLibAdapters
class TyphoeusAdapter < HttpLibAdapter
def self.effective_url(effective_uri)
effective_uri.port = nil if effective_uri.scheme == 'http' && effective_uri.port == 80
effective_uri.port = nil if effective_uri.scheme == 'https' && effective_uri.port == 443
effective_uri.to_s
end
def self.generate_typhoeus_response(request_signature, webmock_response)
response = if webmock_response.should_timeout
::Typhoeus::Response.new(
code: 0,
status_message: '',
body: '',
headers: {},
return_code: :operation_timedout
)
else
::Typhoeus::Response.new(
code: webmock_response.status[0],
status_message: webmock_response.status[1],
body: webmock_response.body,
headers: webmock_response.headers,
effective_url: effective_url(request_signature.uri)
)
end
response.mock = :webmock
response
end
end
end
end
# rubocop:enable all
SPECS = Pathname.new(__FILE__).dirname
FIXTURES = SPECS.join('fixtures')
FINDERS_FIXTURES = FIXTURES.join('finders')
DYNAMIC_FINDERS_FIXTURES = FIXTURES.join('dynamic_finders')
ERROR_404_URL_PATTERN = %r{/[a-z\d]{7}\.html$}.freeze
redefine_constant(:DB_DIR, FIXTURES.join('db')) |
Ruby | wpscan/spec/app/views_spec.rb | # frozen_string_literal: true
describe 'App::Views' do
let(:target_url) { 'http://ex.lo/' }
let(:target) { WPScan::Target.new(target_url) }
let(:fixtures) { SPECS.join('output') }
# CliNoColour is used to test the CLI output to avoid the painful colours
# in the expected output.
%i[JSON CliNoColour].each do |formatter|
context "when #{formatter}" do
it_behaves_like 'App::Views::VulnApi'
it_behaves_like 'App::Views::WpVersion'
it_behaves_like 'App::Views::MainTheme'
it_behaves_like 'App::Views::Enumeration'
let(:parsed_options) { { url: target_url, format: formatter.to_s.underscore.dasherize } }
before do
WPScan::ParsedCli.options = parsed_options
# Resets the formatter to ensure the correct one is loaded
controller.class.class_variable_set(:@@formatter, nil)
end
after do
view_filename = defined?(expected_view) ? expected_view : view
view_filename = "#{view_filename}.#{formatter.to_s.underscore.downcase}"
controller_dir = controller.class.to_s.demodulize.underscore.downcase
expected_output = File.read(fixtures.join(controller_dir, view_filename))
expect($stdout).to receive(:puts).with(expected_output)
controller.output(view, @tpl_vars)
controller.formatter.beautify # Mandatory to be able to test formatter such as JSON
end
end
end
end |
Ruby | wpscan/spec/app/controllers/aliases_spec.rb | # frozen_string_literal: true
describe WPScan::Controller::Aliases do
subject(:controller) { described_class.new }
let(:target_url) { 'http://ex.lo/' }
let(:cli_args) { "--url #{target_url}" }
before do
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
end
describe '#cli_options' do
its(:cli_options) { should_not be_empty }
its(:cli_options) { should be_a Array }
it 'contains to correct options' do
expect(controller.cli_options.map(&:to_sym)).to eq %i[stealthy]
end
end
describe 'parsed_options' do
context 'when no --stealthy supplied' do
it 'contains the correct options' do
expect(WPScan::ParsedCli.options).to include(
detection_mode: :mixed, plugins_version_detection: :mixed
)
end
end
context 'when --stealthy supplied' do
let(:cli_args) { "#{super()} --stealthy" }
it 'contains the correct options' do
expect(WPScan::ParsedCli.options).to include(
random_user_agent: true, detection_mode: :passive, plugins_version_detection: :passive
)
end
end
end
end |
Ruby | wpscan/spec/app/controllers/core_spec.rb | # frozen_string_literal: true
describe WPScan::Controller::Core do
subject(:core) { described_class.new }
let(:target_url) { 'http://ex.lo/' }
let(:cli_args) { "--url #{target_url}" }
before do
described_class.reset
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
end
describe '#cli_options' do
its(:cli_options) { should_not be_empty }
its(:cli_options) { should be_a Array }
it 'contains to correct options' do
cli_options = core.cli_options
expect(cli_options.map(&:to_sym)).to include(:url, :server, :force, :update)
# Ensures the :url is the first one and is correctly setup
expect(cli_options.first.to_sym).to eql :url
expect(cli_options.first.required_unless).to match_array %i[update help hh version]
end
end
describe '#load_server_module' do
after do
expect(core.target).to receive(:server).and_return(@stubbed_server)
expect(core.load_server_module).to eql @expected
[core.target, WPScan::Model::WpItem.new(target_url, core.target)].each do |instance|
expect(instance).to respond_to(:directory_listing?)
expect(instance).to respond_to(:directory_listing_entries)
# The below doesn't work, the module would have to be removed from the class
# TODO: find a way to test this
# expect(instance.server).to eql @expected if instance.is_a? WPScan::Model::WpItem
end
end
context 'when no --server supplied' do
%i[Apache IIS Nginx].each do |server|
it "loads the #{server} module and returns :#{server}" do
@stubbed_server = server
@expected = server
end
end
end
context 'when --server' do
%i[apache iis nginx].each do |server|
context "when #{server}" do
let(:cli_args) { "#{super()} --server #{server}" }
let(:servers) { [:Apache, nil, :IIS, :Nginx] }
it "loads the #{server.capitalize} module and returns :#{server}" do
@stubbed_server = servers.sample
@expected = server == :iis ? :IIS : server.to_s.camelize.to_sym
end
end
end
end
end
describe '#update_db_required?' do
context 'when missing files' do
before { expect(core.local_db).to receive(:missing_files?).ordered.and_return(true) }
context 'when --no-update' do
let(:cli_args) { "#{super()} --no-update" }
it 'raises an error' do
expect { core.update_db_required? }.to raise_error(WPScan::Error::MissingDatabaseFile)
end
end
context 'otherwise' do
its(:update_db_required?) { should eql true }
end
end
context 'when not missing files' do
before { expect(core.local_db).to receive(:missing_files?).ordered.and_return(false) }
context 'when --update' do
let(:cli_args) { "#{super()} --update" }
its(:update_db_required?) { should eql true }
end
context 'when --no-update' do
let(:cli_args) { "#{super()} --no-update" }
its(:update_db_required?) { should eql false }
end
context 'when user_interation (i.e cli output)' do
let(:cli_args) { "#{super()} --format cli" }
context 'when the db is up-to-date' do
before { expect(core.local_db).to receive(:outdated?).and_return(false) }
its(:update_db_required?) { should eql false }
end
context 'when the db is outdated' do
before do
expect(core.local_db).to receive(:outdated?).ordered.and_return(true)
expect(core.formatter).to receive(:output).with('@notice', hash_including(:msg), 'core').ordered
expect($stdout).to receive(:write).ordered # for the print()
end
context 'when a positive answer' do
before { expect(Readline).to receive(:readline).and_return('Yes').ordered }
its(:update_db_required?) { should eql true }
end
context 'when a negative answer' do
before { expect(Readline).to receive(:readline).and_return('no').ordered }
its(:update_db_required?) { should eql false }
end
end
end
context 'when no user_interation' do
let(:cli_args) { "#{super()} --format json" }
its(:update_db_required?) { should eql false }
end
end
end
describe '#before_scan' do
before do
stub_request(:get, target_url)
expect(core.formatter).to receive(:output).with('banner', hash_including(verbose: nil), 'core')
expect(core).to receive(:update_db_required?).and_return(false) unless WPScan::ParsedCli.update
end
context 'when --update' do
before do
expect(core.formatter).to receive(:output)
.with('db_update_started', hash_including(verbose: nil), 'core').ordered
expect_any_instance_of(WPScan::DB::Updater).to receive(:update)
expect(core.formatter).to receive(:output)
.with('db_update_finished', hash_including(verbose: nil), 'core').ordered
end
context 'when the --url is not supplied' do
let(:cli_args) { '--update' }
it 'calls the formatter when started and finished to update the db and exit' do
expect { core.before_scan }.to raise_error(SystemExit)
end
end
context 'when --url is supplied' do
let(:cli_args) { "#{super()} --update" }
before do
expect(core).to receive(:load_server_module)
expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true)
expect(core.target).to receive(:wordpress_hosted?).and_return(false)
end
it 'calls the formatter when started and finished to update the db' do
expect { core.before_scan }.to_not raise_error
end
end
end
context 'when hosted on wordpress.com' do
let(:target_url) { 'http://ex.wordpress.com' }
before { expect(core).to receive(:load_server_module) }
it 'raises an error' do
expect { core.before_scan }.to raise_error(WPScan::Error::WordPressHosted)
end
end
context 'when not hosted on wordpress.com' do
before { allow(core.target).to receive(:wordpress_hosted?).and_return(false) }
context 'when a redirect occurs' do
before do
stub_request(:any, target_url)
expect(core.target).to receive(:homepage_res)
.at_least(1)
.and_return(Typhoeus::Response.new(effective_url: redirection, body: ''))
end
context 'to the wp-admin/install.php' do
let(:redirection) { "#{target_url}wp-admin/install.php" }
it 'calls the formatter with the correct parameters and exit' do
expect(core.formatter).to receive(:output)
.with('not_fully_configured', hash_including(url: redirection), 'core').ordered
# TODO: Would be cool to be able to test the exit code
expect { core.before_scan }.to raise_error(SystemExit)
end
end
context 'to something else' do
let(:redirection) { 'http://g.com/' }
it 'raises an error' do
expect { core.before_scan }.to raise_error(CMSScanner::Error::HTTPRedirect)
end
end
context 'to another path with the wp-admin/install.php in the query' do
let(:redirection) { "#{target_url}index.php?a=/wp-admin/install.php" }
context 'when wordpress' do
it 'does not raise an error' do
expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true)
expect { core.before_scan }.to_not raise_error
end
end
context 'when not wordpress' do
it 'raises an error' do
expect(core.target).to receive(:wordpress?).twice.with(:mixed).and_return(false)
expect { core.before_scan }.to raise_error(WPScan::Error::NotWordPress)
end
end
end
end
context 'when wordpress' do
before do
expect(core).to receive(:load_server_module)
expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true)
end
it 'does not raise any error' do
expect { core.before_scan }.to_not raise_error
end
end
context 'when not wordpress' do
before do
expect(core).to receive(:load_server_module)
end
context 'when no --force' do
before { expect(core.target).to receive(:maybe_add_cookies) }
context 'when no cookies added or still not wordpress after being added' do
it 'raises an error' do
expect(core.target).to receive(:wordpress?).twice.with(:mixed).and_return(false)
expect { core.before_scan }.to raise_error(WPScan::Error::NotWordPress)
end
end
context 'when the added cookies solved it' do
it 'does not raise an error' do
expect(core.target).to receive(:wordpress?).with(:mixed).and_return(false).ordered
expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true).ordered
expect { core.before_scan }.to_not raise_error
end
end
end
context 'when --force' do
let(:cli_args) { "#{super()} --force" }
it 'does not raise any error' do
expect(core.target).to receive(:wordpress?).with(:mixed).and_return(false)
expect { core.before_scan }.to_not raise_error
end
end
end
end
end
end |
Ruby | wpscan/spec/app/controllers/custom_directories_spec.rb | # frozen_string_literal: true
describe WPScan::Controller::CustomDirectories do
subject(:controller) { described_class.new }
let(:target_url) { 'http://ex.lo/' }
let(:cli_args) { "--url #{target_url}" }
before do
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
end
describe '#cli_options' do
its(:cli_options) { should_not be_empty }
its(:cli_options) { should be_a Array }
it 'contains to correct options' do
expect(controller.cli_options.map(&:to_sym)).to eq %i[wp_content_dir wp_plugins_dir]
end
end
describe '#before_scan' do
context 'when the content_dir is not found and not supplied' do
before { expect(controller.target).to receive(:content_dir).and_return(nil) }
it 'raises an exception' do
expect { controller.before_scan }.to raise_error(WPScan::Error::WpContentDirNotDetected)
end
end
context 'when content_dir found/supplied' do
let(:cli_args) { "#{super()} --wp-content-dir wp-content" }
it 'does not raise any error' do
expect { controller.before_scan }.to_not raise_error
expect(controller.target.content_dir).to eq WPScan::ParsedCli.wp_content_dir
end
end
end
end |
Ruby | wpscan/spec/app/controllers/enumeration_spec.rb | # frozen_string_literal: true
describe WPScan::Controller::Enumeration do
subject(:controller) { described_class.new }
let(:target_url) { 'http://wp.lab/' }
let(:cli_args) { "--url #{target_url}" }
before do
## For the --passwords options
allow_any_instance_of(OptParseValidator::OptPath).to receive(:check_file)
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
end
describe '#enum_message' do
after { expect(controller.enum_message(type, detection_mode)).to eql @expected }
context 'when type argument is incorrect' do
let(:type) { 'spec' }
let(:detection_mode) { :mixed }
it 'returns nil' do
@expected = nil
end
end
%w[plugins themes].each do |t|
context "type = #{t}" do
let(:type) { t }
let(:detection_mode) { :mixed }
context 'when vulnerable' do
let(:cli_args) { "#{super()} -e v#{type[0]}" }
it 'returns the expected string' do
@expected = "Enumerating Vulnerable #{type.capitalize} (via Passive and Aggressive Methods)"
end
end
context 'when all' do
let(:cli_args) { "#{super()} -e a#{type[0]}" }
let(:detection_mode) { :passive }
it 'returns the expected string' do
@expected = "Enumerating All #{type.capitalize} (via Passive Methods)"
end
end
context 'when most popular' do
let(:cli_args) { "#{super()} -e #{type[0]}" }
let(:detection_mode) { :aggressive }
it 'returns the expected string' do
@expected = "Enumerating Most Popular #{type.capitalize} (via Aggressive Methods)"
end
end
end
end
end
describe '#default_opts' do
context 'when no --enumerate' do
it 'contains the correct version_detection' do
expect(controller.default_opts('plugins')[:version_detection]).to include(mode: :mixed)
end
end
end
describe '#cli_options' do
it 'contains the correct options' do
expect(controller.cli_options.map(&:to_sym)).to eql(
%i[enumerate exclude_content_based
plugins_list plugins_detection plugins_version_all plugins_version_detection plugins_threshold
themes_list themes_detection themes_version_all themes_version_detection themes_threshold
timthumbs_list timthumbs_detection
config_backups_list config_backups_detection
db_exports_list db_exports_detection
medias_detection
users_list users_detection exclude_usernames]
)
end
end
describe '#enum_users' do
before { expect(controller.formatter).to receive(:output).twice }
after { controller.enum_users }
context 'when --enumerate has been supplied' do
let(:cli_args) { "#{super()} -e u1-10" }
it 'calls the target.users with the correct range' do
expect(controller.target).to receive(:users).with(hash_including(range: (1..10)))
end
end
context 'when --passwords supplied but no --username or --usernames' do
let(:cli_args) { "#{super()} --passwords some-file.txt" }
it 'calls the target.users with the default range' do
expect(controller.target).to receive(:users).with(hash_including(range: (1..10)))
end
end
end
describe '#run' do
context 'when no :enumerate' do
before do
expect(controller).to receive(:enum_plugins)
expect(controller).to receive(:enum_config_backups)
expect(WPScan::ParsedCli.plugins_detection).to eql :passive
end
it 'calls enum_plugins and enum_config_backups' do
controller.run
end
context 'when --passwords supplied but no --username or --usernames' do
let(:cli_args) { "#{super()} --passwords some-file.txt" }
it 'calls the enum_users' do
expect(controller).to receive(:enum_users)
controller.run
end
end
end
context 'when :enumerate' do
after { controller.run }
context 'when no option supplied' do
let(:cli_args) { "#{super()} -e" }
it 'calls the correct enum methods' do
%i[plugins themes timthumbs config_backups db_exports users medias].each do |option|
expect(controller).to receive("enum_#{option}".to_sym)
end
end
end
%i[p ap vp].each do |option|
context "when #{option}" do
let(:cli_args) { "#{super()} -e #{option}" }
it 'calls the #enum_plugins' do
expect(controller).to receive(:enum_plugins)
end
end
end
%i[t at vt].each do |option|
context option.to_s do
let(:cli_args) { "#{super()} -e #{option}" }
it 'calls the #enum_themes' do
expect(controller).to receive(:enum_themes)
end
end
end
{ timthumbs: 'tt', config_backups: 'cb', db_exports: 'dbe', medias: 'm', users: 'u' }.each do |option, shortname|
context "when #{option}" do
let(:cli_args) { "#{super()} -e #{shortname}" }
it "calls the ##{option}" do
expect(controller).to receive("enum_#{option}".to_sym)
end
end
end
end
end
end |
Ruby | wpscan/spec/app/controllers/password_attack_spec.rb | # frozen_string_literal: true
XMLRPC_FAILED_BODY = '
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>405</int></value>
</member>
<member>
<name>faultString</name>
<value><string>%s</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>'
describe WPScan::Controller::PasswordAttack do
subject(:controller) { described_class.new }
let(:target_url) { 'http://ex.lo/' }
let(:cli_args) { "--url #{target_url}" }
before do
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
end
describe '#cli_options' do
its(:cli_options) { should_not be_empty }
its(:cli_options) { should be_a Array }
it 'contains to correct options' do
expect(controller.cli_options.map(&:to_sym))
.to eq(%i[passwords usernames multicall_max_passwords password_attack login_uri])
end
end
describe '#users' do
context 'when no --usernames' do
it 'calls target.users' do
expect(controller.target).to receive(:users)
controller.users
end
end
context 'when --usernames' do
let(:cli_args) { "#{super()} --usernames admin,editor" }
it 'returns an array with the users' do
expected = %w[admin editor].reduce([]) do |a, e|
a << WPScan::Model::User.new(e)
end
expect(controller.users).to eql expected
end
end
end
describe '#run' do
context 'when no --passwords is supplied' do
it 'does not run the attacker' do
expect(controller.run).to eql nil
end
end
end
describe '#xmlrpc_get_users_blogs_enabled?' do
before { expect(controller.target).to receive(:xmlrpc).and_return(xmlrpc) }
context 'when xmlrpc not found' do
let(:xmlrpc) { nil }
its(:xmlrpc_get_users_blogs_enabled?) { should be false }
end
context 'when xmlrpc not enabled' do
let(:xmlrpc) { WPScan::Model::XMLRPC.new("#{target_url}xmlrpc.php") }
it 'returns false' do
expect(xmlrpc).to receive(:enabled?).and_return(false)
expect(controller.xmlrpc_get_users_blogs_enabled?).to be false
end
end
context 'when xmlrpc enabled' do
let(:xmlrpc) { WPScan::Model::XMLRPC.new("#{target_url}xmlrpc.php") }
before { expect(xmlrpc).to receive(:enabled?).and_return(true) }
context 'when wp.getUsersBlogs methods not listed' do
it 'returns false' do
expect(xmlrpc).to receive(:available_methods).and_return(%w[m1 m2])
expect(controller.xmlrpc_get_users_blogs_enabled?).to be false
end
end
context 'when wp.getUsersBlogs method listed' do
before do
expect(xmlrpc).to receive(:available_methods).and_return(%w[wp.getUsersBlogs m2])
stub_request(:post, xmlrpc.url).to_return(body: body)
end
context 'when wp.getUsersBlogs method disabled' do
context 'when blog is in EN' do
let(:body) { format(XMLRPC_FAILED_BODY, 'XML-RPC services are disabled on this site.') }
it 'returns false' do
expect(controller.xmlrpc_get_users_blogs_enabled?).to be false
end
end
context 'when blog is in FR' do
let(:body) { format(XMLRPC_FAILED_BODY, 'Les services XML-RPC sont désactivés sur ce site.') }
it 'returns false' do
expect(controller.xmlrpc_get_users_blogs_enabled?).to be false
end
end
end
context 'when wp.getUsersBlogs method enabled' do
let(:body) { 'Incorrect username or password.' }
it 'returns true' do
expect(controller.xmlrpc_get_users_blogs_enabled?).to be true
end
end
end
end
end
describe '#attacker' do
before do
allow(controller.target).to receive(:sub_dir)
controller.target.instance_variable_set(:@login_url, nil)
end
context 'when --password-attack provided' do
let(:cli_args) { "#{super()} --password-attack #{attack}" }
context 'when wp-login' do
before { stub_request(:get, controller.target.url('wp-login.php')).to_return(status: status) }
let(:attack) { 'wp-login' }
context 'when available' do
let(:status) { 200 }
it 'returns the correct object' do
expect(controller.attacker).to be_a WPScan::Finders::Passwords::WpLogin
expect(controller.attacker.target).to be_a WPScan::Target
end
end
context 'when not available (404)' do
let(:status) { 404 }
it 'raises an error' do
expect { controller.attacker }.to raise_error(WPScan::Error::NoLoginInterfaceDetected)
end
end
end
context 'when xmlrpc' do
context 'when xmlrpc not detected on target' do
before do
expect(controller.target).to receive(:xmlrpc).and_return(nil)
end
context 'when single xmlrpc' do
let(:attack) { 'xmlrpc' }
it 'raises an error' do
expect { controller.attacker }.to raise_error(WPScan::Error::XMLRPCNotDetected)
end
end
context 'when xmlrpc-multicall' do
let(:attack) { 'xmlrpc-multicall' }
it 'raises an error' do
expect { controller.attacker }.to raise_error(WPScan::Error::XMLRPCNotDetected)
end
end
end
context 'when xmlrpc detected on target' do
before do
expect(controller.target)
.to receive(:xmlrpc)
.and_return(WPScan::Model::XMLRPC.new("#{target_url}xmlrpc.php"))
end
context 'when single xmlrpc' do
let(:attack) { 'xmlrpc' }
it 'returns the correct object' do
expect(controller.attacker).to be_a WPScan::Finders::Passwords::XMLRPC
expect(controller.attacker.target).to be_a WPScan::Model::XMLRPC
end
end
context 'when xmlrpc-multicall' do
let(:attack) { 'xmlrpc-multicall' }
it 'returns the correct object' do
expect(controller.attacker).to be_a WPScan::Finders::Passwords::XMLRPCMulticall
expect(controller.attacker.target).to be_a WPScan::Model::XMLRPC
end
end
end
end
end
context 'when automatic detection' do
context 'when xmlrpc_get_users_blogs_enabled? is false' do
before do
expect(controller).to receive(:xmlrpc_get_users_blogs_enabled?).and_return(false)
stub_request(:get, controller.target.url('wp-login.php')).to_return(status: status)
end
context 'when wp-login available' do
let(:status) { 200 }
it 'returns the WpLogin' do
expect(controller.attacker).to be_a WPScan::Finders::Passwords::WpLogin
expect(controller.attacker.target).to be_a WPScan::Target
end
end
context 'when wp-login.php not available' do
let(:status) { 404 }
it 'raises an error' do
expect { controller.attacker }.to raise_error(WPScan::Error::NoLoginInterfaceDetected)
end
end
end
context 'when xmlrpc_get_users_blogs_enabled? is true' do
before do
expect(controller).to receive(:xmlrpc_get_users_blogs_enabled?).and_return(true)
expect(controller.target)
.to receive(:xmlrpc).and_return(WPScan::Model::XMLRPC.new("#{target_url}xmlrpc.php"))
end
context 'when WP version not found' do
it 'returns the XMLRPC' do
expect(controller.target).to receive(:wp_version).and_return(false)
expect(controller.attacker).to be_a WPScan::Finders::Passwords::XMLRPC
expect(controller.attacker.target).to be_a WPScan::Model::XMLRPC
end
end
context 'when WP version found' do
before { expect(controller.target).to receive(:wp_version).and_return(wp_version) }
context 'when WP < 4.4' do
let(:wp_version) { WPScan::Model::WpVersion.new('3.8.1') }
it 'returns the XMLRPCMulticall' do
expect(controller.attacker).to be_a WPScan::Finders::Passwords::XMLRPCMulticall
expect(controller.attacker.target).to be_a WPScan::Model::XMLRPC
end
end
context 'when WP >= 4.4' do
let(:wp_version) { WPScan::Model::WpVersion.new('4.4') }
it 'returns the XMLRPC' do
expect(controller.attacker).to be_a WPScan::Finders::Passwords::XMLRPC
expect(controller.attacker.target).to be_a WPScan::Model::XMLRPC
end
end
end
end
end
end
end |
Ruby | wpscan/spec/app/controllers/vuln_api_spec.rb | # frozen_string_literal: true
describe WPScan::Controller::VulnApi do
subject(:controller) { described_class.new }
let(:target_url) { 'http://ex.lo/' }
let(:cli_args) { "--url #{target_url}" }
before do
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
WPScan::DB::VulnApi.instance_variable_set(:@default_request_params, nil)
end
describe '#cli_options' do
its(:cli_options) { should_not be_empty }
its(:cli_options) { should be_a Array }
it 'contains to correct options' do
expect(controller.cli_options.map(&:to_sym)).to eq %i[api_token]
end
end
describe '#before_scan' do
context 'when no --api-token provided' do
its(:before_scan) { should be nil }
end
context 'when --api-token given' do
let(:cli_args) { "#{super()} --api-token token" }
context 'when the token is invalid' do
before { expect(WPScan::DB::VulnApi).to receive(:status).and_return('status' => 'forbidden') }
it 'raise an InvalidApiToken error' do
expect { controller.before_scan }.to raise_error(WPScan::Error::InvalidApiToken)
end
end
context 'when the token is valid' do
context 'when the limit has been reached' do
before do
expect(WPScan::DB::VulnApi)
.to receive(:status)
.and_return('success' => true, 'plan' => 'free', 'requests_remaining' => 0)
end
it 'raises an ApiLimitReached error' do
expect { controller.before_scan }.to raise_error(WPScan::Error::ApiLimitReached)
end
end
context 'when a HTTP error, like a timeout' do
before do
expect(WPScan::DB::VulnApi)
.to receive(:status)
.and_return(
'http_error' => WPScan::Error::HTTP.new(
Typhoeus::Response.new(effective_url: 'mock-url', return_code: 28)
)
)
end
it 'raises an HTTP error' do
expect { controller.before_scan }
.to raise_error(WPScan::Error::HTTP, 'HTTP Error: mock-url (Timeout was reached)')
end
end
context 'when the token is valid and no HTTP error' do
before do
expect(WPScan::DB::VulnApi)
.to receive(:status)
.and_return('success' => true, 'plan' => 'free', 'requests_remaining' => requests)
end
context 'when limited requests' do
let(:requests) { 100 }
it 'sets the token and does not raise an error' do
expect { controller.before_scan }.to_not raise_error
expect(WPScan::DB::VulnApi.token).to eql 'token'
end
context 'when unlimited requests' do
let(:requests) { 'Unlimited' }
it 'sets the token and does not raise an error' do
expect { controller.before_scan }.to_not raise_error
expect(WPScan::DB::VulnApi.token).to eql 'token'
end
end
end
end
end
end
context 'when token in ENV' do
before do
ENV[described_class::ENV_KEY] = 'token-from-env'
expect(WPScan::DB::VulnApi)
.to receive(:status)
.and_return('success' => true, 'plan' => 'free', 'requests_remaining' => 'Unlimited')
end
it 'sets the token and does not raise an error' do
expect { controller.before_scan }.to_not raise_error
expect(WPScan::DB::VulnApi.token).to eql 'token-from-env'
end
end
end
end |
Ruby | wpscan/spec/app/controllers/wp_version_spec.rb | # frozen_string_literal: true
def it_calls_the_formatter_with_the_correct_parameter(version)
it 'calls the formatter with the correct parameter' do
expect(controller.formatter).to receive(:output)
.with('version', hash_including(version: version), 'wp_version')
end
end
describe WPScan::Finders::WpVersionFinders do
subject(:finders) { described_class.new }
describe 'filter_findings' do
context 'when super returns false (nothing found)' do
before do
expect_any_instance_of(WPScan::Finders::UniqueFinders).to receive(:filter_findings).and_return(false)
end
its(:filter_findings) { should be false }
end
end
end
describe WPScan::Controller::WpVersion do
subject(:controller) { described_class.new }
let(:target_url) { 'http://ex.lo/' }
let(:cli_args) { "--url #{target_url}" }
before do
WPScan::ParsedCli.options = rspec_parsed_options(cli_args)
end
describe '#cli_options' do
its(:cli_options) { should_not be_empty }
its(:cli_options) { should be_a Array }
it 'contains to correct options' do
expect(controller.cli_options.map(&:to_sym)).to eq %i[wp_version_all wp_version_detection]
end
end
describe '#run' do
before do
expect(controller.target).to receive(:wp_version)
.with(
hash_including(
mode: WPScan::ParsedCli.wp_version_detection || WPScan::ParsedCli.detection_mode,
confidence_threshold: WPScan::ParsedCli.wp_version_all ? 0 : 100
)
).and_return(stubbed)
end
after { controller.run }
%i[mixed passive aggressive].each do |mode|
context "when --detection-mode #{mode}" do
let(:cli_args) { "#{super()} --detection-mode #{mode}" }
[WPScan::Model::WpVersion.new('4.0')].each do |version|
context "when version = #{version}" do
let(:stubbed) { version }
it_calls_the_formatter_with_the_correct_parameter(version)
end
end
end
end
context 'when --wp-version-all supplied' do
let(:cli_args) { "#{super()} --wp-version-all" }
let(:stubbed) { WPScan::Model::WpVersion.new('3.9.1') }
it_calls_the_formatter_with_the_correct_parameter(WPScan::Model::WpVersion.new('3.9.1'))
end
context 'when --wp-version-detection mode supplied' do
let(:cli_args) { "#{super()} --detection-mode mixed --wp-version-detection passive" }
let(:stubbed) { WPScan::Model::WpVersion.new('4.4') }
it_calls_the_formatter_with_the_correct_parameter(WPScan::Model::WpVersion.new('4.4'))
end
end
end |
Ruby | wpscan/spec/app/finders/config_backups_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::ConfigBackups::Base do
subject(:config_backups) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(config_backups.finders.map { |f| f.class.to_s.demodulize }).to eq %w[KnownFilenames]
end
end
end |
Ruby | wpscan/spec/app/finders/db_exports_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::DbExports::Base do
subject(:db_exports) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(db_exports.finders.map { |f| f.class.to_s.demodulize }).to eq %w[KnownLocations]
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::Base do
subject(:files) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
let(:expected) do
%w[
Readme DebugLog FullPathDisclosure
Multisite MuPlugins Registration UploadDirectoryListing TmmDbMigrate
UploadSQLDump PHPDisabled
]
end
it 'contains the expected finders' do
expect(files.finders.map { |f| f.class.to_s.demodulize }).to include(*expected)
end
end
end |
Ruby | wpscan/spec/app/finders/main_theme_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::MainTheme::Base do
subject(:main_theme) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(main_theme.finders.map { |f| f.class.to_s.demodulize })
.to eq %w[CssStyleInHomepage CssStyleIn404Page WooFrameworkMetaGenerator UrlsInHomepage UrlsIn404Page]
end
end
end |
Ruby | wpscan/spec/app/finders/medias_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Medias::Base do
subject(:media) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(media.finders.map { |f| f.class.to_s.demodulize }).to eq %w[AttachmentBruteForcing]
end
end
end |
Ruby | wpscan/spec/app/finders/plugins_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::Base do
subject(:plugins) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(plugins.finders.map { |f| f.class.to_s.demodulize })
.to eq %w[UrlsInHomepage UrlsIn404Page HeaderPattern Comment Xpath BodyPattern JavascriptVar KnownLocations]
end
end
end |
Ruby | wpscan/spec/app/finders/plugin_version_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::PluginVersion::Base do
subject(:plugin_version) { described_class.new(plugin) }
let(:plugin) { WPScan::Model::Plugin.new(slug, target) }
let(:target) { WPScan::Target.new('http://wp.lab/') }
let(:default_finders) { %w[Readme] }
describe '#finders' do
after do
expect(target).to receive(:content_dir).and_return('wp-content')
expect(plugin_version.finders.map { |f| f.class.to_s.demodulize }).to match_array @expected
end
context 'when no related dynamic finders' do
let(:slug) { 'spec' }
it 'contains the default finders' do
@expected = default_finders
end
end
# Dynamic Version Finders are not tested here, they are in
# spec/lib/finders/dynamic_finder/plugin_versions_spec
context 'when dynamic finders' do
WPScan::DB::DynamicFinders::Plugin.versions_finders_configs.each do |plugin_slug, configs|
context "when #{plugin_slug} plugin" do
let(:slug) { plugin_slug }
it 'contains the expected finders (default + the dynamic ones)' do
@expected = default_finders + configs.keys
end
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/themes_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Themes::Base do
subject(:themes) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(themes.finders.map { |f| f.class.to_s.demodulize })
.to eq %w[UrlsInHomepage UrlsIn404Page KnownLocations]
end
end
end |
Ruby | wpscan/spec/app/finders/theme_version_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::ThemeVersion::Base do
subject(:theme_version) { described_class.new(theme) }
let(:theme) { WPScan::Model::Plugin.new(slug, target) }
let(:target) { WPScan::Target.new('http://wp.lab/') }
let(:slug) { 'spec' }
let(:default_finders) { %w[Style WooFrameworkMetaGenerator] }
describe '#finders' do
after do
expect(target).to receive(:content_dir).and_return('wp-content')
expect(theme_version.finders.map { |f| f.class.to_s.demodulize }).to eql @expected
end
context 'when no related dynamic finders' do
it 'contains the default finders' do
@expected = default_finders
end
end
# Dynamic Version Finders are not tested here, they are in
# spec/lib/finders/dynamic_finder/theme_versions_spec
context 'when dynamic finders' do
WPScan::DB::DynamicFinders::Theme.versions_finders_configs.each do |theme_slug, configs|
context "when #{theme_slug} theme" do
let(:slug) { theme_slug }
it 'contains the expected finders (default + the dynamic ones)' do
@expected = default_finders + configs.keys
end
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/timthumbs_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Timthumbs::Base do
subject(:timthumb) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(timthumb.finders.map { |f| f.class.to_s.demodulize }).to eq %w[KnownLocations]
end
end
end |
Ruby | wpscan/spec/app/finders/timthumb_version_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::TimthumbVersion::Base do
subject(:timthumb_version) { described_class.new(target) }
let(:target) { WPScan::Model::Timthumb.new(url) }
let(:url) { 'http://ex.lo/timthumb.php' }
describe '#finders' do
it 'contains the expected finders' do
expect(timthumb_version.finders.map { |f| f.class.to_s.demodulize }).to eq %w[BadRequest]
end
end
end |
Ruby | wpscan/spec/app/finders/users_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Users::Base do
subject(:user) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
it 'contains the expected finders' do
expect(user.finders.map { |f| f.class.to_s.demodulize })
.to eq %w[AuthorPosts WpJsonApi OembedApi RSSGenerator AuthorSitemap YoastSeoAuthorSitemap
AuthorIdBruteForcing LoginErrorMessages]
end
end
end |
Ruby | wpscan/spec/app/finders/wp_version_spec.rb | # frozen_string_literal: true
# If this file is tested alone (rspec path-to-this-file), then there will be an error about
# constants not being intilialized. This is due to the Dynamic Finders.
describe WPScan::Finders::WpVersion::Base do
subject(:wp_version) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#finders' do
let(:expected) { %w[RSSGenerator AtomGenerator RDFGenerator Readme UniqueFingerprinting] }
let(:expected_dynamic_finders) { WPScan::DB::DynamicFinders::Wordpress.versions_finders_configs.keys }
it 'contains the expected finders' do
finders = wp_version.finders.map { |f| f.class.to_s.demodulize }
expect(finders).to match_array expected + expected_dynamic_finders
expect(finders.first).to eql 'RSSGenerator'
expect(finders.last).to eql 'UniqueFingerprinting'
end
end
end |
Ruby | wpscan/spec/app/finders/config_backups/known_filenames_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::ConfigBackups::KnownFilenames do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('config_backups') }
let(:opts) { { list: WPScan::DB_DIR.join('config_backups.txt').to_s } }
describe '#aggressive' do
before do
expect(target).to receive(:sub_dir).at_least(1).and_return(false)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
finder.potential_urls(opts).each_key do |url|
stub_request(:head, url).to_return(status: 404)
end
end
context 'when all files are 404s' do
it 'returns an empty array' do
expect(finder.aggressive(opts)).to eql []
end
end
context 'when some files exist' do
let(:found_files) { ['%23wp-config.php%23', 'wp-config.bak'] }
let(:config_backup) { File.read(fixtures.join('wp-config.php')) }
before do
found_files.each do |file|
stub_request(:head, "#{url}#{file}").to_return(status: 200)
stub_request(:get, "#{url}#{file}").to_return(status: 200, body: config_backup)
end
expect(target).to receive(:homepage_or_404?).twice.and_return(false)
end
it 'returns the expected Array<ConfigBackup>' do
expected = []
found_files.each do |file|
url = "#{target.url}#{file}"
expected << WPScan::Model::ConfigBackup.new(
url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
end
expect(finder.aggressive(opts)).to eql expected
end
end
end
end |
Ruby | wpscan/spec/app/finders/db_exports/known_locations_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::DbExports::KnownLocations do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/aa/' }
let(:fixtures) { FINDERS_FIXTURES.join('db_exports') }
let(:opts) { { list: WPScan::DB_DIR.join('db_exports.txt').to_s } }
describe '#potential_urls' do
before do
allow(target).to receive(:sub_dir).and_return(false)
end
it 'replaces {domain_name} by its values' do
expect(finder.potential_urls(opts).keys).to eql %w[
http://ex.lo/aa/ex.sql
http://ex.lo/aa/wordpress.sql
http://ex.lo/aa/backup/ex.zip
http://ex.lo/aa/backup/mysql.sql
http://ex.lo/aa/backups/ex.sql.gz
http://ex.lo/aa/backups/db_backup.sql
]
end
%w[dev poc www].each do |sub_domain|
context "when #{sub_domain} sub-domain" do
let(:url) { "https://#{sub_domain}.domain.tld" }
it 'replaces {domain_name} by its correct values' do
expect(finder.potential_urls(opts).keys).to include "#{url}/domain.sql", "#{url}/#{sub_domain}.domain.sql"
end
end
end
context 'when multi-level tlds' do
let(:url) { 'https://something.com.tr' }
it 'replaces {domain_name} by its correct value' do
expect(finder.potential_urls(opts).keys).to include 'https://something.com.tr/something.sql'
end
end
context 'when multi-level tlds and sub-domain' do
let(:url) { 'https://dev.something.com.tr' }
it 'replaces {domain_name} by its correct values' do
expect(finder.potential_urls(opts).keys).to include(
'https://dev.something.com.tr/something.sql',
'https://dev.something.com.tr/dev.something.sql'
)
end
end
context 'when some weird stuff' do
let(:url) { 'https://098f6bcd4621d373cade4e832627b4f6.aa-bb-ccc-dd.domain-test.com' }
it 'replaces {domain_name} by its correct values' do
expect(finder.potential_urls(opts).keys).to include(
"#{url}/domain-test.sql",
"#{url}/098f6bcd4621d373cade4e832627b4f6.aa-bb-ccc-dd.domain-test.sql"
)
end
end
context 'when a non standard URL' do
let(:url) { 'http://dc-2' }
it 'replaces {domain_name} by its correct value' do
expect(finder.potential_urls(opts).keys).to include "#{url}/dc-2.sql"
end
end
context 'when an IP address' do
let(:url) { 'http://192.168.1.12' }
it 'replaces {domain_name} by the IP address' do
expect(finder.potential_urls(opts).keys).to include "#{url}/192.168.1.12.sql"
end
end
end
describe '#aggressive' do
before do
allow(target).to receive(:sub_dir).and_return(false)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
finder.potential_urls(opts).each_key do |url|
stub_request(:head, url).to_return(status: 404)
end
end
context 'when all files are 404s' do
it 'returns an empty array' do
expect(finder.aggressive(opts)).to eql []
end
end
context 'when a zip returns a 200' do
xit
end
context 'when some files exist' do
let(:found_files) { %w[ex.sql backups/db_backup.sql] }
let(:db_export) { File.read(fixtures.join('dump.sql')) }
before do
found_files.each do |file|
stub_request(:head, "#{url}#{file}").to_return(status: 200)
stub_request(:get, "#{url}#{file}")
.with(headers: { 'Range' => 'bytes=0-3000' })
.to_return(body: db_export)
end
expect(target).to receive(:homepage_or_404?).twice.and_return(false)
end
context 'when matching the pattern' do
it 'returns the expected Array<DbExport>' do
expected = []
found_files.each do |file|
url = "#{target.url}#{file}"
expected << WPScan::Model::DbExport.new(
url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
end
expect(finder.aggressive(opts)).to eql expected
end
end
context 'when not matching the pattern' do
let(:db_export) { '' }
it 'returns an empty array' do
expect(finder.aggressive(opts)).to eql []
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/backup_db_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::BackupDB do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'backup_db') }
let(:wp_content) { 'wp-content' }
let(:dir_url) { target.url("#{wp_content}/backup-db/") }
before do
expect(target).to receive(:content_dir).at_least(1).and_return(wp_content)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
end
describe '#aggressive' do
context 'when not a 200 or 403' do
it 'returns nil' do
stub_request(:head, dir_url).to_return(status: 404)
expect(finder.aggressive).to eql nil
end
end
context 'when 200 and matching the homepage' do
it 'returns nil' do
stub_request(:head, dir_url)
stub_request(:get, dir_url)
expect(target).to receive(:homepage_or_404?).and_return(true)
expect(finder.aggressive).to eql nil
end
end
context 'when 200 or 403' do
before do
stub_request(:head, dir_url)
stub_request(:get, dir_url).and_return(body: body)
expect(target).to receive(:homepage_or_404?).and_return(false)
end
after do
found = finder.aggressive
expect(found).to eql WPScan::Model::BackupDB.new(
dir_url,
confidence: 70,
found_by: described_class::DIRECT_ACCESS
)
expect(found.interesting_entries).to eq @expected_entries
end
context 'when no directory listing' do
let(:body) { '' }
it 'returns an empty interesting_findings attribute' do
@expected_entries = []
end
end
context 'when directory listing enabled' do
let(:body) { File.read(fixtures.join('dir_listing.html')) }
it 'returns the expected interesting_findings attribute' do
@expected_entries = %w[sqldump.sql test.txt]
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/debug_log_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::DebugLog do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'debug_log') }
let(:wp_content) { 'wp-content' }
let(:log_url) { target.url("#{wp_content}/debug.log") }
before do
expect(target).to receive(:head_or_get_params).and_return(method: :head)
expect(target).to receive(:content_dir).at_least(1).and_return(wp_content)
end
describe '#aggressive' do
before do
stub_request(:head, log_url)
stub_request(:get, log_url).to_return(body: body)
end
context 'when empty file' do
let(:body) { '' }
its(:aggressive) { should be_nil }
end
context 'when a log file' do
let(:body) { File.read(fixtures.join('debug.log')) }
it 'returns the InterestingFinding' do
expect(finder.aggressive).to eql WPScan::Model::DebugLog.new(
log_url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/duplicator_installer_log_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::DuplicatorInstallerLog do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'duplicator_installer_log') }
let(:filename) { 'installer-log.txt' }
let(:log_url) { target.url(filename) }
describe '#aggressive' do
before do
expect(target).to receive(:sub_dir).at_least(1).and_return(false)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
end
context 'when not a 200' do
it 'return nil' do
stub_request(:head, log_url).to_return(status: 404)
expect(finder.aggressive).to eql nil
end
end
context 'when a 200' do
before do
stub_request(:head, log_url)
stub_request(:get, log_url).to_return(body: body)
end
context 'when the body does not match' do
let(:body) { '' }
its(:aggressive) { should be_nil }
end
context 'when the body matches' do
after do
expect(finder.aggressive).to eql WPScan::Model::DuplicatorInstallerLog.new(
log_url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
end
context 'when old versions of the file' do
let(:body) { File.read(fixtures.join('old.txt')) }
it 'returns the InterestingFinding' do
# handled in after loop above
end
end
context 'when newest versions of the file' do
context 'when PRO format 1' do
let(:body) { File.read(fixtures.join('pro.txt')) }
it 'returns the InterestingFinding' do
# handled in after loop above
end
end
context 'when PRO format 2' do
let(:body) { File.read(fixtures.join('pro2.txt')) }
it 'returns the InterestingFinding' do
# handled in after loop above
end
end
context 'when LITE' do
let(:body) { File.read(fixtures.join('lite.txt')) }
it 'returns the InterestingFinding' do
# handled in after loop above
end
end
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/emergency_pwd_reset_script_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::EmergencyPwdResetScript do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:file_url) { "#{url}emergency.php" }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'emergency_pwd_reset_script') }
before do
expect(target).to receive(:sub_dir).at_least(1).and_return(false)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
end
describe '#aggressive' do
context 'when not a 200' do
it 'returns nil' do
stub_request(:head, file_url).to_return(status: 404)
expect(finder.aggressive).to eql nil
end
end
context 'when 200 and matching the homepage' do
before { stub_request(:head, file_url) }
context 'when matching the homepage' do
it 'returns nil' do
stub_request(:get, file_url)
expect(target).to receive(:homepage_or_404?).and_return(true)
expect(finder.aggressive).to eql nil
end
end
context 'when 200' do
before do
stub_request(:get, file_url).and_return(body: body)
expect(target).to receive(:homepage_or_404?).and_return(false)
end
after do
found = finder.aggressive
expect(found).to eql WPScan::Model::EmergencyPwdResetScript.new(
file_url,
confidence: @expected_confidence,
found_by: described_class::DIRECT_ACCESS
)
end
context 'when body matches /password/' do
let(:body) { File.read(fixtures.join('emergency.php')) }
it 'returns with a confidence of 100' do
@expected_confidence = 100
end
end
context 'when body does not match /password/' do
let(:body) { 'maybe, maybe not' }
it 'returns with a confidence of 40' do
@expected_confidence = 40
end
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/full_path_disclosure_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::FullPathDisclosure do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'fpd') }
let(:file_url) { target.url('wp-includes/rss-functions.php') }
describe '#aggressive' do
before do
expect(target).to receive(:sub_dir).at_least(1).and_return(false)
stub_request(:get, file_url).to_return(body: body)
end
context 'when empty file' do
let(:body) { '' }
its(:aggressive) { should be_nil }
end
context 'when a log file' do
let(:body) { File.read(fixtures.join('rss_functions.php')) }
it 'returns the InterestingFinding' do
found = finder.aggressive
expect(found).to eql WPScan::Model::FullPathDisclosure.new(
file_url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
expect(found.interesting_entries).to eql %w[/blog/wp-includes/rss-functions.php]
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/multisite_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::Multisite do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'multisite') }
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/mu_plugins_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::MuPlugins do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'mu_plugins') }
before do
expect(target).to receive(:content_dir).at_least(1).and_return('wp-content')
end
describe '#passive' do
before { stub_request(:get, url).to_return(body: body) }
context 'when no uris' do
let(:body) { '' }
its(:passive) { should be nil }
end
context 'when a large amount of unrelated uris' do
let(:body) do
Array.new(250) { |i| "<a href='#{url}#{i}.html'>Some Link</a><img src='#{url}img-#{i}.png'/>" }.join("\n")
end
it 'should not take a while to process the page' do
time_start = Time.now
result = finder.passive
time_end = Time.now
expect(result).to be nil
expect(time_end - time_start).to be < 1
end
end
context 'when uris' do
let(:body) { File.read(fixtures.join(fixture)) }
context 'when none matching' do
let(:fixture) { 'no_match.html' }
its(:passive) { should be nil }
end
context 'when matching via href' do
let(:fixture) { 'match_href.html' }
its(:passive) { should be_a WPScan::Model::MuPlugins }
end
context 'when matching from src' do
let(:fixture) { 'match_src.html' }
its(:passive) { should be_a WPScan::Model::MuPlugins }
end
end
end
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/php_disabled_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::PHPDisabled do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'php_disabled') }
let(:file_path) { 'wp-includes/version.php' }
let(:file_url) { target.url(file_path) }
describe '#aggressive' do
before do
expect(target).to receive(:sub_dir).at_least(1).and_return(false)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
end
context 'when not a 200' do
it 'return nil' do
stub_request(:head, file_url).to_return(status: 404)
expect(finder.aggressive).to eql nil
end
end
context 'when a 200' do
before do
stub_request(:head, file_url)
stub_request(:get, file_url).to_return(body: body)
end
context 'when the body does not match' do
let(:body) { '' }
its(:aggressive) { should be_nil }
end
context 'when the body matches' do
let(:body) { File.read(fixtures.join('version.php')) }
it 'returns the PHPDisabled' do
expect(finder.aggressive).to eql WPScan::Model::PHPDisabled.new(
file_url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/readme_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::Readme do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'readme') }
describe '#aggressive' do
before do
expect(target).to receive(:sub_dir).at_least(1).and_return(false)
expect(target).to receive(:head_or_get_params).at_least(1).and_return(method: :head)
finder.potential_files.each do |file|
stub_request(:head, target.url(file)).to_return(status: 404)
end
end
context 'when no file present' do
its(:aggressive) { should be_nil }
end
# TODO: case when multiple files are present ? (should return only the first one found)
context 'when a file exists' do
let(:file) { finder.potential_files.sample }
let(:readme) { File.read(fixtures.join('readme-3.9.2.html')) }
before do
stub_request(:head, target.url(file))
stub_request(:get, target.url(file)).to_return(body: readme)
end
it 'returns the expected InterestingFinding' do
expected = WPScan::Model::Readme.new(
target.url(file),
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
expect(finder.aggressive).to eql expected
end
end
end
describe '#potential_files' do
it 'does not contain duplicates' do
expect(finder.potential_files.flatten.uniq.length).to eql finder.potential_files.length
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/registration_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::Registration do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'registration') }
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/tmm_db_migrate_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::TmmDbMigrate do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'tmm_db_migrate') }
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/upload_direcrory_listing_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::UploadDirectoryListing do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'upload_directory_listing') }
let(:wp_content) { 'wp-content' }
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/upload_sql_dump_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::UploadSQLDump do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://ex.lo/' }
let(:dump_url) { "#{url}wp-content/uploads/dump.sql" }
let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'upload_sql_dump') }
let(:wp_content) { 'wp-content' }
describe '#aggressive' do
before do
expect(target).to receive(:content_dir).at_least(1).and_return(wp_content)
expect(target).to receive(:head_or_get_params).and_return(method: :head)
end
after { expect(finder.aggressive).to eql @expected }
context 'when not a 200' do
it 'returns nil' do
stub_request(:head, dump_url).to_return(status: 404)
@expected = nil
end
end
context 'when a 200' do
before do
stub_request(:head, dump_url).to_return(status: 200)
stub_request(:get, dump_url)
.with(headers: { 'Range' => 'bytes=0-3000' })
.to_return(body: File.read(fixtures.join(fixture)))
end
context 'when the body does not match a SQL dump' do
let(:fixture) { 'not_sql.txt' }
it 'returns nil' do
@expected = nil
end
end
context 'when the body matches a SQL dump' do
let(:fixture) { 'dump.sql' }
it 'returns the interesting findings' do
@expected = WPScan::Model::UploadSQLDump.new(
dump_url,
confidence: 100,
found_by: described_class::DIRECT_ACCESS
)
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/interesting_findings/wp_cron_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::InterestingFindings::WPCron do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:wp_content) { 'wp-content' }
before { expect(target).to receive(:sub_dir).at_least(1).and_return(false) }
describe '#aggressive' do
before { stub_request(:get, finder.wp_cron_url).to_return(status: status) }
context 'when 200' do
let(:status) { 200 }
it 'returns the InterestingFinding' do
expect(finder.aggressive).to eql WPScan::Model::WPCron.new(
finder.wp_cron_url,
confidence: 60,
found_by: described_class::DIRECT_ACCESS
)
end
end
context 'otherwise' do
let(:status) { 403 }
its(:aggressive) { should be_nil }
end
end
end |
Ruby | wpscan/spec/app/finders/main_theme/css_style_in_404_page_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::MainTheme::CssStyleIn404Page do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('main_theme', 'css_style_in_404_page') }
# This stuff is just a child class of CssStyleInHomepage (using the error_404_res rather than homepage_res)
# which already has a spec
end |
Ruby | wpscan/spec/app/finders/main_theme/css_style_in_homepage_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::MainTheme::CssStyleInHomepage do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('main_theme', 'css_style_in_homepage') }
describe '#passive' do
after do
stub_request(:get, url).to_return(body: File.read(fixtures.join(fixture)))
expect(finder.passive).to eql @expected
end
context 'when no in scope style' do
let(:fixture) { 'no_in_scope_style.html' }
it 'returns nil' do
@expected = nil
end
end
context 'when in scope style' do
before do
expect(target).to receive(:content_dir).at_least(1).and_return('wp-content')
stub_request(:get, /.*.css/)
end
context 'when in a link href' do
let(:fixture) { 'link_href.html' }
it 'returns the expected theme' do
@expected = WPScan::Model::Theme.new(
'twentyfifteen',
target,
found_by: 'Css Style In Homepage (Passive Detection)',
confidence: 70,
style_url: 'http://wp.lab/wp-content/themes/twentyfifteen/style.css?ver=4.1.1'
)
end
end
context 'when in the style code' do
let(:fixture) { 'style_code.html' }
it 'returns the expected theme' do
@expected = WPScan::Model::Theme.new(
'custom',
target,
found_by: 'Css Style In Homepage (Passive Detection)',
confidence: 70,
style_url: 'http://wp.lab/wp-content/themes/custom/style.css'
)
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/main_theme/urls_in_404_page_spec.rb.rb | # frozen_string_literal: true
describe WPScan::Finders::MainTheme::UrlsIn404Page do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('main_theme', 'urls_in_404_page') }
# This stuff is just a child class of URLsInHomepage (using the error_404_res rather than homepage_res)
# which already has a spec
end |
Ruby | wpscan/spec/app/finders/main_theme/urls_in_homepage_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::MainTheme::UrlsInHomepage do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('main_theme', 'urls_in_homepage') }
it_behaves_like 'App::Finders::WpItems::UrlsInPage' do
let(:page_url) { url }
let(:type) { 'themes' }
let(:uniq_links) { false }
let(:uniq_codes) { false }
let(:expected_from_links) { %w[twentyfifteen twentyfifteen twentyfifteen yolo] }
let(:expected_from_codes) { %w[test yolo] }
end
describe '#passive' do
before do
stub_request(:get, /.*.css/)
stub_request(:get, target.url).to_return(body: File.read(fixtures.join('found.html')))
allow(target).to receive(:content_dir).and_return('wp-content')
end
it 'returns the expected Themes' do
@expected = []
{ 'twentyfifteen' => 6, 'yolo' => 4, 'test' => 2 }.each do |slug, confidence|
@expected << WPScan::Model::Theme.new(
slug, target, found_by: 'Urls In Homepage (Passive Detection)', confidence: confidence
)
end
expect(finder.passive).to eql @expected
end
end
end |
Ruby | wpscan/spec/app/finders/main_theme/woo_framework_meta_generator_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::MainTheme::WooFrameworkMetaGenerator do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('main_theme', 'woo_framework_meta_generator') }
describe '#passive' do
before do
stub_request(:get, url).to_return(body: File.read(fixtures.join(homepage_fixture)))
stub_request(:get, ERROR_404_URL_PATTERN).to_return(body: File.read(fixtures.join(error_404_fixture)))
end
context 'when no Woo generator' do
let(:homepage_fixture) { 'no_woo_generator.html' }
let(:error_404_fixture) { 'no_woo_generator.html' }
it 'returns nil' do
expect(finder.passive).to eql nil
end
end
context 'when Woo generator' do
before do
allow(target).to receive(:content_dir).and_return('wp-content')
stub_request(:get, "#{url}wp-content/themes/Merchant/style.css")
end
context 'from the homepage' do
let(:homepage_fixture) { 'woo_generator.html' }
let(:error_404_fixture) { 'no_woo_generator.html' }
it 'returns the expected theme' do
expect(finder.passive).to eql WPScan::Model::Theme.new(
'Merchant', target,
found_by: 'Woo Framework Meta Generator (Passive Detection)',
confidence: 80
)
end
end
context 'from the 404 page' do
let(:homepage_fixture) { 'no_woo_generator.html' }
let(:error_404_fixture) { 'woo_generator.html' }
it 'returns the expected theme' do
expect(finder.passive).to eql WPScan::Model::Theme.new(
'Merchant', target,
found_by: 'Woo Framework Meta Generator (Passive Detection)',
confidence: 80
)
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/medias/attachment_brute_forcing_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Medias::AttachmentBruteForcing do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('medias', 'attachment_brute_forcing') }
describe '#aggressive' do
xit
end
describe '#target_urls' do
it 'returns the expected urls' do
expect(finder.target_urls(range: (1..2))).to eql(
"#{url}?attachment_id=1" => 1,
"#{url}?attachment_id=2" => 2
)
end
end
end |
Ruby | wpscan/spec/app/finders/passwords/wp_login_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Passwords::WpLogin do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
describe '#valid_credentials?' do
context 'when a non 302' do
it 'returns false' do
expect(finder.valid_credentials?(Typhoeus::Response.new(code: 200, headers: {}))).to be_falsey
end
end
context 'when a 302' do
let(:response) { Typhoeus::Response.new(code: 302, headers: headers) }
context 'when no cookies set' do
let(:headers) { {} }
it 'returns false' do
expect(finder.valid_credentials?(response)).to be_falsey
end
end
context 'when no logged_in cookie set' do
context 'when only one cookie set' do
let(:headers) { 'Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/' }
it 'returns false' do
expect(finder.valid_credentials?(response)).to be_falsey
end
end
context 'when multiple cookies set' do
let(:headers) do
"Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/\r\n" \
'Set-Cookie: something=value; path=/'
end
it 'returns false' do
expect(finder.valid_credentials?(response)).to be_falsey
end
end
end
context 'when logged_in cookie set' do
let(:headers) do
"Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/\r\r" \
"Set-Cookie: wordpress_xxx=yyy; path=/wp-content/plugins; httponly\r\n" \
"Set-Cookie: wordpress_xxx=yyy; path=/wp-admin; httponly\r\n" \
'Set-Cookie: wordpress_logged_in_xxx=yyy; path=/; httponly'
end
it 'returns false' do
expect(finder.valid_credentials?(response)).to eql true
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/passwords/xml_rpc_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Passwords::XMLRPC do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Model::XMLRPC.new(url) }
let(:url) { 'http://ex.lo/xmlrpc.php' }
RESPONSE_403_BODY = '<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>403</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Incorrect username or password.</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>'
describe '#attack' do
let(:wordlist_path) { FINDERS_FIXTURES.join('passwords.txt').to_s }
context 'when no valid credentials' do
before do
stub_request(:post, url).to_return(status: status, body: RESPONSE_403_BODY)
finder.attack(users, wordlist_path)
end
let(:users) { %w[admin].map { |username| WPScan::Model::User.new(username) } }
context 'when status = 200' do
let(:status) { 200 }
its('progress_bar.log') { should be_empty }
end
context 'when status = 403' do
let(:status) { 403 }
its('progress_bar.log') { should be_empty }
end
end
end
end |
Ruby | wpscan/spec/app/finders/plugins/body_pattern_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::BodyPattern do
it_behaves_like WPScan::Finders::DynamicFinder::WpItems::Finder do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
let(:expected_all) { df_expected_all['plugins'] }
let(:item_class) { WPScan::Model::Plugin }
end
end |
Ruby | wpscan/spec/app/finders/plugins/comment_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::Comment do
it_behaves_like WPScan::Finders::DynamicFinder::WpItems::Finder do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
let(:expected_all) { df_expected_all['plugins'] }
let(:item_class) { WPScan::Model::Plugin }
end
end |
Ruby | wpscan/spec/app/finders/plugins/config_parser_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::ConfigParser do
xit
# it_behaves_like WPScan::Finders::DynamicFinder::WpItems::Finder do
# subject(:finder) { described_class.new(target) }
# let(:target) { WPScan::Target.new(url) }
# let(:url) { 'http://wp.lab/' }
# let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
#
# let(:expected_all) { df_expected_all['plugins'] }
# let(:item_class) { WPScan::Model::Plugin }
# end
end |
Ruby | wpscan/spec/app/finders/plugins/header_pattern_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::HeaderPattern do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
def plugin(slug)
WPScan::Model::Plugin.new(slug, target)
end
describe '#passive' do
after do
stub_request(:get, target.url).to_return(headers: headers)
found = finder.passive
expect(found).to match_array @expected
expect(found.first.found_by).to eql 'Header Pattern (Passive Detection)' unless found.empty?
end
context 'when empty headers' do
let(:headers) { {} }
it 'returns an empty array' do
@expected = []
end
end
context 'when headers' do
before { expect(target).to receive(:content_dir).and_return('wp-content') }
let(:headers) { JSON.parse(File.read(fixtures.join('header_pattern_passive_all.html'))) }
it 'returns the expected plugins' do
@expected = []
WPScan::DB::DynamicFinders::Plugin.passive_header_pattern_finder_configs.each_key do |slug|
@expected << plugin(slug)
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/plugins/javascript_var_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::JavascriptVar do
it_behaves_like WPScan::Finders::DynamicFinder::WpItems::Finder do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
let(:expected_all) { df_expected_all['plugins'] }
let(:item_class) { WPScan::Model::Plugin }
end
end |
Ruby | wpscan/spec/app/finders/plugins/known_locations_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::KnownLocations do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('plugins', 'known_locations') }
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/plugins/query_parameter_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::QueryParameter do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
describe '#passive' do
its(:passive) { should be nil }
end
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/plugins/urls_in_404_page_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::UrlsIn404Page do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'https://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('plugins', 'urls_in_404_page') }
# This stuff is just a child class of URLsInHomepage (using the error_404_res rather than homepage_res)
# which already has a spec
end |
Ruby | wpscan/spec/app/finders/plugins/urls_in_homepage_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::UrlsInHomepage do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'https://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('plugins', 'urls_in_homepage') }
before { target.scope << 'sub.lab' }
it_behaves_like 'App::Finders::WpItems::UrlsInPage' do
let(:page_url) { url }
let(:type) { 'plugins' }
let(:uniq_links) { true }
let(:uniq_codes) { true }
let(:expected_from_links) { (1..5).map { |i| "dl-#{i}" } }
let(:expected_from_codes) { (1..6).map { |i| "dc-#{i}" } }
end
describe '#passive' do
before do
stub_request(:get, finder.target.url)
.to_return(body: File.read(fixtures.join('found.html')))
expect(finder.target).to receive(:content_dir).at_least(1).and_return('wp-content')
end
xit
end
end |
Ruby | wpscan/spec/app/finders/plugins/xpath_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Plugins::Xpath do
it_behaves_like WPScan::Finders::DynamicFinder::WpItems::Finder do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { DYNAMIC_FINDERS_FIXTURES.join('plugin_version') }
let(:expected_all) { df_expected_all['plugins'] }
let(:item_class) { WPScan::Model::Plugin }
end
end |
Ruby | wpscan/spec/app/finders/plugin_version/readme_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::PluginVersion::Readme do
subject(:finder) { described_class.new(plugin) }
let(:plugin) { WPScan::Model::Plugin.new('spec', target) }
let(:target) { WPScan::Target.new('http://wp.lab/') }
let(:fixtures) { FINDERS_FIXTURES.join('plugin_version', 'readme') }
def version(number, found_by, confidence)
WPScan::Model::Version.new(
number,
found_by: format('Readme - %s (Aggressive Detection)', found_by),
confidence: confidence,
interesting_entries: [readme_url]
)
end
def stable_tag(number)
version(number, 'Stable Tag', 80)
end
def changelog_section(number)
version(number, 'ChangeLog Section', 50)
end
describe '#aggressive' do
before do
expect(target).to receive(:content_dir).and_return('wp-content')
allow(target).to receive(:head_or_get_params).and_return(method: :head)
stub_request(:head, /.*/).to_return(status: 404)
stub_request(:head, readme_url).to_return(status: 200)
end
let(:readme_url) { plugin.url(WPScan::Model::WpItem::READMES.sample) }
after do
stub_request(:get, readme_url).to_return(body: File.read(fixtures.join(@file)))
expect(finder.aggressive).to eql @expected
end
context 'when no version' do
it 'returns nil' do
@file = 'no_version.txt'
@expected = nil
end
end
context 'when the stable tag does not contain numbers' do
it 'returns nil' do
@file = 'aa-health-calculator.txt'
@expected = nil
end
end
context 'when empty changelog section' do
it 'returns nil' do
@file = 'all-in-one-facebook.txt'
@expected = nil
end
end
context 'when no changelog section' do
it 'returns nil' do
@file = 'blog-reordering.txt'
@expected = nil
end
end
context 'when leaked from the stable tag' do
it 'returns the expected versions' do
@file = 'simple-login-lockdown-0.4.txt'
@expected = [stable_tag('0.4'), changelog_section('04')]
end
end
context 'when leaked from the version' do
it 'returns it' do
@file = 'wp-photo-plus-5.1.15.txt'
@expected = [stable_tag('5.1.15')]
end
end
context 'when version is in a release date format' do
it 'detects and returns it' do
@file = 's2member.txt'
@expected = [stable_tag('141007')]
end
end
context 'when version contains letters' do
it 'returns it' do
@file = 'beta1.txt'
@expected = [stable_tag('2.0.0-beta1')]
end
end
context 'when parsing the changelog for version numbers' do
{
'changelog_version' => '1.3',
'wp_polls' => '2.64',
'nextgen_gallery' => '2.0.66.33',
'wp_user_frontend' => '1.2.3',
'my_calendar' => '2.1.5',
'nextgen_gallery_2' => '1.9.13',
'advanced-most-recent-posts-mod' => '1.6.5.2',
'a-lead-capture-contact-form-and-tab-button-by-awebvoicecom' => '3.1',
'backup-scheduler' => '1.5.9',
'release_date_slash' => '1.0.4',
'cool_tag_cloud' => '2.27'
}.each do |file, version_number|
context "whith #{file}.txt" do
it 'returns the expected version' do
@file = "#{file}.txt"
@expected = [changelog_section(version_number)]
end
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/themes/known_locations_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Themes::KnownLocations do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://ex.lo/' }
let(:fixtures) { FINDERS_FIXTURES.join('themes', 'known_locations') }
describe '#aggressive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/themes/urls_in_404_page_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Themes::UrlsIn404Page do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('themes', 'urls_in_404_page') }
# This stuff is just a child class of URLsInHomepage (using the error_404_res rather than homepage_res)
# which already has a spec
end |
Ruby | wpscan/spec/app/finders/themes/urls_in_homepage_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::Themes::UrlsInHomepage do
subject(:finder) { described_class.new(target) }
let(:target) { WPScan::Target.new(url) }
let(:url) { 'http://wp.lab/' }
let(:fixtures) { FINDERS_FIXTURES.join('themes', 'urls_in_homepage') }
# before { target.scope << 'sub.lab' }
it_behaves_like 'App::Finders::WpItems::UrlsInPage' do
let(:page_url) { url }
let(:type) { 'themes' }
let(:uniq_links) { true }
let(:uniq_codes) { true }
let(:expected_from_links) { %w[dl-1] }
let(:expected_from_codes) { %w[dc-1] }
end
describe '#passive' do
xit
end
end |
Ruby | wpscan/spec/app/finders/theme_version/style_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::ThemeVersion::Style do
subject(:finder) { described_class.new(theme) }
let(:theme) { WPScan::Model::Theme.new('spec', target) }
let(:target) { WPScan::Target.new('http://wp.lab/') }
let(:fixtures) { FINDERS_FIXTURES.join('theme_version', 'style') }
before :all do
Typhoeus::Config.cache = WPScan::Cache::Typhoeus.new(SPECS.join('cache'))
end
before do
expect(target).to receive(:content_dir).at_least(1).and_return('wp-content')
stub_request(:get, /.*.css/).and_return(body: defined?(style_body) ? style_body : '')
end
describe '#passive' do
before { expect(finder).to receive(:cached_style?).and_return(cached?) }
after { finder.passive }
context 'when the style_url request has been cached' do
let(:cached?) { true }
it 'calls the style_version' do
expect(finder).to receive(:style_version)
end
end
context 'when the style_url request has not been cached' do
let(:cached?) { false }
it 'returns nil' do
expect(finder).to_not receive(:style_version)
end
end
end
describe '#aggressive' do
before { expect(finder).to receive(:cached_style?).and_return(cached?) }
after { finder.aggressive }
context 'when the style_url request has been cached' do
let(:cached?) { true }
it 'returns nil' do
expect(finder).to_not receive(:style_version)
end
end
context 'when the style_url request has not been cached' do
let(:cached?) { false }
it 'calls the style_version' do
expect(finder).to receive(:style_version)
end
end
end
describe '#cached_style?' do
it 'calls the Cache with the correct arguments' do
expected = Typhoeus::Request.new(
theme.style_url,
finder.browser.default_request_params.merge(method: :get)
)
expect(Typhoeus::Config.cache).to receive(:get) { |arg| expect(arg).to eql expected }
finder.cached_style?
end
end
describe '#style_version' do
{
'inline' => '1.5.1',
'firefart' => '1.0.0',
'tralling_quote' => '1.3',
'no_version_tag' => nil,
'trunk_version' => nil,
'no_version' => nil
}.each do |file, expected_version|
context "when #{file}" do
let(:style_body) { File.new(fixtures.join("#{file}.css")) }
it 'returns the expected version' do
expected = if expected_version
WPScan::Model::Version.new(
expected_version,
confidence: 80,
interesting_entries: ["#{theme.style_url}, Version: #{expected_version}"]
)
end
expect(finder.style_version).to eql expected
end
end
end
end
end |
Ruby | wpscan/spec/app/finders/theme_version/woo_framework_meta_generator_spec.rb | # frozen_string_literal: true
describe WPScan::Finders::ThemeVersion::WooFrameworkMetaGenerator do
subject(:finder) { described_class.new(theme) }
let(:theme) { WPScan::Model::Theme.new(slug, target) }
let(:target) { WPScan::Target.new('http://wp.lab/') }
let(:fixtures) { FINDERS_FIXTURES.join('theme_version', 'woo_framework_meta_generator') }
before do
expect(target).to receive(:content_dir).and_return('wp-content')
stub_request(:get, /\.css\z/)
end
describe '#passive' do
after do
stub_request(:get, target.url).to_return(body: File.read(fixtures.join('editorial-1.3.5.html')))
expect(finder.passive).to eql @expected
end
context 'when the theme slug does not match' do
let(:slug) { 'spec' }
it 'returns nil' do
@expected = nil
end
end
context 'when the theme slug matches' do
let(:slug) { 'Editorial' }
it 'return the expected version' do
@expected = WPScan::Model::Version.new(
'1.3.5',
found_by: 'Woo Framework Meta Generator (Passive Detection)',
confidence: 80
)
end
end
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.