Path: blob/master/app/finders/db_exports/known_locations.rb
485 views
# frozen_string_literal: true12module WPScan3module Finders4module DbExports5# DB Exports finder6class KnownLocations < CMSScanner::Finders::Finder7include CMSScanner::Finders::Finder::Enumerator89def valid_response_codes10@valid_response_codes ||= [200, 206].freeze11end1213SQL_PATTERN = /(?:DROP|(?:UN)?LOCK|CREATE|ALTER) (?:TABLE|DATABASE)|INSERT INTO/.freeze1415# @param [ Hash ] opts16# @option opts [ String ] :list17# @option opts [ Boolean ] :show_progression18#19# @return [ Array<DBExport> ]20def aggressive(opts = {})21found = []2223enumerate(potential_urls(opts), opts.merge(check_full_response: valid_response_codes)) do |res|24if res.effective_url.end_with?('.zip')25next unless %r{\Aapplication/zip}i.match?(res.headers['Content-Type'])26else27next unless SQL_PATTERN.match?(res.body)28end2930found << Model::DbExport.new(res.request.url, found_by: DIRECT_ACCESS, confidence: 100)31end3233found34end3536def full_request_params37@full_request_params ||= { headers: { 'Range' => 'bytes=0-3000' } }38end3940# @param [ Hash ] opts41# @option opts [ String ] :list Mandatory42#43# @return [ Hash ]44def potential_urls(opts = {})45urls = {}46index = 04748File.open(opts[:list]).each do |path|49path.chomp!5051if path.include?('{domain_name}')52urls[target.url(path.gsub('{domain_name}', domain_name))] = index5354if domain_name != domain_name_with_sub55urls[target.url(path.gsub('{domain_name}', domain_name_with_sub))] = index + 15657index += 158end59else60urls[target.url(path)] = index61end6263index += 164end6566urls67end6869def domain_name70@domain_name ||= if Resolv::AddressRegex.match?(target.uri.host)71target.uri.host72else73(PublicSuffix.domain(target.uri.host) || target.uri.host)[/(^[\w|-]+)/, 1]74end75end7677def domain_name_with_sub78@domain_name_with_sub ||=79if Resolv::AddressRegex.match?(target.uri.host)80target.uri.host81else82parsed = PublicSuffix.parse(target.uri.host)8384if parsed.subdomain85parsed.subdomain.gsub(".#{parsed.tld}", '')86elsif parsed.domain87parsed.domain.gsub(".#{parsed.tld}", '')88else89target.uri.host90end91end92rescue PublicSuffix::DomainNotAllowed93@domain_name_with_sub = target.uri.host94end9596def create_progress_bar(opts = {})97super(opts.merge(title: ' Checking DB Exports -'))98end99end100end101end102end103104105