From b909856933b20cd795ef63ad2220dfc9e47195ae Mon Sep 17 00:00:00 2001 From: erwanlr Date: Mon, 8 Jun 2020 20:13:18 +0200 Subject: [PATCH] Fixes #1504 --- app/finders/db_exports/known_locations.rb | 2 +- .../finders/db_exports/known_locations_spec.rb | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/finders/db_exports/known_locations.rb b/app/finders/db_exports/known_locations.rb index ff068577..e4157f04 100644 --- a/app/finders/db_exports/known_locations.rb +++ b/app/finders/db_exports/known_locations.rb @@ -40,7 +40,7 @@ module WPScan # @return [ Hash ] def potential_urls(opts = {}) urls = {} - domain_name = PublicSuffix.domain(target.uri.host)[/(^[\w|-]+)/, 1] + domain_name = (PublicSuffix.domain(target.uri.host) || target.uri.host)[/(^[\w|-]+)/, 1] File.open(opts[:list]).each_with_index do |path, index| path.gsub!('{domain_name}', domain_name) diff --git a/spec/app/finders/db_exports/known_locations_spec.rb b/spec/app/finders/db_exports/known_locations_spec.rb index d11272c0..9d16b759 100644 --- a/spec/app/finders/db_exports/known_locations_spec.rb +++ b/spec/app/finders/db_exports/known_locations_spec.rb @@ -12,7 +12,7 @@ describe WPScan::Finders::DbExports::KnownLocations do allow(target).to receive(:sub_dir).and_return(false) end - it 'replace {domain_name} by its value' do + it 'replaces {domain_name} by its value' do expect(finder.potential_urls(opts).keys).to eql %w[ http://ex.lo/aa/ex.sql http://ex.lo/aa/wordpress.sql @@ -27,7 +27,7 @@ describe WPScan::Finders::DbExports::KnownLocations do context "when #{sub_domain} sub-domain" do let(:url) { "https://#{sub_domain}.domain.tld" } - it 'replace {domain_name} by its correct value' do + it 'replaces {domain_name} by its correct value' do expect(finder.potential_urls(opts).keys).to include "#{url}/domain.sql" end end @@ -36,7 +36,7 @@ describe WPScan::Finders::DbExports::KnownLocations do context 'when multi-level tlds' do let(:url) { 'https://something.com.tr' } - it 'replace {domain_name} by its correct value' do + 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 @@ -44,7 +44,7 @@ describe WPScan::Finders::DbExports::KnownLocations do context 'when multi-level tlds and sub-domain' do let(:url) { 'https://dev.something.com.tr' } - it 'replace {domain_name} by its correct value' do + it 'replaces {domain_name} by its correct value' do expect(finder.potential_urls(opts).keys).to include 'https://dev.something.com.tr/something.sql' end end @@ -52,10 +52,18 @@ describe WPScan::Finders::DbExports::KnownLocations do context 'when some weird stuff' do let(:url) { 'https://098f6bcd4621d373cade4e832627b4f6.aa-bb-ccc-dd.domain-test.com' } - it 'replace {domain_name} by its correct value' do + it 'replaces {domain_name} by its correct value' do expect(finder.potential_urls(opts).keys).to include "#{url}/domain-test.sql" end end + + context 'when a non standard URL host' 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 end describe '#aggressive' do