language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
Ruby
wpscan/app/finders/main_theme/woo_framework_meta_generator.rb
# frozen_string_literal: true module WPScan module Finders module MainTheme # From the WooFramework meta generators class WooFrameworkMetaGenerator < CMSScanner::Finders::Finder THEME_PATTERN = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?"\s+/?>}.freeze FRAMEWORK_PATTERN = %r{<meta name="generator" content="WooFramework\s?([^"]+)?"\s+/?>}.freeze PATTERN = /#{THEME_PATTERN}\s+#{FRAMEWORK_PATTERN}/i.freeze def passive(opts = {}) return unless target.homepage_res.body =~ PATTERN || target.error_404_res.body =~ PATTERN Model::Theme.new( Regexp.last_match[1], target, opts.merge(found_by: found_by, confidence: 80) ) end end end end end
Ruby
wpscan/app/finders/medias/attachment_brute_forcing.rb
# frozen_string_literal: true module WPScan module Finders module Medias # Medias Finder, see https://github.com/wpscanteam/wpscan/issues/172 class AttachmentBruteForcing < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::Enumerator # @param [ Hash ] opts # @option opts [ Range ] :range Mandatory # # @return [ Array<Media> ] def aggressive(opts = {}) found = [] enumerate(target_urls(opts), opts) do |res| next unless res.code == 200 found << Model::Media.new(res.effective_url, opts.merge(found_by: found_by, confidence: 100)) end found end # @param [ Hash ] opts # @option opts [ Range ] :range Mandatory # # @return [ Hash ] def target_urls(opts = {}) urls = {} opts[:range].each do |id| urls[target.uri.join("?attachment_id=#{id}").to_s] = id end urls end def create_progress_bar(opts = {}) super(opts.merge(title: ' Brute Forcing Attachment IDs -')) end end end end end
Ruby
wpscan/app/finders/passwords/wp_login.rb
# frozen_string_literal: true module WPScan module Finders module Passwords # Password attack against the wp-login.php class WpLogin < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::BreadthFirstDictionaryAttack def login_request(username, password) target.login_request(username, password) end def valid_credentials?(response) response.code == 302 && Array(response.headers['Set-Cookie'])&.any? { |cookie| cookie =~ /wordpress_logged_in_/i } end def errored_response?(response) response.code != 200 && response.body !~ /login_error/i end end end end end
Ruby
wpscan/app/finders/passwords/xml_rpc.rb
# frozen_string_literal: true module WPScan module Finders module Passwords # Password attack against the XMLRPC interface class XMLRPC < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::BreadthFirstDictionaryAttack def login_request(username, password) target.method_call('wp.getUsersBlogs', [username, password], cache_ttl: 0) end def valid_credentials?(response) response.code == 200 && response.body.include?('blogName') end def errored_response?(response) response.code != 200 && response.body !~ /Incorrect username or password/i end end end end end
Ruby
wpscan/app/finders/passwords/xml_rpc_multicall.rb
# frozen_string_literal: true module WPScan module Finders module Passwords # Password attack against the XMLRPC interface with the multicall method # WP < 4.4 is vulnerable to such attack class XMLRPCMulticall < CMSScanner::Finders::Finder # @param [ Array<User> ] users # @param [ Array<String> ] passwords # # @return [ Typhoeus::Response ] def do_multi_call(users, passwords) methods = [] users.each do |user| passwords.each do |password| methods << ['wp.getUsersBlogs', user.username, password] end end target.multi_call(methods, cache_ttl: 0).run end # @param [ IO ] file # @param [ Integer ] passwords_size # @return [ Array<String> ] The passwords from the last checked position in the file until there are # passwords_size passwords retrieved def passwords_from_wordlist(file, passwords_size) pwds = [] added_pwds = 0 return pwds if passwords_size.zero? # Make sure that the main code does not call #sysseek or #count etc # otherwise the file descriptor will be set to somwehere else file.each_line(chomp: true) do |line| pwds << line added_pwds += 1 break if added_pwds == passwords_size end pwds end # @param [ Array<Model::User> ] users # @param [ String ] wordlist_path # @param [ Hash ] opts # @option opts [ Boolean ] :show_progression # @option opts [ Integer ] :multicall_max_passwords # # @yield [ Model::User ] When a valid combination is found # # TODO: Make rubocop happy about metrics etc # # rubocop:disable all def attack(users, wordlist_path, opts = {}) checked_passwords = 0 wordlist = File.open(wordlist_path) wordlist_size = wordlist.count max_passwords = opts[:multicall_max_passwords] current_passwords_size = passwords_size(max_passwords, users.size) create_progress_bar(total: (wordlist_size / current_passwords_size.round(1)).ceil, show_progression: opts[:show_progression]) wordlist.sysseek(0) # reset the descriptor to the beginning of the file as it changed with #count loop do current_users = users.select { |user| user.password.nil? } current_passwords = passwords_from_wordlist(wordlist, current_passwords_size) checked_passwords += current_passwords_size break if current_users.empty? || current_passwords.nil? || current_passwords.empty? res = do_multi_call(current_users, current_passwords) progress_bar.increment check_and_output_errors(res) # Avoid to parse the response and iterate over all the structs in the document # if there isn't any tag matching a valid combination next unless res.body =~ /isAdmin/ # maybe a better one ? Nokogiri::XML(res.body).xpath('//struct').each_with_index do |struct, index| next if struct.text =~ /faultCode/ user = current_users[index / current_passwords.size] user.password = current_passwords[index % current_passwords.size] yield user # Updates the current_passwords_size and progress_bar#total # given that less requests will be done due to a valid combination found. current_passwords_size = passwords_size(max_passwords, current_users.size - 1) if current_passwords_size == 0 progress_bar.log('All Found') # remove ? progress_bar.stop break end begin progress_bar.total = progress_bar.progress + ((wordlist_size - checked_passwords) / current_passwords_size.round(1)).ceil rescue ProgressBar::InvalidProgressError end end end # Maybe a progress_bar.stop ? end # rubocop:enable all def passwords_size(max_passwords, users_size) return 1 if max_passwords < users_size return 0 if users_size.zero? max_passwords / users_size end # @param [ Typhoeus::Response ] res def check_and_output_errors(res) progress_bar.log("Incorrect response: #{res.code} / #{res.return_message}") unless res.code == 200 if /parse error. not well formed/i.match?(res.body) progress_bar.log('Parsing error, might be caused by a too high --max-passwords value (such as >= 2k)') end return unless /requested method [^ ]+ does not exist/i.match?(res.body) progress_bar.log('The requested method is not supported') end end end end end
Ruby
wpscan/app/finders/plugins/body_pattern.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from Dynamic Finder 'BodyPattern' class BodyPattern < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 30 # @param [ Hash ] opts The options from the #passive, #aggressive methods # @param [ Typhoeus::Response ] response # @param [ String ] slug # @param [ String ] klass # @param [ Hash ] config The related dynamic finder config hash # # @return [ Plugin ] The detected plugin in the response, related to the config def process_response(opts, response, slug, klass, config) return unless response.body&.match?(config['pattern']) Model::Plugin.new( slug, target, opts.merge(found_by: found_by(klass), confidence: config['confidence'] || DEFAULT_CONFIDENCE) ) end end end end end
Ruby
wpscan/app/finders/plugins/comment.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from the Dynamic Finder 'Comment' class Comment < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 30 # @param [ Hash ] opts The options from the #passive, #aggressive methods # @param [ Typhoeus::Response ] response # @param [ String ] slug # @param [ String ] klass # @param [ Hash ] config The related dynamic finder config hash # # @return [ Plugin ] The detected plugin in the response, related to the config def process_response(opts, response, slug, klass, config) response.html.xpath(config['xpath'] || '//comment()').each do |node| comment = node.text.to_s.strip next unless comment&.match?(config['pattern']) return Model::Plugin.new( slug, target, opts.merge(found_by: found_by(klass), confidence: config['confidence'] || DEFAULT_CONFIDENCE) ) end end end end end end
Ruby
wpscan/app/finders/plugins/config_parser.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from Dynamic Finder 'ConfigParser' class ConfigParser < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 40 # @param [ Hash ] opts The options from the #passive, #aggressive methods # @param [ Typhoeus::Response ] response # @param [ String ] slug # @param [ String ] klass # @param [ Hash ] config The related dynamic finder config hash # # @return [ Plugin ] The detected plugin in the response, related to the config def _process_response(_opts, _response, slug, klass, config) # # TODO. Currently not implemented, and not even loaded by the Finders, as this # finder only has an aggressive method, which has been disabled (globally) # when checking for plugins # Model::Plugin.new( slug, target, opts.merge(found_by: found_by(klass), confidence: config['confidence'] || DEFAULT_CONFIDENCE) ) end end end end end
Ruby
wpscan/app/finders/plugins/header_pattern.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from Dynamic Finder 'HeaderPattern' class HeaderPattern < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 30 # @param [ Hash ] opts # # @return [ Array<Plugin> ] def passive(opts = {}) found = [] headers = target.homepage_res.headers return found if headers.empty? DB::DynamicFinders::Plugin.passive_header_pattern_finder_configs.each do |slug, configs| configs.each do |klass, config| next unless headers[config['header']] && headers[config['header']].to_s =~ config['pattern'] found << Model::Plugin.new( slug, target, opts.merge(found_by: found_by(klass), confidence: config['confidence'] || DEFAULT_CONFIDENCE) ) end end found end # @param [ Hash ] opts # # @return [ nil ] def aggressive(_opts = {}) # None end end end end end
Ruby
wpscan/app/finders/plugins/javascript_var.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from the Dynamic Finder 'JavascriptVar' class JavascriptVar < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 60 # @param [ Hash ] opts The options from the #passive, #aggressive methods # @param [ Typhoeus::Response ] response # @param [ String ] slug # @param [ String ] klass # @param [ Hash ] config The related dynamic finder config hash # # @return [ Plugin ] The detected plugin in the response, related to the config def process_response(opts, response, slug, klass, config) response.html.xpath(config['xpath'] || '//script[not(@src)]').each do |node| next if config['pattern'] && !node.text.match(config['pattern']) return Model::Plugin.new( slug, target, opts.merge(found_by: found_by(klass), confidence: config['confidence'] || DEFAULT_CONFIDENCE) ) end end end end end end
Ruby
wpscan/app/finders/plugins/known_locations.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Known Locations Plugins Finder class KnownLocations < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::Enumerator # @return [ Array<Integer> ] def valid_response_codes @valid_response_codes ||= [200, 401, 403, 500].freeze end # @param [ Hash ] opts # @option opts [ String ] :list # # @return [ Array<Plugin> ] def aggressive(opts = {}) found = [] enumerate(target_urls(opts), opts.merge(check_full_response: true)) do |res, slug| finding_opts = opts.merge(found_by: found_by, confidence: 80, interesting_entries: ["#{res.effective_url}, status: #{res.code}"]) found << Model::Plugin.new(slug, target, finding_opts) raise Error::PluginsThresholdReached if opts[:threshold].positive? && found.size >= opts[:threshold] end found end # @param [ Hash ] opts # @option opts [ String ] :list # # @return [ Hash ] def target_urls(opts = {}) slugs = opts[:list] || DB::Plugins.vulnerable_slugs urls = {} slugs.each do |slug| urls[target.plugin_url(slug)] = slug end urls end def create_progress_bar(opts = {}) super(opts.merge(title: ' Checking Known Locations -')) end end end end end
Ruby
wpscan/app/finders/plugins/query_parameter.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from Dynamic Finder 'QueryParameter' class QueryParameter < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 10 def passive(_opts = {}) # Handled by UrlsInHomePage, so no need to check this twice end # @param [ Hash ] opts The options from the #passive, #aggressive methods # @param [ Typhoeus::Response ] response # @param [ String ] slug # @param [ String ] klass # @param [ Hash ] config The related dynamic finder config hash # # @return [ Plugin ] The detected plugin in the response, related to the config def process_response(opts, response, slug, klass, config) # TODO: when a real case will be found end end end end end
Ruby
wpscan/app/finders/plugins/urls_in_404_page.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # URLs In 404 Page Finder # Typically, the items detected from URLs like /wp-content/plugins/<slug>/ class UrlsIn404Page < UrlsInHomepage # @return [ Typhoeus::Response ] def page_res @page_res ||= target.error_404_res end end end end end
Ruby
wpscan/app/finders/plugins/urls_in_homepage.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # URLs In Homepage Finder # Typically, the items detected from URLs like /wp-content/plugins/<slug>/ class UrlsInHomepage < CMSScanner::Finders::Finder include WpItems::UrlsInPage # @param [ Hash ] opts # # @return [ Array<Plugin> ] def passive(opts = {}) found = [] (items_from_links('plugins') + items_from_codes('plugins')).uniq.sort.each do |slug| found << Model::Plugin.new(slug, target, opts.merge(found_by: found_by, confidence: 80)) end found end # @return [ Typhoeus::Response ] def page_res @page_res ||= target.homepage_res end end end end end
Ruby
wpscan/app/finders/plugins/xpath.rb
# frozen_string_literal: true module WPScan module Finders module Plugins # Plugins finder from the Dynamic Finder 'Xpath' class Xpath < Finders::DynamicFinder::WpItems::Finder DEFAULT_CONFIDENCE = 40 # @param [ Hash ] opts The options from the #passive, #aggressive methods # @param [ Typhoeus::Response ] response # @param [ String ] slug # @param [ String ] klass # @param [ Hash ] config The related dynamic finder config hash # # @return [ Plugin ] The detected plugin in the response, related to the config def process_response(opts, response, slug, klass, config) response.html.xpath(config['xpath']).each do |node| next if config['pattern'] && !node.text.match(config['pattern']) return Model::Plugin.new( slug, target, opts.merge(found_by: found_by(klass), confidence: config['confidence'] || DEFAULT_CONFIDENCE) ) end end end end end end
Ruby
wpscan/app/finders/plugin_version/readme.rb
# frozen_string_literal: true module WPScan module Finders module PluginVersion # Plugin Version Finder from the readme.txt file class Readme < CMSScanner::Finders::Finder # @return [ Version ] def aggressive(_opts = {}) found_by_msg = 'Readme - %s (Aggressive Detection)' # The target(plugin)#readme_url can't be used directly here # as if the --detection-mode is passive, it will always return nil target.potential_readme_filenames.each do |file| res = target.head_and_get(file) next unless res.code == 200 && !(numbers = version_numbers(res.body)).empty? return numbers.reduce([]) do |a, e| a << Model::Version.new( e[0], found_by: format(found_by_msg, e[1]), confidence: e[2], interesting_entries: [res.effective_url] ) end end nil end # @return [ Array<String, String, Integer> ] number, found_by, confidence def version_numbers(body) numbers = [] if (number = from_stable_tag(body)) numbers << [number, 'Stable Tag', 80] end if (number = from_changelog_section(body)) numbers << [number, 'ChangeLog Section', 50] end numbers end # @param [ String ] body # # @return [ String, nil ] The version number detected from the stable tag def from_stable_tag(body) return unless body =~ /\b(?:stable tag|version):\s*(?!trunk)([0-9a-z.-]+)/i number = Regexp.last_match[1] number if /[0-9]+/.match?(number) end # @param [ String ] body # # @return [ String, nil ] The best version number detected from the changelog section def from_changelog_section(body) extracted_versions = body.scan(/^=+\s+(?:v(?:ersion)?\s*)?([0-9.-]+)[^=]*=+$/i) return if extracted_versions.nil? || extracted_versions.empty? extracted_versions.flatten! # must contain at least one number extracted_versions = extracted_versions.grep(/[0-9]+/) sorted = extracted_versions.sort do |x, y| Gem::Version.new(x) <=> Gem::Version.new(y) rescue StandardError 0 end sorted.last end end end end end
Ruby
wpscan/app/finders/themes/known_locations.rb
# frozen_string_literal: true module WPScan module Finders module Themes # Known Locations Themes Finder class KnownLocations < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::Enumerator # @return [ Array<Integer> ] def valid_response_codes @valid_response_codes ||= [200, 401, 403, 500].freeze end # @param [ Hash ] opts # @option opts [ String ] :list # # @return [ Array<Theme> ] def aggressive(opts = {}) found = [] enumerate(target_urls(opts), opts.merge(check_full_response: true)) do |res, slug| finding_opts = opts.merge(found_by: found_by, confidence: 80, interesting_entries: ["#{res.effective_url}, status: #{res.code}"]) found << Model::Theme.new(slug, target, finding_opts) raise Error::ThemesThresholdReached if opts[:threshold].positive? && found.size >= opts[:threshold] end found end # @param [ Hash ] opts # @option opts [ String ] :list # # @return [ Hash ] def target_urls(opts = {}) slugs = opts[:list] || DB::Themes.vulnerable_slugs urls = {} slugs.each do |slug| urls[target.theme_url(slug)] = slug end urls end def create_progress_bar(opts = {}) super(opts.merge(title: ' Checking Known Locations -')) end end end end end
Ruby
wpscan/app/finders/themes/urls_in_404_page.rb
# frozen_string_literal: true module WPScan module Finders module Themes # URLs In 04 Page Finder class UrlsIn404Page < UrlsInHomepage # @return [ Typhoeus::Response ] def page_res @page_res ||= target.error_404_res end end end end end
Ruby
wpscan/app/finders/themes/urls_in_homepage.rb
# frozen_string_literal: true module WPScan module Finders module Themes # URLs In Homepage Finder class UrlsInHomepage < CMSScanner::Finders::Finder include WpItems::UrlsInPage # @param [ Hash ] opts # # @return [ Array<Theme> ] def passive(opts = {}) found = [] (items_from_links('themes') + items_from_codes('themes')).uniq.sort.each do |slug| found << Model::Theme.new(slug, target, opts.merge(found_by: found_by, confidence: 80)) end found end # @return [ Typhoeus::Response ] def page_res @page_res ||= target.homepage_res end end end end end
Ruby
wpscan/app/finders/theme_version/style.rb
# frozen_string_literal: true module WPScan module Finders module ThemeVersion # Theme Version Finder from the style.css file class Style < CMSScanner::Finders::Finder # @param [ Hash ] opts # # @return [ Version ] def passive(_opts = {}) return unless cached_style? style_version end # @param [ Hash ] opts # # @return [ Version ] def aggressive(_opts = {}) return if cached_style? style_version end # @return [ Boolean ] def cached_style? Typhoeus::Config.cache.get(browser.forge_request(target.style_url)) ? true : false end # @return [ Version ] def style_version return unless Browser.get(target.style_url).body =~ /Version:[\t ]*(?!trunk)([0-9a-z.-]+)/i Model::Version.new( Regexp.last_match[1], found_by: found_by, confidence: 80, interesting_entries: ["#{target.style_url}, Match: '#{Regexp.last_match}'"] ) end end end end end
Ruby
wpscan/app/finders/theme_version/woo_framework_meta_generator.rb
# frozen_string_literal: true module WPScan module Finders module ThemeVersion # Theme Version Finder from the WooFramework generators class WooFrameworkMetaGenerator < CMSScanner::Finders::Finder # @param [ Hash ] opts # # @return [ Version ] def passive(_opts = {}) return unless target.blog.homepage_res.body =~ Finders::MainTheme::WooFrameworkMetaGenerator::PATTERN return unless Regexp.last_match[1] == target.slug Model::Version.new(Regexp.last_match[2], found_by: found_by, confidence: 80) end end end end end
Ruby
wpscan/app/finders/timthumbs/known_locations.rb
# frozen_string_literal: true module WPScan module Finders module Timthumbs # Known Locations Timthumbs Finder # Note: A vulnerable version, 2.8.13 can be found here: # https://github.com/GabrielGil/TimThumb/blob/980c3d6a823477761570475e8b83d3e9fcd2d7ae/timthumb.php class KnownLocations < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::Enumerator # @return [ Array<Integer> ] def valid_response_codes @valid_response_codes ||= [400] end # @param [ Hash ] opts # @option opts [ String ] :list Mandatory # # @return [ Array<Timthumb> ] def aggressive(opts = {}) found = [] enumerate(target_urls(opts), opts.merge(check_full_response: 400)) do |res| next unless /no image specified/i.match?(res.body) found << Model::Timthumb.new(res.request.url, opts.merge(found_by: found_by, confidence: 100)) end found end # @param [ Hash ] opts # @option opts [ String ] :list Mandatory # # @return [ Hash ] def target_urls(opts = {}) urls = {} File.open(opts[:list]).each_with_index do |path, index| urls[target.url(path.chomp)] = index end # Add potential timthumbs located in the main theme if target.main_theme main_theme_timthumbs_paths.each do |path| urls[target.main_theme.url(path)] = 1 # index not important there end end urls end def main_theme_timthumbs_paths %w[timthumb.php lib/timthumb.php inc/timthumb.php includes/timthumb.php scripts/timthumb.php tools/timthumb.php functions/timthumb.php] end def create_progress_bar(opts = {}) super(opts.merge(title: ' Checking Known Locations -')) end end end end end
Ruby
wpscan/app/finders/timthumb_version/bad_request.rb
# frozen_string_literal: true module WPScan module Finders module TimthumbVersion # Timthumb Version Finder from the body of a bad request # See https://code.google.com/p/timthumb/source/browse/trunk/timthumb.php#435 class BadRequest < CMSScanner::Finders::Finder # @return [ Version ] def aggressive(_opts = {}) return unless Browser.get(target.url).body =~ /(TimThumb version\s*: ([^<]+))/ Model::Version.new( Regexp.last_match[2], found_by: 'Bad Request (Aggressive Detection)', confidence: 90, interesting_entries: ["#{target.url}, Match: '#{Regexp.last_match[1]}'"] ) end end end end end
Ruby
wpscan/app/finders/users/author_id_brute_forcing.rb
# frozen_string_literal: true module WPScan module Finders module Users # Author Id Brute Forcing class AuthorIdBruteForcing < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::Enumerator # @return [ Array<Integer> ] def valid_response_codes @valid_response_codes ||= [200, 301, 302] end # @param [ Hash ] opts # @option opts [ Range ] :range Mandatory # # @return [ Array<User> ] def aggressive(opts = {}) found = [] found_by_msg = 'Author Id Brute Forcing - %s (Aggressive Detection)' enumerate(target_urls(opts), opts.merge(check_full_response: true)) do |res, id| username, found_by, confidence = potential_username(res) next unless username found << Model::User.new( username, id: id, found_by: format(found_by_msg, found_by), confidence: confidence ) end found end # @param [ Hash ] opts # @option opts [ Range ] :range # # @return [ Hash ] def target_urls(opts = {}) urls = {} opts[:range].each do |id| urls[target.uri.join("?author=#{id}").to_s] = id end urls end def create_progress_bar(opts = {}) super(opts.merge(title: ' Brute Forcing Author IDs -')) end def full_request_params { followlocation: true } end # @param [ Typhoeus::Response ] res # # @return [ Array<String, String, Integer>, nil ] username, found_by, confidence def potential_username(res) username = username_from_author_url(res.effective_url) || username_from_response(res) return username, 'Author Pattern', 100 if username username = display_name_from_body(res.body) return username, 'Display Name', 50 if username end # @param [ String, Addressable::URI ] uri # # @return [ String, nil ] def username_from_author_url(uri) uri = Addressable::URI.parse(uri) unless uri.is_a?(Addressable::URI) uri.path[%r{/author/([^/\b]+)/?}i, 1] end # @param [ Typhoeus::Response ] res # # @return [ String, nil ] The username found def username_from_response(res) # Permalink enabled target.in_scope_uris(res, '//@href[contains(., "author/")]') do |uri| username = username_from_author_url(uri) return username if username end # No permalink, TODO Maybe use xpath to extract the classes ? res.body[/<body class="archive author author-([^\s]+)[ "]/i, 1] end # @param [ String ] body # # @return [ String, nil ] def display_name_from_body(body) page = Nokogiri::HTML.parse(body) # WP >= 3.0 page.css('h1.page-title span').each do |node| text = node.text.to_s.strip return text unless text.empty? end # WP < 3.0 page.xpath('//link[@rel="alternate" and @type="application/rss+xml"]').each do |node| title = node['title'] next unless title =~ /Posts by (.*) Feed\z/i return Regexp.last_match[1] unless Regexp.last_match[1].empty? end nil end end end end end
Ruby
wpscan/app/finders/users/author_posts.rb
# frozen_string_literal: true module WPScan module Finders module Users # Author Posts class AuthorPosts < CMSScanner::Finders::Finder # @param [ Hash ] opts # # @return [ Array<User> ] def passive(opts = {}) found_by_msg = 'Author Posts - %s (Passive Detection)' usernames(opts).reduce([]) do |a, e| a << Model::User.new( e[0], found_by: format(found_by_msg, e[1]), confidence: e[2] ) end end # @param [ Hash ] opts # # @return [ Array<Array>> ] def usernames(_opts = {}) found = potential_usernames(target.homepage_res) return found unless found.empty? target.homepage_res.html.css('header.entry-header a').each do |post_url_node| url = post_url_node['href'] next if url.nil? || url.empty? found += potential_usernames(Browser.get(url)) end found.compact.uniq end # @param [ Typhoeus::Response ] res # # @return [ Array<Array> ] def potential_usernames(res) usernames = [] target.in_scope_uris(res, '//a/@href[contains(., "author")]') do |uri, node| if uri.path =~ %r{/author/([^/\b]+)/?\z}i usernames << [Regexp.last_match[1], 'Author Pattern', 100] elsif /author=[0-9]+/.match?(uri.query) usernames << [node.text.to_s.strip, 'Display Name', 30] end end usernames.uniq end end end end end
Ruby
wpscan/app/finders/users/author_sitemap.rb
# frozen_string_literal: true module WPScan module Finders module Users # Since WP 5.5, /wp-sitemap-users-1.xml is generated and contains # the usernames of accounts who made a post class AuthorSitemap < CMSScanner::Finders::Finder # @param [ Hash ] opts # # @return [ Array<User> ] def aggressive(_opts = {}) found = [] Browser.get(sitemap_url).html.xpath('//url/loc').each do |user_tag| username = user_tag.text.to_s[%r{/author/([^/]+)/}, 1] next unless username && !username.strip.empty? found << Model::User.new(username, found_by: found_by, confidence: 100, interesting_entries: [sitemap_url]) end found end # @return [ String ] The URL of the sitemap def sitemap_url @sitemap_url ||= target.url('wp-sitemap-users-1.xml') end end end end end
Ruby
wpscan/app/finders/users/login_error_messages.rb
# frozen_string_literal: true module WPScan module Finders module Users # Login Error Messages # # Existing username: # WP < 3.1 - Incorrect password. # WP >= 3.1 - The password you entered for the username admin is incorrect. # Non existent username: Invalid username. # class LoginErrorMessages < CMSScanner::Finders::Finder # @param [ Hash ] opts # @option opts [ String ] :list # # @return [ Array<User> ] def aggressive(opts = {}) found = [] usernames(opts).each do |username| res = target.do_login(username, SecureRandom.hex[0, 8]) error = res.html.css('div#login_error').text.strip return found if error.empty? # Protection plugin / error disabled next unless /The password you entered for the username|Incorrect Password/i.match?(error) found << Model::User.new(username, found_by: found_by, confidence: 100) end found end # @return [ Array<String> ] List of usernames to check def usernames(opts = {}) # usernames from the potential Users found unames = opts[:found].map(&:username) Array(opts[:list]).each { |uname| unames << uname.chomp } unames.uniq end end end end end
Ruby
wpscan/app/finders/users/oembed_api.rb
# frozen_string_literal: true module WPScan module Finders module Users # Since WP 4.4, the oembed API can disclose a user # https://github.com/wpscanteam/wpscan/issues/1049 class OembedApi < CMSScanner::Finders::Finder # @param [ Hash ] opts # # @return [ Array<User> ] def passive(_opts = {}) # TODO: get the api_url from the Homepage and query it if present, # then discard the aggressive check if same/similar URL end # @param [ Hash ] opts # # @return [ Array<User> ] def aggressive(_opts = {}) oembed_data = JSON.parse(Browser.get(api_url).body) details = user_details_from_oembed_data(oembed_data) return [] unless details [Model::User.new(details[0], found_by: format(found_by_msg, details[1]), confidence: details[2], interesting_entries: [api_url])] rescue JSON::ParserError [] end def user_details_from_oembed_data(oembed_data) return unless oembed_data oembed_data = oembed_data.first if oembed_data.is_a?(Array) if oembed_data['author_url'] =~ %r{/author/([^/]+)/?\z} details = [Regexp.last_match[1], 'Author URL', 90] elsif oembed_data['author_name'] && !oembed_data['author_name'].empty? details = [oembed_data['author_name'], 'Author Name', 70] end details end def found_by_msg 'Oembed API - %s (Aggressive Detection)' end # @return [ String ] The URL of the API listing the Users def api_url @api_url ||= target.url("wp-json/oembed/1.0/embed?url=#{target.url}&format=json") end end end end end
Ruby
wpscan/app/finders/users/rss_generator.rb
# frozen_string_literal: true module WPScan module Finders module Users # Users disclosed from the dc:creator field in the RSS # The names disclosed are display names, however depending on the configuration of the blog, # they can be the same than usernames class RSSGenerator < Finders::WpVersion::RSSGenerator def process_urls(urls, _opts = {}) found = [] urls.each do |url| res = Browser.get_and_follow_location(url) next unless res.code == 200 && res.body =~ /<dc:creator>/i potential_usernames = [] begin res.xml.xpath('//item/dc:creator').each do |node| username = node.text.to_s # Ignoring potential username longer than 60 characters and containing accents # as they are considered invalid. See https://github.com/wpscanteam/wpscan/issues/1215 next if username.strip.empty? || username.length > 60 || username =~ /[^\x00-\x7F]/ potential_usernames << username end rescue Nokogiri::XML::XPath::SyntaxError next end potential_usernames.uniq.each do |username| found << Model::User.new(username, found_by: found_by, confidence: 50) end break end found end end end end end
Ruby
wpscan/app/finders/users/wp_json_api.rb
# frozen_string_literal: true module WPScan module Finders module Users # WP JSON API # # Since 4.7 - Need more investigation as it seems WP 4.7.1 reduces the exposure, see https://github.com/wpscanteam/wpscan/issues/1038) # For the pagination, see https://github.com/wpscanteam/wpscan/issues/1285 # class WpJsonApi < CMSScanner::Finders::Finder MAX_PER_PAGE = 100 # See https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/ # @param [ Hash ] opts # # @return [ Array<User> ] def aggressive(_opts = {}) found = [] current_page = 0 loop do current_page += 1 res = Browser.get(api_url, params: { per_page: MAX_PER_PAGE, page: current_page }) total_pages ||= res.headers['X-WP-TotalPages'].to_i users_in_page = users_from_response(res) found += users_in_page break if current_page >= total_pages || users_in_page.empty? end found rescue JSON::ParserError, TypeError found end # @param [ Typhoeus::Response ] response # # @return [ Array<User> ] The users from the response def users_from_response(response) found = [] JSON.parse(response.body)&.each do |user| found << Model::User.new(user['slug'], id: user['id'], found_by: found_by, confidence: 100, interesting_entries: [response.effective_url]) end found end # @return [ String ] The URL of the API listing the Users def api_url return @api_url if @api_url target.in_scope_uris(target.homepage_res, "//link[@rel='https://api.w.org/']/@href").each do |uri| return @api_url = uri.join('wp/v2/users/').to_s if uri.path.include?('wp-json') end @api_url = target.url('wp-json/wp/v2/users/') end end end end end
Ruby
wpscan/app/finders/users/yoast_seo_author_sitemap.rb
# frozen_string_literal: true module WPScan module Finders module Users # The YOAST SEO plugin has an author-sitemap.xml which can leak usernames # See https://github.com/wpscanteam/wpscan/issues/1228 class YoastSeoAuthorSitemap < AuthorSitemap # @return [ String ] The URL of the author-sitemap def sitemap_url @sitemap_url ||= target.url('author-sitemap.xml') end end end end end
Ruby
wpscan/app/finders/wp_items/urls_in_page.rb
# frozen_string_literal: true module WPScan module Finders module WpItems # URLs In Homepage Module to use in plugins & themes finders module UrlsInPage # @param [ String ] type plugins / themes # @param [ Boolean ] uniq Wether or not to apply the #uniq on the results # # @return [ Array<String> ] The plugins/themes detected in the href, src attributes of the page def items_from_links(type, uniq: true) found = [] xpath = format( '(//@href|//@src|//@data-src)[contains(., "%s")]', type == 'plugins' ? target.plugins_dir : target.content_dir ) target.in_scope_uris(page_res, xpath) do |uri| next unless uri.to_s =~ item_attribute_pattern(type) slug = Regexp.last_match[1]&.strip found << slug unless slug&.empty? end uniq ? found.uniq.sort : found.sort end # @param [ String ] type plugins / themes # @param [ Boolean ] uniq Wether or not to apply the #uniq on the results # # @return [Array<String> ] The plugins/themes detected in the javascript/style of the homepage def items_from_codes(type, uniq: true) found = [] page_res.html.xpath('//script[not(@src)]|//style[not(@src)]').each do |tag| code = tag.text.to_s next if code.empty? code.scan(item_code_pattern(type)).flatten.uniq.each { |slug| found << slug } end uniq ? found.uniq.sort : found.sort end # @param [ String ] type # # @return [ Regexp ] def item_attribute_pattern(type) @item_attribute_pattern ||= %r{#{item_url_pattern(type)}([^/]+)/}i end # @param [ String ] type # # @return [ Regexp ] def item_code_pattern(type) @item_code_pattern ||= %r{["'( ]#{item_url_pattern(type)}([^\\/)"']+)}i end # @param [ String ] type # # @return [ Regexp ] def item_url_pattern(type) item_dir = type == 'plugins' ? target.plugins_dir : target.content_dir item_url = type == 'plugins' ? target.plugins_url : target.content_url url = /#{item_url.gsub(/\A(?:https?)/i, 'https?').gsub('/', '\\\\\?\/')}/i item_dir = %r{(?:#{url}|\\?/#{item_dir.gsub('/', '\\\\\?\/')}\\?/)}i type == 'plugins' ? item_dir : %r{#{item_dir}#{type}\\?/}i end end end end end
Ruby
wpscan/app/finders/wp_version/atom_generator.rb
# frozen_string_literal: true module WPScan module Finders module WpVersion # Atom Generator Version Finder class AtomGenerator < CMSScanner::Finders::Finder include Finder::WpVersion::SmartURLChecker def process_urls(urls, _opts = {}) found = Findings.new urls.each do |url| res = Browser.get_and_follow_location(url) res.html.css('generator').each do |node| next unless node.text.to_s.strip.casecmp('wordpress').zero? found << create_version( node['version'], found_by: found_by, entries: ["#{res.effective_url}, #{node.to_s.strip}"] ) end end found end def passive_urls_xpath '//link[@rel="alternate" and @type="application/atom+xml"]/@href' end def aggressive_urls(_opts = {}) %w[feed/atom/ ?feed=atom].reduce([]) do |a, uri| a << target.url(uri) end end end end end end
Ruby
wpscan/app/finders/wp_version/rdf_generator.rb
# frozen_string_literal: true module WPScan module Finders module WpVersion # RDF Generator Version Finder class RDFGenerator < CMSScanner::Finders::Finder include Finder::WpVersion::SmartURLChecker def process_urls(urls, _opts = {}) found = Findings.new urls.each do |url| res = Browser.get_and_follow_location(url) res.html.xpath('//generatoragent').each do |node| next unless node['rdf:resource'] =~ %r{\Ahttps?://wordpress\.(?:[a-z.]+)/\?v=(.*)\z}i found << create_version( Regexp.last_match[1], found_by: found_by, entries: ["#{res.effective_url}, #{node.to_s.strip}"] ) end end found end def passive_urls_xpath '//a[contains(@href, "/rdf")]/@href' end def aggressive_urls(_opts = {}) [target.url('feed/rdf/')] end end end end end
Ruby
wpscan/app/finders/wp_version/readme.rb
# frozen_string_literal: true module WPScan module Finders module WpVersion # Readme Version Finder class Readme < CMSScanner::Finders::Finder # @return [ WpVersion ] def aggressive(_opts = {}) readme_url = target.url('readme.html') # Maybe move this into the Target ? node = Browser.get(readme_url).html.css('h1#logo').last return unless node&.text.to_s.strip =~ /\AVersion (.*)\z/i number = Regexp.last_match(1) return unless Model::WpVersion.valid?(number) Model::WpVersion.new( number, found_by: 'Readme (Aggressive Detection)', # Since WP 4.7, the Readme only contains the major version (ie 4.7, 4.8 etc) confidence: number >= '4.7' ? 10 : 90, interesting_entries: ["#{readme_url}, Match: '#{node.text.to_s.strip}'"] ) end end end end end
Ruby
wpscan/app/finders/wp_version/rss_generator.rb
# frozen_string_literal: true module WPScan module Finders module WpVersion # RSS Generator Version Finder class RSSGenerator < CMSScanner::Finders::Finder include Finder::WpVersion::SmartURLChecker def process_urls(urls, _opts = {}) found = Findings.new urls.each do |url| res = Browser.get_and_follow_location(url) res.html.xpath('//comment()[contains(., "wordpress")] | //generator').each do |node| node_text = node.text.to_s.strip next unless node_text =~ %r{\Ahttps?://wordpress\.(?:[a-z]+)/\?v=(.*)\z}i || node_text =~ %r{\Agenerator="wordpress/([^"]+)"\z}i found << create_version( Regexp.last_match[1], found_by: found_by, entries: ["#{res.effective_url}, #{node.to_s.strip}"] ) end end found end def passive_urls_xpath '//link[@rel="alternate" and @type="application/rss+xml"]/@href' end def aggressive_urls(_opts = {}) %w[feed/ comments/feed/ feed/rss/ feed/rss2/].reduce([]) do |a, uri| a << target.url(uri) end end end end end end
Ruby
wpscan/app/finders/wp_version/unique_fingerprinting.rb
# frozen_string_literal: true module WPScan module Finders module WpVersion # Unique Fingerprinting Version Finder class UniqueFingerprinting < CMSScanner::Finders::Finder include CMSScanner::Finders::Finder::Fingerprinter # @return [ WpVersion ] def aggressive(opts = {}) fingerprint(DB::Fingerprints.wp_unique_fingerprints, opts) do |version_number, url, md5sum| hydra.abort progress_bar.finish return Model::WpVersion.new( version_number, found_by: 'Unique Fingerprinting (Aggressive Detection)', confidence: 100, interesting_entries: ["#{url} md5sum is #{md5sum}"] ) end nil end def create_progress_bar(opts = {}) super(opts.merge(title: 'Fingerprinting the version -')) end end end end end
Ruby
wpscan/app/models/config_backup.rb
# frozen_string_literal: true module WPScan module Model # Config Backup class ConfigBackup < InterestingFinding end end end
Ruby
wpscan/app/models/db_export.rb
# frozen_string_literal: true module WPScan module Model # DB Export class DbExport < InterestingFinding end end end
Ruby
wpscan/app/models/interesting_finding.rb
# frozen_string_literal: true module WPScan module Model # Custom class to include the WPScan::References module class InterestingFinding < CMSScanner::Model::InterestingFinding include References end class BackupDB < InterestingFinding def to_s @to_s ||= "A backup directory has been found: #{url}" end # @return [ Hash ] def references @references ||= { url: ['https://github.com/wpscanteam/wpscan/issues/422'] } end end class DebugLog < InterestingFinding def to_s @to_s ||= "Debug Log found: #{url}" end # @ return [ Hash ] def references @references ||= { url: ['https://codex.wordpress.org/Debugging_in_WordPress'] } end end class DuplicatorInstallerLog < InterestingFinding # @return [ Hash ] def references @references ||= { url: ['https://www.exploit-db.com/ghdb/3981/'] } end end class EmergencyPwdResetScript < InterestingFinding def references @references ||= { url: ['https://codex.wordpress.org/Resetting_Your_Password#Using_the_Emergency_Password_Reset_Script'] } end end class FullPathDisclosure < InterestingFinding def to_s @to_s ||= "Full Path Disclosure found: #{url}" end # @return [ Hash ] def references @references ||= { url: ['https://www.owasp.org/index.php/Full_Path_Disclosure'] } end end class MuPlugins < InterestingFinding # @return [ String ] def to_s @to_s ||= "This site has 'Must Use Plugins': #{url}" end # @return [ Hash ] def references @references ||= { url: ['http://codex.wordpress.org/Must_Use_Plugins'] } end end class Multisite < InterestingFinding # @return [ String ] def to_s @to_s ||= 'This site seems to be a multisite' end # @return [ Hash ] def references @references ||= { url: ['http://codex.wordpress.org/Glossary#Multisite'] } end end class Readme < InterestingFinding def to_s @to_s ||= "WordPress readme found: #{url}" end end class Registration < InterestingFinding # @return [ String ] def to_s @to_s ||= "Registration is enabled: #{url}" end end class TmmDbMigrate < InterestingFinding def to_s @to_s ||= "ThemeMakers migration file found: #{url}" end # @return [ Hash ] def references @references ||= { packetstorm: [131_957] } end end class UploadDirectoryListing < InterestingFinding # @return [ String ] def to_s @to_s ||= "Upload directory has listing enabled: #{url}" end end class UploadSQLDump < InterestingFinding def to_s @to_s ||= "SQL Dump found: #{url}" end end class WPCron < InterestingFinding # @return [ String ] def to_s @to_s ||= "The external WP-Cron seems to be enabled: #{url}" end # @return [ Hash ] def references @references ||= { url: [ 'https://www.iplocation.net/defend-wordpress-from-ddos', 'https://github.com/wpscanteam/wpscan/issues/1299' ] } end end class PHPDisabled < InterestingFinding # @return [ String ] def to_s @to_s ||= 'PHP seems to be disabled' end # @return [ Hash ] def references @references ||= { url: ['https://github.com/wpscanteam/wpscan/issues/1593'] } end end end end
Ruby
wpscan/app/models/media.rb
# frozen_string_literal: true module WPScan module Model # Media class Media < InterestingFinding end end end
Ruby
wpscan/app/models/plugin.rb
# frozen_string_literal: true module WPScan module Model # WordPress Plugin class Plugin < WpItem # See WpItem def initialize(slug, blog, opts = {}) super(slug, blog, opts) # To be used by #head_and_get # If custom wp-content, it will be replaced by blog#url @path_from_blog = "wp-content/plugins/#{slug}/" @uri = Addressable::URI.parse(blog.url(path_from_blog)) end # Retrieve the metadata from the vuln API if available (and a valid token is given), # or the local metadata db otherwise # @return [ Hash ] def metadata @metadata ||= db_data.empty? ? DB::Plugin.metadata_at(slug) : db_data end # @return [ Hash ] def db_data @db_data ||= DB::VulnApi.plugin_data(slug) end # @param [ Hash ] opts # # @return [ Model::Version, false ] def version(opts = {}) @version = Finders::PluginVersion::Base.find(self, version_detection_opts.merge(opts)) if @version.nil? @version end # @return [ Array<String> ] def potential_readme_filenames @potential_readme_filenames ||= Array((DB::DynamicFinders::Plugin.df_data.dig(slug, 'Readme', 'path') || super)) end end end end
Ruby
wpscan/app/models/theme.rb
# frozen_string_literal: true module WPScan module Model # WordPress Theme class Theme < WpItem attr_reader :style_url, :style_name, :style_uri, :author, :author_uri, :template, :description, :license, :license_uri, :tags, :text_domain # See WpItem def initialize(slug, blog, opts = {}) super(slug, blog, opts) # To be used by #head_and_get # If custom wp-content, it will be replaced by blog#url @path_from_blog = "wp-content/themes/#{slug}/" @uri = Addressable::URI.parse(blog.url(path_from_blog)) @style_url = opts[:style_url] || url('style.css') parse_style end # Retrieve the metadata from the vuln API if available (and a valid token is given), # or the local metadata db otherwise # @return [ JSON ] def metadata @metadata ||= db_data.empty? ? DB::Theme.metadata_at(slug) : db_data end # @return [ Hash ] def db_data @db_data ||= DB::VulnApi.theme_data(slug) end # @param [ Hash ] opts # # @return [ Model::Version, false ] def version(opts = {}) @version = Finders::ThemeVersion::Base.find(self, version_detection_opts.merge(opts)) if @version.nil? @version end # @return [ Theme ] def parent_theme return unless template return unless style_body =~ /^@import\surl\(["']?([^"')]+)["']?\);\s*$/i opts = detection_opts.merge( style_url: url(Regexp.last_match[1]), found_by: 'Parent Themes (Passive Detection)', confidence: 100 ).merge(version_detection: version_detection_opts) self.class.new(template, blog, opts) end # @param [ Integer ] depth # # @retun [ Array<Theme> ] def parent_themes(depth = 3) theme = self found = [] (1..depth).each do |_| parent = theme.parent_theme break unless parent found << parent theme = parent end found end def style_body @style_body ||= Browser.get(style_url).body end def parse_style { style_name: 'Theme Name', style_uri: 'Theme URI', author: 'Author', author_uri: 'Author URI', template: 'Template', description: 'Description', license: 'License', license_uri: 'License URI', tags: 'Tags', text_domain: 'Text Domain' }.each do |attribute, tag| instance_variable_set(:"@#{attribute}", parse_style_tag(style_body, tag)) end end # @param [ String ] bofy # @param [ String ] tag # # @return [ String ] def parse_style_tag(body, tag) value = body[/\b#{Regexp.escape(tag)}:[\t ]*([^\r\n*]+)/, 1] value && !value.strip.empty? ? value.strip : nil end def ==(other) super(other) && style_url == other.style_url end end end end
Ruby
wpscan/app/models/timthumb.rb
# frozen_string_literal: true module WPScan module Model # Timthumb class Timthumb < InterestingFinding include Vulnerable attr_reader :version_detection_opts # @param [ String ] url # @param [ Hash ] opts # @option opts [ Symbol ] :mode The mode to use to detect the version def initialize(url, opts = {}) super(url, opts) @version_detection_opts = opts[:version_detection] || {} end # @param [ Hash ] opts # # @return [ Model::Version, false ] def version(opts = {}) @version = Finders::TimthumbVersion::Base.find(self, version_detection_opts.merge(opts)) if @version.nil? @version end # @return [ Array<Vulnerability> ] def vulnerabilities vulns = [] vulns << rce_webshot_vuln if version == false || (version > '1.35' && version < '2.8.14' && webshot_enabled?) vulns << rce_132_vuln if version == false || version < '1.33' vulns end # @return [ Vulnerability ] The RCE in the <= 1.32 def rce_132_vuln Vulnerability.new( 'Timthumb <= 1.32 Remote Code Execution', references: { exploitdb: ['17602'] }, type: 'RCE', fixed_in: '1.33' ) end # @return [ Vulnerability ] The RCE due to the WebShot in the > 1.35 (or >= 2.0) and <= 2.8.13 def rce_webshot_vuln Vulnerability.new( 'Timthumb <= 2.8.13 WebShot Remote Code Execution', references: { url: ['http://seclists.org/fulldisclosure/2014/Jun/117', 'https://github.com/wpscanteam/wpscan/issues/519'], cve: '2014-4663' }, type: 'RCE', fixed_in: '2.8.14' ) end # @return [ Boolean ] def webshot_enabled? res = Browser.get(url, params: { webshot: 1, src: "http://#{default_allowed_domains.sample}" }) !/WEBSHOT_ENABLED == true/.match?(res.body) end # @return [ Array<String> ] The default allowed domains (between the 2.0 and 2.8.13) def default_allowed_domains %w[flickr.com picasa.com img.youtube.com upload.wikimedia.org] end end end end
Ruby
wpscan/app/models/wp_item.rb
# frozen_string_literal: true module WPScan module Model # WpItem (superclass of Plugin & Theme) class WpItem include Vulnerable include Finders::Finding include CMSScanner::Target::Platform::PHP include CMSScanner::Target::Server::Generic # Most common readme filenames, based on checking all public plugins and themes. READMES = %w[readme.txt README.txt README.md readme.md Readme.txt].freeze attr_reader :uri, :slug, :detection_opts, :version_detection_opts, :blog, :path_from_blog, :db_data delegate :homepage_res, :error_404_res, :xpath_pattern_from_page, :in_scope_uris, :head_or_get_params, to: :blog # @param [ String ] slug The plugin/theme slug # @param [ Target ] blog The targeted blog # @param [ Hash ] opts # @option opts [ Symbol ] :mode The detection mode to use # @option opts [ Hash ] :version_detection The options to use when looking for the version # @option opts [ String ] :url The URL of the item def initialize(slug, blog, opts = {}) @slug = Addressable::URI.unencode(slug) @blog = blog @uri = Addressable::URI.parse(opts[:url]) if opts[:url] @detection_opts = { mode: opts[:mode] } @version_detection_opts = opts[:version_detection] || {} parse_finding_options(opts) end # @return [ Array<Vulnerabily> ] def vulnerabilities return @vulnerabilities if @vulnerabilities @vulnerabilities = [] Array(db_data['vulnerabilities']).each do |json_vuln| vulnerability = Vulnerability.load_from_json(json_vuln) @vulnerabilities << vulnerability if vulnerable_to?(vulnerability) end @vulnerabilities end # Checks if the wp_item is vulnerable to a specific vulnerability # # @param [ Vulnerability ] vuln Vulnerability to check the item against # # @return [ Boolean ] def vulnerable_to?(vuln) return false if version && vuln&.introduced_in && version < vuln.introduced_in return true unless version && vuln&.fixed_in && !vuln.fixed_in.empty? version < vuln.fixed_in end # @return [ String ] def latest_version @latest_version ||= metadata['latest_version'] ? Model::Version.new(metadata['latest_version']) : nil end # Not used anywhere ATM # @return [ Boolean ] def popular? @popular ||= metadata['popular'] ? true : false end # @return [ String ] def last_updated @last_updated ||= metadata['last_updated'] end # @return [ Boolean ] def outdated? @outdated ||= if version && latest_version version < latest_version else false end end # @param [ String ] path Optional path to merge with the uri # # @return [ String ] def url(path = nil) return unless @uri return @uri.to_s unless path @uri.join(Addressable::URI.encode(path)).to_s end # @return [ Boolean ] def ==(other) self.class == other.class && slug == other.slug end def to_s slug end # @return [ Symbol ] The Class symbol associated to the item def classify @classify ||= classify_slug(slug) end # @return [ String, False ] The readme url if found, false otherwise def readme_url return if detection_opts[:mode] == :passive return @readme_url unless @readme_url.nil? potential_readme_filenames.each do |path| t_url = url(path) return @readme_url = t_url if Browser.forge_request(t_url, blog.head_or_get_params).run.code == 200 end @readme_url = false end def potential_readme_filenames @potential_readme_filenames ||= READMES end # @param [ String ] path # @param [ Hash ] params The request params # # @return [ Boolean ] def directory_listing?(path = nil, params = {}) return if detection_opts[:mode] == :passive super(path, params) end # @param [ String ] path # @param [ Hash ] params The request params # # @return [ Boolean ] def error_log?(path = 'error_log', params = {}) return if detection_opts[:mode] == :passive super(path, params) end # See CMSScanner::Target#head_and_get # # This is used by the error_log? above in the super() # to have the correct path (ie readme.txt checked from the plugin/theme location # and not from the blog root). Could also be used in finders # # @param [ String ] path # @param [ Array<String> ] codes # @param [ Hash ] params The requests params # @option params [ Hash ] :head Request params for the HEAD # @option params [ hash ] :get Request params for the GET # # @return [ Typhoeus::Response ] def head_and_get(path, codes = [200], params = {}) final_path = @path_from_blog.dup # @path_from_blog is set in the plugin/theme final_path << path unless path.nil? blog.head_and_get(final_path, codes, params) end end end end
Ruby
wpscan/app/models/wp_version.rb
# frozen_string_literal: true module WPScan module Model # WP Version class WpVersion < CMSScanner::Model::Version include Vulnerable def initialize(number, opts = {}) raise Error::InvalidWordPressVersion unless WpVersion.valid?(number.to_s) super(number, opts) end # @param [ String ] number # # @return [ Boolean ] true if the number is a valid WP version, false otherwise def self.valid?(number) all.include?(number) end # @return [ Array<String> ] All the version numbers def self.all return @all_numbers if @all_numbers @all_numbers = [] DB::Fingerprints.wp_fingerprints.each_value do |fp| @all_numbers << fp.values end # @all_numbers.flatten.uniq.sort! {} doesn't produce the same result here. @all_numbers.flatten! @all_numbers.uniq! @all_numbers.sort! { |a, b| Gem::Version.new(b) <=> Gem::Version.new(a) } end # Retrieve the metadata from the vuln API if available (and a valid token is given), # or the local metadata db otherwise # @return [ Hash ] def metadata @metadata ||= db_data.empty? ? DB::Version.metadata_at(number) : db_data end # @return [ Hash ] def db_data @db_data ||= DB::VulnApi.wordpress_data(number) end # @return [ Array<Vulnerability> ] def vulnerabilities return @vulnerabilities if @vulnerabilities @vulnerabilities = [] Array(db_data['vulnerabilities']).each do |json_vuln| @vulnerabilities << Vulnerability.load_from_json(json_vuln) end @vulnerabilities end # @return [ String ] def release_date @release_date ||= metadata['release_date'] || 'Unknown' end # @return [ String ] def status @status ||= metadata['status'] || 'Unknown' end end end end
Ruby
wpscan/app/models/xml_rpc.rb
# frozen_string_literal: true module WPScan module Model # Override of the CMSScanner::XMLRPC to include the references class XMLRPC < CMSScanner::Model::XMLRPC include References # To be able to use the :wpvulndb reference if needed # @return [ Hash ] def references @references ||= { url: ['http://codex.wordpress.org/XML-RPC_Pingback_API'], metasploit: [ 'auxiliary/scanner/http/wordpress_ghost_scanner', 'auxiliary/dos/http/wordpress_xmlrpc_dos', 'auxiliary/scanner/http/wordpress_xmlrpc_login', 'auxiliary/scanner/http/wordpress_pingback_access' ] } end end end end
wpscan/app/views/cli/finding.erb
| Found By: <%= @item.found_by %> <% @item.interesting_entries.each do |entry| -%> | - <%= entry %> <% end -%> <% unless (confirmed = @item.confirmed_by).empty? -%> <% if confirmed.size == 1 -%> | Confirmed By: <%= confirmed.first.found_by %> <% confirmed.first.interesting_entries.each do |entry| -%> | - <%= entry %> <% end -%> <% else -%> | Confirmed By: <% confirmed.each do |c| -%> | <%= c.found_by %> <% c.interesting_entries.each do |entry| -%> | - <%= entry %> <% end -%> <% end -%> <% end -%> <% end -%> <% if @item.respond_to?(:vulnerabilities) && !(vulns = @item.vulnerabilities).empty? -%> <% vulns_size = vulns.size -%> | | <%= critical_icon %> <%= vulns_size %> <%= vulns_size == 1 ? 'vulnerability' : 'vulnerabilities' %> identified: | <% vulns.each_with_index do |vulnerability, index| -%> <%= render('@vulnerability', v: vulnerability) -%> <% if index != vulns_size -1 -%> | <% end -%> <% end -%> <% end -%>
wpscan/app/views/cli/theme.erb
<%= render('@wp_item', wp_item: @theme) -%> | Style URL: <%= @theme.style_url %> <% if @theme.style_name -%> | Style Name: <%= @theme.style_name %> <% end -%> <% if @theme.style_uri -%> | Style URI: <%= @theme.style_uri %> <% end -%> <% if @theme.description -%> | Description: <%= @verbose ? @theme.description : @theme.description[0, 100] + '...' %> <% end -%> <% if @theme.author -%> | Author: <%= @theme.author %> <% end -%> <% if @theme.author_uri -%> | Author URI: <%= @theme.author_uri %> <% end -%> <% if @theme.template && @verbose -%> | Template: <%= @theme.template %> <% end -%> <% if @theme.license && @verbose -%> | License: <%= @theme.license %> <% end -%> <% if @theme.license_uri && @verbose -%> | License URI: <%= @theme.license_uri %> <% end -%> <% if @theme.tags && @verbose -%> | Tags: <%= @theme.tags %> <% end -%> <% if @theme.text_domain && @verbose -%> | Text Domain: <%= @theme.text_domain %> <% end -%> | <%= render('@finding', item: @theme) -%> | <% if @theme.version -%> | Version: <%= @theme.version %> (<%= @theme.version.confidence %>% confidence) <%= render('@finding', item: @theme.version) -%> <% else -%> | The version could not be determined. <% end -%> <% if @show_parents && !(parents = @theme.parent_themes).empty? -%> | | Parent Theme(s): <% parents.each do |parent| -%> | <%= render('@theme', theme: parent, show_parents: false) -%> <% end -%> <% end -%>
wpscan/app/views/cli/vulnerability.erb
| <%= critical_icon %> Title: <%= @v.title %> <% if @v.cvss -%> | CVSS: <%= @v.cvss[:score] %> (<%= @v.cvss[:vector] %>) <% end -%> <% if @v.fixed_in -%> | Fixed in: <%= @v.fixed_in %> <% end -%> <% unless (references = @v.references_urls).empty? -%> <% if references.size == 1 -%> | Reference: <%= references.first %> <% else -%> | References: <% references.each do |ref| -%> | - <%= ref %> <% end -%> <% end -%> <% end -%>
wpscan/app/views/cli/wp_item.erb
| Location: <%= @wp_item.url %> <% if @wp_item.latest_version && !@wp_item.outdated? -%> | Latest Version: <%= @wp_item.latest_version %><% if @wp_item.version %> (up to date)<% end %> <% end -%> <% if @wp_item.last_updated -%> | Last Updated: <%= @wp_item.last_updated %> <% end -%> <% if @wp_item.readme_url -%> | Readme: <%= @wp_item.readme_url %> <% end -%> <% if @wp_item.latest_version && @wp_item.outdated? -%> | <%= warning_icon %> The version is out of date, the latest version is <%= @wp_item.latest_version %> <% end -%> <% if @wp_item.directory_listing? -%> | <%= critical_icon %> Directory listing is enabled <% end -%> <% if @wp_item.error_log? -%> | <%= critical_icon %> An error log file has been found: <%= @wp_item.url('error_log') %> <% end -%>
wpscan/app/views/cli/core/banner.erb
_______________________________________________________________ __ _______ _____ \ \ / / __ \ / ____| \ \ /\ / /| |__) | (___ ___ __ _ _ __ ® \ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \ \ /\ / | | ____) | (__| (_| | | | | \/ \/ |_| |_____/ \___|\__,_|_| |_| WordPress Security Scanner by the WPScan Team Version <%= WPScan::VERSION %> <%= ' ' * ((63 - WPScan::DB::Sponsor.text.length)/2) + WPScan::DB::Sponsor.text %> @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart _______________________________________________________________
wpscan/app/views/cli/core/db_update_finished.erb
<% if @verbose && [email protected]? -%> <%= notice_icon %> File(s) Updated: <% @updated.each do |file| -%> | <%= file %> <% end -%> <% end -%> <%= notice_icon %> Update completed.
wpscan/app/views/cli/core/not_fully_configured.erb
<%= critical_icon %> The Website is not fully configured and currently in install mode. Create a new admin user at <%= @url %>
wpscan/app/views/cli/core/version.erb
Current Version: <%= WPScan::VERSION %> <% if @last_update -%> Last DB Update: <%= @last_update.strftime('%Y-%m-%d') %> <% end -%>
wpscan/app/views/cli/enumeration/config_backups.erb
<% if @config_backups.empty? -%> <%= notice_icon %> No Config Backups Found. <% else -%> <%= notice_icon %> Config Backup(s) Identified: <% @config_backups.each do |config_backup| -%> <%= critical_icon %> <%= config_backup %> <%= render('@finding', item: config_backup) -%> <% end -%> <% end %>
wpscan/app/views/cli/enumeration/db_exports.erb
<% if @db_exports.empty? -%> <%= notice_icon %> No DB Exports Found. <% else -%> <%= notice_icon %> Db Export(s) Identified: <% @db_exports.each do |db_export| -%> <%= critical_icon %> <%= db_export %> <%= render('@finding', item: db_export) -%> <% end -%> <% end %>
wpscan/app/views/cli/enumeration/medias.erb
<% if @medias.empty? -%> <%= notice_icon %> No Medias Found. <% else -%> <%= notice_icon %> Medias(s) Identified: <% @medias.each do |media| -%> <%= info_icon %> <%= media %> <%= render('@finding', item: media) -%> <% end -%> <% end %>
wpscan/app/views/cli/enumeration/plugins.erb
<% if @plugins.empty? -%> <%= notice_icon %> No plugins Found. <% else -%> <%= notice_icon %> Plugin(s) Identified: <% @plugins.each do |plugin| -%> <%= info_icon %> <%= plugin %> <%= render('@wp_item', wp_item: plugin) -%> | <%= render('@finding', item: plugin) -%> | <% if plugin.version -%> | Version: <%= plugin.version %> (<%= plugin.version.confidence %>% confidence) <%= render('@finding', item: plugin.version) -%> <% else -%> | The version could not be determined. <% end -%> <% end -%> <% end %>
wpscan/app/views/cli/enumeration/themes.erb
<% if @themes.empty? -%> <%= notice_icon %> No themes Found. <% else -%> <%= notice_icon %> Theme(s) Identified: <% @themes.each do |theme| -%> <%= info_icon %> <%= theme %> <%= render('@theme', theme: theme, show_parents: false) -%> <% end -%> <% end %>
wpscan/app/views/cli/enumeration/timthumbs.erb
<% if @timthumbs.empty? -%> <%= notice_icon %> No Timthumbs Found. <% else -%> <%= notice_icon %> Timthumb(s) Identified: <% @timthumbs.each do |timthumb| -%> <%= info_icon %> <%= timthumb %> <%= render('@finding', item: timthumb) -%> | <% if timthumb.version -%> | Version: <%= timthumb.version %> <%= render('@finding', item: timthumb.version) -%> <% else -%> | The version could not be determined. <% end -%> <% end -%> <% end %>
wpscan/app/views/cli/enumeration/users.erb
<% if @users.empty? -%> <%= notice_icon %> No Users Found. <% else -%> <%= notice_icon %> User(s) Identified: <% @users.each do |user| -%> <%= info_icon %> <%= user %> <%= render('@finding', item: user) -%> <% end -%> <% end %>
wpscan/app/views/cli/main_theme/theme.erb
<% if @theme -%> <%= info_icon %> WordPress theme in use: <%= @theme %> <%= render('@theme', theme: @theme, show_parents: true) -%> <% else -%> <%= notice_icon %> The main theme could not be detected. <% end %>
wpscan/app/views/cli/password_attack/users.erb
<% if @users.empty? -%> <%= notice_icon %> No Valid Passwords Found. <% else -%> <%= critical_icon %> Valid Combinations Found: <% @users.each do |user| -%> | Username: <%= user.username %>, Password: <%= user.password %> <% end -%> <% end %>
wpscan/app/views/cli/vuln_api/status.erb
<% unless @status.empty? -%> <% if @status['http_error'] -%> <%= critical_icon %> WPScan DB API, <%= @status['http_error'].to_s %> <% else -%> <%= info_icon %> WPScan DB API OK | Plan: <%= @status['plan'] %> | Requests Done (during the scan): <%= @api_requests %> | Requests Remaining: <%= @status['requests_remaining'] %> <% end -%> <% else -%> <%= warning_icon %> No WPScan API Token given, as a result vulnerability data has not been output. <%= warning_icon %> You can get a free API token with 25 daily requests by registering at https://wpscan.com/register <% end -%>
wpscan/app/views/cli/wp_version/version.erb
<% if @version -%> <%= info_icon %> WordPress version <%= @version.number %> identified (<%= @version.status.tr('-', '_').humanize %>, released on <%= @version.release_date %>). <%= render('@finding', item: @version) -%> <% else -%> <%= notice_icon %> The WordPress version could not be detected. <% end %>
wpscan/app/views/json/finding.erb
"found_by": <%= @item.found_by.to_json %>, "confidence": <%= @item.confidence.to_json %>, "interesting_entries": <%= @item.interesting_entries.to_json %>, "confirmed_by": { <% unless (confirmed = @item.confirmed_by).empty? -%> <% last_index = @item.confirmed_by.size - 1 -%> <% @item.confirmed_by.each_with_index do |c, index| -%> <%= c.found_by.to_json %>: { "confidence": <%= c.confidence.to_json %>, "interesting_entries": <%= c.interesting_entries.to_json %> }<% unless index == last_index %>,<% end -%> <% end -%> <% end -%> } <% if @item.respond_to?(:vulnerabilities) -%> ,"vulnerabilities": [ <% unless (vulns = @item.vulnerabilities).empty? -%> <% last_index = vulns.size - 1 -%> <% vulns.each_with_index do |v, index| -%> { "title": <%= v.title.to_json %>, <% if v.cvss -%> "cvss": <%= v.cvss.to_json %>, <% end -%> "fixed_in": <%= v.fixed_in.to_json %>, "references": <%= v.references.to_json %> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> ] <% end -%>
wpscan/app/views/json/theme.erb
<%= render('@wp_item', wp_item: @theme) %>, "style_url": <%= @theme.style_url.to_json %>, "style_name": <%= @theme.style_name.to_json %>, "style_uri": <%= @theme.style_uri.to_json %>, "description": <%= @theme.description.to_json %>, "author": <%= @theme.author.to_json %>, "author_uri": <%= @theme.author_uri.to_json %>, "template": <%= @theme.template.to_json %>, "license": <%= @theme.license.to_json %>, "license_uri": <%= @theme.license_uri.to_json %>, "tags": <%= @theme.tags.to_json %>, "text_domain": <%= @theme.text_domain.to_json %>, <%= render('@finding', item: @theme) -%>, <% if @theme.version -%> "version": { "number": <%= @theme.version.number.to_json %>, "confidence": <%= @theme.version.confidence.to_json %>, <%= render('@finding', item: @theme.version) -%> }, <% else -%> "version": null, <% end -%> "parents": [ <% if @show_parents && !(parents = @theme.parent_themes).empty? -%> <% last_index = parents.size - 1 -%> <% parents.each_with_index do |parent, index| -%> { <%= render('@theme', theme: parent, show_parents: false) -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> ]
wpscan/app/views/json/wp_item.erb
"slug": <%= @wp_item.slug.to_json %>, "location": <%= @wp_item.url.to_json %>, "latest_version": <%= @wp_item.latest_version ? @wp_item.latest_version.number.to_json : nil.to_json %>, "last_updated": <%= @wp_item.last_updated.to_json %>, "outdated": <%= @wp_item.outdated?.to_json %>, "readme_url": <%= @wp_item.readme_url.to_json %>, "directory_listing": <%= @wp_item.directory_listing?.to_json %>, "error_log_url": <% if @wp_item.error_log? %><%= @wp_item.url('error_log').to_json %><% else %>null<% end %>
wpscan/app/views/json/core/banner.erb
"banner": { "description": "WordPress Security Scanner by the WPScan Team", "version": <%= WPScan::VERSION.to_json %>, "authors": [ "@_WPScan_", "@ethicalhack3r", "@erwan_lr", "@firefart" ], "sponsor": <%= WPScan::DB::Sponsor.text.to_json %> },
wpscan/app/views/json/core/not_fully_configured.erb
"not_fully_configured": "The Website is not fully configured and currently in install mode. Create a new admin user at <%= @url %>",
wpscan/app/views/json/enumeration/config_backups.erb
"config_backups": { <% unless @config_backups.empty? -%> <% last_index = @config_backups.size - 1 -%> <% @config_backups.each_with_index do |config_backup, index| -%> <%= config_backup.url.to_json %>: { <%= render('@finding', item: config_backup) -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/enumeration/db_exports.erb
"db_exports": { <% unless @db_exports.empty? -%> <% last_index = @db_exports.size - 1 -%> <% @db_exports.each_with_index do |db_export, index| -%> <%= db_export.url.to_json %>: { <%= render('@finding', item: db_export) -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/enumeration/medias.erb
"medias": { <% unless @medias.empty? -%> <% last_index = @medias.size - 1 -%> <% @medias.each_with_index do |media, index| -%> <%= media.url.to_json %>: { <%= render('@finding', item: media) -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/enumeration/plugins.erb
"plugins": { <% unless @plugins.empty? -%> <% last_index = @plugins.size - 1 -%> <% @plugins.each_with_index do |plugin, index| -%> <%= plugin.slug.to_json %>: { <%= render('@wp_item', wp_item: plugin) %>, <%= render('@finding', item: plugin) -%>, <% if plugin.version -%> "version": { "number": <%= plugin.version.number.to_json %>, "confidence": <%= plugin.version.confidence.to_json %>, <%= render('@finding', item: plugin.version) -%> } <% else -%> "version": null <% end -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/enumeration/themes.erb
"themes": { <% unless @themes.empty? -%> <% last_index = @themes.size - 1 -%> <% @themes.each_with_index do |theme, index| -%> <%= theme.slug.to_json %>: { <%= render('@theme', theme: theme) -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/enumeration/timthumbs.erb
"timthumbs": { <% unless @timthumbs.empty? -%> <% last_index = @timthumbs.size - 1 -%> <% @timthumbs.each_with_index do |timthumb, index| -%> <%= timthumb.url.to_json %>: { <%= render('@finding', item: timthumb) -%>, <% if timthumb.version -%> "version": { "number": <%= timthumb.version.number.to_json %>, "confidence": <%= timthumb.version.confidence.to_json %>, <%= render('@finding', item: timthumb.version) -%> } <% else -%> "version": null <% end -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/enumeration/users.erb
"users": { <% unless @users.empty? -%> <% last_index = @users.size - 1 -%> <% @users.each_with_index do |user, index| -%> <%= user.username.to_json %>: { "id": <%= user.id.to_json %>, <%= render('@finding', item: user) -%> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/main_theme/theme.erb
<% if @theme -%> "main_theme": { <%= render('@theme', theme: @theme, show_parents: true) %> }, <% else -%> "main_theme": null, <% end -%>
wpscan/app/views/json/password_attack/users.erb
"password_attack": { <% unless @users.empty? -%> <% last_index = @users.size - 1 -%> <% @users.each_with_index do |user, index| -%> <%= user.username.to_json %>: { "password": <%= user.password.to_json %> }<% unless index == last_index -%>,<% end -%> <% end -%> <% end -%> },
wpscan/app/views/json/vuln_api/status.erb
"vuln_api": { <% unless @status.empty? -%> <% if @status['http_error'] -%> "http_error": <%= @status['http_error'].to_s.to_json %> <% else -%> "plan": <%= @status['plan'].to_json %>, "requests_done_during_scan": <%= @api_requests.to_json %>, "requests_remaining": <%= @status['requests_remaining'].to_json %> <% end -%> <% else -%> "error": "No WPScan API Token given, as a result vulnerability data has not been output.\nYou can get a free API token with 25 daily requests by registering at https://wpscan.com/register" <% end -%> },
wpscan/app/views/json/wp_version/version.erb
<% if @version -%> "version": { "number": <%= @version.number.to_json %>, "release_date": <%= @version.release_date.to_json %>, "status": <%= @version.status.to_json %>, <%= render('@finding', item: @version) -%> }, <% else -%> "version": null, <% end -%>
wpscan/bin/wpscan
#!/usr/bin/env ruby # frozen_string_literal: true require 'wpscan' WPScan::Scan.new do |s| s.controllers << WPScan::Controller::VulnApi.new << WPScan::Controller::CustomDirectories.new << WPScan::Controller::InterestingFindings.new << WPScan::Controller::WpVersion.new << WPScan::Controller::MainTheme.new << WPScan::Controller::Enumeration.new << WPScan::Controller::PasswordAttack.new << WPScan::Controller::Aliases.new s.run end
wpscan/bin/wpscan-docker
#!/bin/bash SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" SOURCE="$(readlink "$SOURCE")" [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" cd $DIR/../ docker build -q -t wpscan:git . docker run -it --rm wpscan:git "$@"
wpscan/bin/wpscan-docker-dev
#!/bin/bash SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" SOURCE="$(readlink "$SOURCE")" [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" cd $DIR/../ if [[ -n "$WPSCAN_BUILD" ]]; then docker build -q -t wpscan:git . fi docker run -it --rm -v $DIR/../:/wpscan wpscan:git "$@"
wpscan/bin/wpscan-memprof
#!/usr/bin/env ruby # frozen_string_literal: true require 'memory_profiler' # https://github.com/SamSaffron/memory_profiler require 'wpscan' report = MemoryProfiler.report(top: 15) do WPScan::Scan.new do |s| s.controllers << WPScan::Controller::VulnApi.new << WPScan::Controller::CustomDirectories.new << WPScan::Controller::InterestingFindings.new << WPScan::Controller::WpVersion.new << WPScan::Controller::MainTheme.new << WPScan::Controller::Enumeration.new << WPScan::Controller::PasswordAttack.new << WPScan::Controller::Aliases.new s.run end end report.pretty_print(scale_bytes: true, to_file: 'memprof.report')
wpscan/bin/wpscan-stackprof
#!/usr/bin/env ruby # frozen_string_literal: true require 'stackprof' # https://github.com/tmm1/stackprof require 'wpscan' # The object mode produces a segfault currently: https://github.com/jfelchner/ruby-progressbar/issues/153 # StackProf.run(mode: :object, out: '/tmp/stackprof-object.dump') do # StackProf.run(mode: :wall, out: '/tmp/stackprof-wall.dump') do StackProf.run(mode: :cpu, out: '/tmp/stackprof-cpu.dump', interval: 500) do # Couldn't we just load the ./wpscan here ? # require_relative 'wpscan' doesn't work WPScan::Scan.new do |s| s.controllers << WPScan::Controller::VulnApi.new << WPScan::Controller::CustomDirectories.new << WPScan::Controller::InterestingFindings.new << WPScan::Controller::WpVersion.new << WPScan::Controller::MainTheme.new << WPScan::Controller::Enumeration.new << WPScan::Controller::PasswordAttack.new << WPScan::Controller::Aliases.new s.run end end
Ruby
wpscan/lib/wpscan.rb
# frozen_string_literal: true # Gems # Believe it or not, active_support MUST be the first one, # otherwise encoding issues can happen when using JSON format. # Not kidding. require 'active_support/all' require 'cms_scanner' require 'yajl/json_gem' require 'addressable/uri' # Standard Lib require 'uri' require 'time' require 'readline' require 'securerandom' require 'resolv' # Monkey Patches/Fixes/Override require 'wpscan/typhoeus/response' # Adds a from_vuln_api? method # Custom Libs require 'wpscan/helper' require 'wpscan/db' require 'wpscan/version' require 'wpscan/errors' require 'wpscan/parsed_cli' require 'wpscan/browser' require 'wpscan/target' require 'wpscan/finders' require 'wpscan/controller' require 'wpscan/controllers' require 'wpscan/references' require 'wpscan/vulnerable' require 'wpscan/vulnerability' Encoding.default_external = Encoding::UTF_8 # WPScan module WPScan include CMSScanner APP_DIR = Pathname.new(__FILE__).dirname.join('..', 'app').expand_path DB_DIR = Pathname.new(Dir.home).join('.wpscan', 'db') Typhoeus.on_complete do |response| next if response.cached? || !response.from_vuln_api? self.api_requests += 1 end # Override, otherwise it would be returned as 'wp_scan' # # @return [ String ] def self.app_name 'wpscan' end # @return [ Integer ] def self.api_requests @@api_requests ||= 0 end # @param [ Integer ] value def self.api_requests=(value) @@api_requests = value end end require "#{WPScan::APP_DIR}/app"
Ruby
wpscan/lib/wpscan/browser.rb
# frozen_string_literal: true module WPScan # Custom Browser class Browser < CMSScanner::Browser extend Actions # @return [ String ] def default_user_agent @default_user_agent ||= "WPScan v#{VERSION} (https://wpscan.com/wordpress-security-scanner)" end end end
Ruby
wpscan/lib/wpscan/controller.rb
# frozen_string_literal: true module WPScan # Needed to load at least the Core controller # Otherwise, the following error will be raised: # `initialize': uninitialized constant WPScan::Controller::Core (NameError) module Controller include CMSScanner::Controller end end
Ruby
wpscan/lib/wpscan/controllers.rb
# frozen_string_literal: true module WPScan # Override to set the OptParser's summary width to 45 (instead of 40 from the CMSScanner) class Controllers < CMSScanner::Controllers def initialize(option_parser = OptParseValidator::OptParser.new(nil, 45)) super(option_parser) end end end
Ruby
wpscan/lib/wpscan/db.rb
# frozen_string_literal: true require_relative 'db/wp_item' require_relative 'db/updater' require_relative 'db/wp_items' require_relative 'db/plugins' require_relative 'db/themes' require_relative 'db/plugin' require_relative 'db/theme' require_relative 'db/sponsor' require_relative 'db/wp_version' require_relative 'db/fingerprints' require_relative 'db/vuln_api' require_relative 'db/dynamic_finders/base' require_relative 'db/dynamic_finders/plugin' require_relative 'db/dynamic_finders/theme' require_relative 'db/dynamic_finders/wordpress'
Ruby
wpscan/lib/wpscan/errors.rb
# frozen_string_literal: true module WPScan module Error include CMSScanner::Error class Standard < StandardError end end end require_relative 'errors/enumeration' require_relative 'errors/http' require_relative 'errors/update' require_relative 'errors/vuln_api' require_relative 'errors/wordpress' require_relative 'errors/xmlrpc'
Ruby
wpscan/lib/wpscan/finders.rb
# frozen_string_literal: true require 'wpscan/finders/finder/wp_version/smart_url_checker' require 'wpscan/finders/dynamic_finder/finder' require 'wpscan/finders/dynamic_finder/wp_items/finder' require 'wpscan/finders/dynamic_finder/version/finder' require 'wpscan/finders/dynamic_finder/version/xpath' require 'wpscan/finders/dynamic_finder/version/comment' require 'wpscan/finders/dynamic_finder/version/header_pattern' require 'wpscan/finders/dynamic_finder/version/body_pattern' require 'wpscan/finders/dynamic_finder/version/javascript_var' require 'wpscan/finders/dynamic_finder/version/query_parameter' require 'wpscan/finders/dynamic_finder/version/config_parser' require 'wpscan/finders/dynamic_finder/wp_item_version' require 'wpscan/finders/dynamic_finder/wp_version' module WPScan # Custom Finders module Finders include CMSScanner::Finders # Custom InterestingFindings module InterestingFindings include CMSScanner::Finders::InterestingFindings end end end
Ruby
wpscan/lib/wpscan/helper.rb
# frozen_string_literal: true def read_json_file(file) JSON.parse(File.read(file)) rescue StandardError => e raise "JSON parsing error in #{file} #{e}" end # Sanitize and classify a slug # @note As a class can not start with a digit or underscore, a D_ is # put as a prefix in such case. Ugly but well :x # Not only used to classify slugs though, but Dynamic Finder names as well # # @return [ Symbol ] def classify_slug(slug) classified = slug.to_s.gsub(/[^a-z\d\-]/i, '-').gsub(/-{1,}/, '_').camelize.to_s classified = "D_#{classified}" if /\d/.match?(classified[0]) classified.to_sym end
Ruby
wpscan/lib/wpscan/parsed_cli.rb
# frozen_string_literal: true module WPScan # To be able to use ParsedCli directly, rather than having to access it via WPscan::ParsedCli class ParsedCli < CMSScanner::ParsedCli end end
Ruby
wpscan/lib/wpscan/references.rb
# frozen_string_literal: true module WPScan # References module (which should be included along with the CMSScanner::References) # to allow the use of the wpvulndb reference. module References extend ActiveSupport::Concern # See ActiveSupport::Concern module ClassMethods # @return [ Array<Symbol> ] def references_keys @references_keys ||= super << :wpvulndb end end def references_urls wpvulndb_urls + super end def wpvulndb_ids references[:wpvulndb] || [] end def wpvulndb_urls wpvulndb_ids.reduce([]) { |acc, elem| acc << wpvulndb_url(elem) } end def wpvulndb_url(id) "https://wpscan.com/vulnerability/#{id}" end end end
Ruby
wpscan/lib/wpscan/target.rb
# frozen_string_literal: true require 'wpscan/target/platform/wordpress' module WPScan # Includes the WordPress Platform class Target < CMSScanner::Target include Platform::WordPress # @return [ Hash ] def head_or_get_request_params @head_or_get_request_params ||= if Browser.head(url).code == 405 { method: :get, maxfilesize: 1 } else { method: :head } end end # @return [ Boolean ] def vulnerable? [@wp_version, @main_theme, @plugins, @themes, @timthumbs].each do |e| Array(e).each { |ae| return true if ae && ae.vulnerable? } # rubocop:disable Style/SafeNavigation end return true unless Array(@config_backups).empty? return true unless Array(@db_exports).empty? Array(@users).each { |u| return true if u.password } false end # @return [ XMLRPC, nil ] def xmlrpc @xmlrpc ||= interesting_findings&.select { |f| f.is_a?(Model::XMLRPC) }&.first end # @param [ Hash ] opts # # @return [ WpVersion, false ] The WpVersion found or false if not detected def wp_version(opts = {}) @wp_version = Finders::WpVersion::Base.find(self, opts) if @wp_version.nil? @wp_version end # @param [ Hash ] opts # # @return [ Theme ] def main_theme(opts = {}) @main_theme = Finders::MainTheme::Base.find(self, opts) if @main_theme.nil? @main_theme end # @param [ Hash ] opts # # @return [ Array<Plugin> ] def plugins(opts = {}) @plugins ||= Finders::Plugins::Base.find(self, opts) end # @param [ Hash ] opts # # @return [ Array<Theme> ] def themes(opts = {}) @themes ||= Finders::Themes::Base.find(self, opts) end # @param [ Hash ] opts # # @return [ Array<Timthumb> ] def timthumbs(opts = {}) @timthumbs ||= Finders::Timthumbs::Base.find(self, opts) end # @param [ Hash ] opts # # @return [ Array<ConfigBackup> ] def config_backups(opts = {}) @config_backups ||= Finders::ConfigBackups::Base.find(self, opts) end # @param [ Hash ] opts # # @return [ Array<DBExport> ] def db_exports(opts = {}) @db_exports ||= Finders::DbExports::Base.find(self, opts) end # @param [ Hash ] opts # # @return [ Array<Media> ] def medias(opts = {}) @medias ||= Finders::Medias::Base.find(self, opts) end # @param [ Hash ] opts # # @return [ Array<User> ] def users(opts = {}) @users ||= Finders::Users::Base.find(self, opts) end end end
Ruby
wpscan/lib/wpscan/vulnerability.rb
# frozen_string_literal: true module WPScan # Specific implementation class Vulnerability < CMSScanner::Vulnerability include References # @param [ Hash ] json_data # @return [ Vulnerability ] def self.load_from_json(json_data) references = { wpvulndb: json_data['id'].to_s } if json_data['references'] references_keys.each do |key| references[key] = json_data['references'][key.to_s] if json_data['references'].key?(key.to_s) end end new( json_data['title'], references: references, type: json_data['vuln_type'], fixed_in: json_data['fixed_in'], introduced_in: json_data['introduced_in'], cvss: json_data['cvss']&.symbolize_keys ) end end end
Ruby
wpscan/lib/wpscan/vulnerable.rb
# frozen_string_literal: true module WPScan # Module to include in vulnerable WP item such as WpVersion. # the vulnerabilities method should be implemented module Vulnerable # @return [ Boolean ] def vulnerable? !vulnerabilities.empty? end end end