WebSite module reworked
This commit is contained in:
@@ -18,9 +18,18 @@
|
|||||||
|
|
||||||
module WebSite
|
module WebSite
|
||||||
|
|
||||||
|
# Checks if the remote website is up.
|
||||||
|
def online?
|
||||||
|
Browser.instance.get(@uri.to_s).code != 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_basic_auth?
|
||||||
|
Browser.instance.get(@uri.to_s).code == 401
|
||||||
|
end
|
||||||
|
|
||||||
# check if the remote website is
|
# check if the remote website is
|
||||||
# actually running wordpress.
|
# actually running wordpress.
|
||||||
def is_wordpress?
|
def wordpress?
|
||||||
wordpress = false
|
wordpress = false
|
||||||
|
|
||||||
response = Browser.instance.get(
|
response = Browser.instance.get(
|
||||||
@@ -32,8 +41,8 @@ module WebSite
|
|||||||
wordpress = true
|
wordpress = true
|
||||||
else
|
else
|
||||||
response = Browser.instance.get(
|
response = Browser.instance.get(
|
||||||
xml_rpc_url,
|
xml_rpc_url,
|
||||||
{:follow_location => true, :max_redirects => 2}
|
{:follow_location => true, :max_redirects => 2}
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.body =~ %r{XML-RPC server accepts POST requests only}i
|
if response.body =~ %r{XML-RPC server accepts POST requests only}i
|
||||||
@@ -44,6 +53,10 @@ module WebSite
|
|||||||
wordpress
|
wordpress
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_xml_rpc?
|
||||||
|
!xml_rpc_url.nil?
|
||||||
|
end
|
||||||
|
|
||||||
def xml_rpc_url
|
def xml_rpc_url
|
||||||
unless @xmlrpc_url
|
unless @xmlrpc_url
|
||||||
headers = Browser.instance.get(@uri.to_s).headers_hash
|
headers = Browser.instance.get(@uri.to_s).headers_hash
|
||||||
@@ -57,19 +70,6 @@ module WebSite
|
|||||||
@xmlrpc_url
|
@xmlrpc_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_xml_rpc?
|
|
||||||
!xml_rpc_url.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
# Checks if the remote website is up.
|
|
||||||
def is_online?
|
|
||||||
Browser.instance.get(@uri.to_s).code != 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_basic_auth?
|
|
||||||
Browser.instance.get(@uri.to_s).code == 401
|
|
||||||
end
|
|
||||||
|
|
||||||
# see if the remote url returns 30x redirect
|
# see if the remote url returns 30x redirect
|
||||||
# return a string with the redirection or nil
|
# return a string with the redirection or nil
|
||||||
def redirection(url = nil)
|
def redirection(url = nil)
|
||||||
|
|||||||
@@ -18,111 +18,104 @@
|
|||||||
|
|
||||||
shared_examples_for "WebSite" do
|
shared_examples_for "WebSite" do
|
||||||
let(:fixtures_dir) { SPEC_FIXTURES_WPSCAN_MODULES_DIR + "/web_site" }
|
let(:fixtures_dir) { SPEC_FIXTURES_WPSCAN_MODULES_DIR + "/web_site" }
|
||||||
|
subject(:web_site) { WpScanModuleSpec.new("http://example.localhost/").extend(WebSite) }
|
||||||
|
|
||||||
before :each do
|
describe "#online?" do
|
||||||
@module = WpScanModuleSpec.new("http://example.localhost/")
|
it "should not be considered online if the status code is 0" do
|
||||||
@module.extend(WebSite)
|
stub_request(:get, web_site.url).to_return(:status => 0)
|
||||||
|
web_site.should_not be_online
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be considered online if the status code is != 0" do
|
||||||
|
stub_request(:get, web_site.url).to_return(:status => 200)
|
||||||
|
web_site.should be_online
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#login_url" do
|
describe "#has_basic_auth?" do
|
||||||
it "should return the correct url : http://example.localhost/wp-login.php" do
|
it "should detect that the wpsite is basic auth protected" do
|
||||||
@module.login_url.should === "http://example.localhost/wp-login.php"
|
stub_request(:get, web_site.url).to_return(:status => 401)
|
||||||
|
web_site.should have_basic_auth
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not have a basic auth for a 200" do
|
||||||
|
stub_request(:get, web_site.url).to_return(:status => 200)
|
||||||
|
web_site.should_not have_basic_auth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#xml_rpc_url" do
|
describe "#xml_rpc_url" do
|
||||||
it "should return the correct url : http://example.localhost/xmlrpc.php" do
|
it "should return the correct url : http://example.localhost/xmlrpc.php" do
|
||||||
xmlrpc = "http://example.localhost/xmlrpc.php"
|
xmlrpc = "http://example.localhost/xmlrpc.php"
|
||||||
stub_request(:get, "http://example.localhost/").
|
stub_request(:get, web_site.url).
|
||||||
to_return(:status => 200, :body => "", :headers => { "X-Pingback" => xmlrpc})
|
to_return(:status => 200, :body => "", :headers => { "X-Pingback" => xmlrpc})
|
||||||
@module.xml_rpc_url.should === xmlrpc
|
|
||||||
|
web_site.xml_rpc_url.should === xmlrpc
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return nil" do
|
it "should return nil" do
|
||||||
stub_request(:get, "http://example.localhost/").to_return(:status => 200)
|
stub_request(:get, web_site.url).to_return(:status => 200)
|
||||||
@module.xml_rpc_url.should be_nil
|
web_site.xml_rpc_url.should be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#has_xml_rpc?" do
|
describe "#has_xml_rpc?" do
|
||||||
it "should return true" do
|
it "should return true" do
|
||||||
stub_request(:get, "http://example.localhost/").
|
stub_request(:get, web_site.url).
|
||||||
to_return(:status => 200, :body => "", :headers => { "X-Pingback" => "xmlrpc"})
|
to_return(:status => 200, :body => "", :headers => { "X-Pingback" => "xmlrpc"})
|
||||||
@module.has_xml_rpc?.should be_true
|
|
||||||
|
web_site.should have_xml_rpc
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false" do
|
it "should return false" do
|
||||||
stub_request(:get, "http://example.localhost/").to_return(:status => 200)
|
stub_request(:get, web_site.url).to_return(:status => 200)
|
||||||
@module.has_xml_rpc?.should be_false
|
web_site.should_not have_xml_rpc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#is_wordpress?" do
|
describe "#wordpress?" do
|
||||||
# each url (wp-login and xmlrpc) pointed to a 404
|
# each url (wp-login and xmlrpc) pointed to a 404
|
||||||
before :each do
|
before :each do
|
||||||
stub_request(:get, @module.uri.to_s).
|
stub_request(:get, web_site.url).
|
||||||
to_return(:status => 200, :body => "", :headers => { "X-Pingback" => @module.uri.merge("xmlrpc.php")})
|
to_return(:status => 200, :body => "", :headers => { "X-Pingback" => web_site.uri.merge("xmlrpc.php")})
|
||||||
[@module.login_url, @module.xml_rpc_url].each do |url|
|
|
||||||
|
[web_site.login_url, web_site.xml_rpc_url].each do |url|
|
||||||
stub_request(:get, url).to_return(:status => 404, :body => "")
|
stub_request(:get, url).to_return(:status => 404, :body => "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false if both files are not found (404)" do
|
it "should return false if both files are not found (404)" do
|
||||||
@module.is_wordpress?.should be_false
|
web_site.should_not be_wordpress
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return true if the wp-login is found and is a valid wordpress one" do
|
it "should return true if the wp-login is found and is a valid wordpress one" do
|
||||||
stub_request(:get, @module.login_url).
|
stub_request(:get, web_site.login_url).
|
||||||
to_return(:status => 200, :body => File.new(fixtures_dir + "/wp-login.php"))
|
to_return(:status => 200, :body => File.new(fixtures_dir + "/wp-login.php"))
|
||||||
|
|
||||||
@module.is_wordpress?.should be_true
|
web_site.should be_wordpress
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return true if the xmlrpc is found" do
|
it "should return true if the xmlrpc is found" do
|
||||||
stub_request(:get, @module.xml_rpc_url).
|
stub_request(:get, web_site.xml_rpc_url).
|
||||||
to_return(:status => 200, :body => File.new(fixtures_dir + "/xmlrpc.php"))
|
to_return(:status => 200, :body => File.new(fixtures_dir + "/xmlrpc.php"))
|
||||||
|
|
||||||
@module.is_wordpress?.should be_true
|
web_site.should be_wordpress
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#is_online?" do
|
|
||||||
it "should return false" do
|
|
||||||
stub_request(:get, @module.url).to_return(:status => 0)
|
|
||||||
@module.is_online?.should be_false
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return true" do
|
|
||||||
stub_request(:get, @module.url).to_return(:status => 200)
|
|
||||||
@module.is_online?.should be_true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#has_basic_auth?" do
|
|
||||||
it "should detect that the wpsite is basic auth protected" do
|
|
||||||
stub_request(:get, "http://example.localhost/").to_return(:status => 401)
|
|
||||||
@module.should have_basic_auth
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should not have a basic auth for a 200" do
|
|
||||||
stub_request(:get, "http://example.localhost/").to_return(:status => 200)
|
|
||||||
@module.should_not have_basic_auth
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#redirection" do
|
describe "#redirection" do
|
||||||
it "should return nil if no redirection detected" do
|
it "should return nil if no redirection detected" do
|
||||||
stub_request(:get, @module.url).to_return(:status => 200, :body => '')
|
stub_request(:get, web_site.url).to_return(:status => 200, :body => "")
|
||||||
|
|
||||||
@module.redirection.should be_nil
|
web_site.redirection.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
[301, 302].each do |status_code|
|
[301, 302].each do |status_code|
|
||||||
it "should return http://new-location.com if the status code is #{status_code}" do
|
it "should return http://new-location.com if the status code is #{status_code}" do
|
||||||
stub_request(:get, @module.url).
|
stub_request(:get, web_site.url).
|
||||||
to_return(:status => status_code, :headers => {:location => "http://new-location.com"})
|
to_return(:status => status_code, :headers => {:location => "http://new-location.com"})
|
||||||
|
|
||||||
@module.redirection.should === "http://new-location.com"
|
web_site.redirection.should === "http://new-location.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,23 +20,23 @@ require 'spec_helper'
|
|||||||
|
|
||||||
require WPSCAN_LIB_DIR + '/wpscan_helper'
|
require WPSCAN_LIB_DIR + '/wpscan_helper'
|
||||||
|
|
||||||
SPEC_FIXTURES_WPSCAN_DIR = SPEC_FIXTURES_DIR + '/wpscan'
|
SPEC_FIXTURES_WPSCAN_DIR = SPEC_FIXTURES_DIR + '/wpscan'
|
||||||
SPEC_FIXTURES_WPSCAN_MODULES_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/modules'
|
SPEC_FIXTURES_WPSCAN_MODULES_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/modules'
|
||||||
SPEC_FIXTURES_WPSCAN_WP_TARGET_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_target'
|
SPEC_FIXTURES_WPSCAN_WP_TARGET_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_target'
|
||||||
SPEC_FIXTURES_WPSCAN_WPSCAN_OPTIONS_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wpscan_options'
|
SPEC_FIXTURES_WPSCAN_WPSCAN_OPTIONS_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wpscan_options'
|
||||||
SPEC_FIXTURES_WPSCAN_WP_THEME_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_theme'
|
SPEC_FIXTURES_WPSCAN_WP_THEME_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_theme'
|
||||||
SPEC_FIXTURES_WPSCAN_WP_PLUGIN_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_plugin'
|
SPEC_FIXTURES_WPSCAN_WP_PLUGIN_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_plugin'
|
||||||
SPEC_FIXTURES_WPSCAN_WP_VERSION_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_version'
|
SPEC_FIXTURES_WPSCAN_WP_VERSION_DIR = SPEC_FIXTURES_WPSCAN_DIR + '/wp_version'
|
||||||
|
|
||||||
class WpScanModuleSpec
|
class WpScanModuleSpec
|
||||||
attr_reader :uri
|
attr_reader :uri
|
||||||
attr_accessor :error_404_hash, :wp_content_dir, :verbose
|
attr_accessor :error_404_hash, :wp_content_dir, :verbose
|
||||||
|
|
||||||
def initialize(target_url)
|
def initialize(target_url)
|
||||||
@uri = URI.parse(add_http_protocol(target_url))
|
@uri = URI.parse(add_http_protocol(target_url))
|
||||||
Browser.instance(
|
Browser.instance(
|
||||||
:config_file => SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf.json',
|
:config_file => SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf.json',
|
||||||
:cache_timeout => 0
|
:cache_timeout => 0
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ begin
|
|||||||
wp_target = WpTarget.new(wpscan_options.url, wpscan_options.to_h)
|
wp_target = WpTarget.new(wpscan_options.url, wpscan_options.to_h)
|
||||||
|
|
||||||
# Remote website up?
|
# Remote website up?
|
||||||
unless wp_target.is_online?
|
unless wp_target.online?
|
||||||
raise "The WordPress URL supplied '#{wp_target.uri}' seems to be down."
|
raise "The WordPress URL supplied '#{wp_target.uri}' seems to be down."
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ begin
|
|||||||
|
|
||||||
# Remote website is wordpress?
|
# Remote website is wordpress?
|
||||||
unless wpscan_options.force
|
unless wpscan_options.force
|
||||||
unless wp_target.is_wordpress?
|
unless wp_target.wordpress?
|
||||||
raise "The remote website is up, but does not seem to be running WordPress."
|
raise "The remote website is up, but does not seem to be running WordPress."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user