diff --git a/app/controllers/core.rb b/app/controllers/core.rb index d2c6ab79..2af48df9 100644 --- a/app/controllers/core.rb +++ b/app/controllers/core.rb @@ -71,7 +71,7 @@ module WPScan exit(WPScan::ExitCode::VULNERABLE) end - raise NotWordPressError unless target.wordpress? || parsed_options[:force] + raise NotWordPressError unless target.wordpress?(parsed_options[:detection_mode]) || parsed_options[:force] end # Loads the related server module in the target diff --git a/lib/wpscan/target/platform/wordpress.rb b/lib/wpscan/target/platform/wordpress.rb index 9c86613c..033cb54f 100644 --- a/lib/wpscan/target/platform/wordpress.rb +++ b/lib/wpscan/target/platform/wordpress.rb @@ -18,10 +18,10 @@ module WPScan alias registration_enabled? registration_enabled alias mu_plugins? mu_plugins + # @param [ Symbol ] detection_mode + # # @return [ Boolean ] - def wordpress? - # res = Browser.get(url) - + def wordpress?(detection_mode) in_scope_urls(homepage_res) do |url| return true if Addressable::URI.parse(url).path.match(WORDPRESS_PATTERN) end @@ -32,6 +32,14 @@ module WPScan return true unless comments_from_page(/wordpress/i, homepage_res).empty? + if %i[mixed aggressive].include?(detection_mode) + %w[wp-admin/install.php wp-login.php].each do |path| + in_scope_urls(Browser.get_and_follow_location(url(path))).each do |url| + return true if Addressable::URI.parse(url).path.match(WORDPRESS_PATTERN) + end + end + end + false end diff --git a/spec/app/controllers/core_spec.rb b/spec/app/controllers/core_spec.rb index 27e19ac2..01d517f8 100644 --- a/spec/app/controllers/core_spec.rb +++ b/spec/app/controllers/core_spec.rb @@ -165,7 +165,7 @@ describe WPScan::Controller::Core do before do expect(core).to receive(:load_server_module) - expect(core.target).to receive(:wordpress?).and_return(true) + expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true) end it 'calls the formatter when started and finished to update the db' do @@ -208,7 +208,7 @@ describe WPScan::Controller::Core do context 'when wordpress' do it 'does not raise an error' do - expect(core.target).to receive(:wordpress?).and_return(true) + expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true) expect { core.before_scan }.to_not raise_error end @@ -216,7 +216,7 @@ describe WPScan::Controller::Core do context 'when not wordpress' do it 'raises an error' do - expect(core.target).to receive(:wordpress?).and_return(false) + expect(core.target).to receive(:wordpress?).with(:mixed).and_return(false) expect { core.before_scan }.to raise_error(WPScan::NotWordPressError) end @@ -237,7 +237,7 @@ describe WPScan::Controller::Core do context 'when wordpress' do before do expect(core).to receive(:load_server_module) - expect(core.target).to receive(:wordpress?).and_return(true) + expect(core.target).to receive(:wordpress?).with(:mixed).and_return(true) end it 'does not raise any error' do @@ -248,7 +248,7 @@ describe WPScan::Controller::Core do context 'when not wordpress' do before do expect(core).to receive(:load_server_module) - expect(core.target).to receive(:wordpress?).and_return(false) + expect(core.target).to receive(:wordpress?).with(:mixed).and_return(false) end context 'when no --force' do diff --git a/spec/fixtures/target/platform/wordpress/detection/wp-admin-install.php b/spec/fixtures/target/platform/wordpress/detection/wp-admin-install.php new file mode 100644 index 00000000..9ea119b5 --- /dev/null +++ b/spec/fixtures/target/platform/wordpress/detection/wp-admin-install.php @@ -0,0 +1,15 @@ + + +
+ + + +You appear to have already installed WordPress. To reinstall please clear your old database tables first.
diff --git a/spec/fixtures/target/platform/wordpress/detection/wp-login.php b/spec/fixtures/target/platform/wordpress/detection/wp-login.php new file mode 100644 index 00000000..9affc3ca --- /dev/null +++ b/spec/fixtures/target/platform/wordpress/detection/wp-login.php @@ -0,0 +1,68 @@ + + + + + + + +