diff --git a/lib/wpscan/modules/web_site.rb b/lib/wpscan/modules/web_site.rb index ad266525..9ed62621 100644 --- a/lib/wpscan/modules/web_site.rb +++ b/lib/wpscan/modules/web_site.rb @@ -86,16 +86,24 @@ module WebSite redirection end + # Returns the MD5 hash of the page given by url + def self.page_hash(url) + Digest::MD5.hexdigest(Browser.instance.get(url).body) + end + + def homepage_hash + unless @homepage_hash + @homepage_hash = WebSite.page_hash(self.url) + end + @homepage_hash + end + # Return the MD5 hash of a 404 page def error_404_hash unless @error_404_hash non_existant_page = Digest::MD5.hexdigest(rand(9999999999).to_s) + ".html" - - response = Browser.instance.get(@uri.merge(non_existant_page).to_s) - - @error_404_hash = Digest::MD5.hexdigest(response.body) + @error_404_hash = WebSite.page_hash(@uri.merge(non_existant_page).to_s) end - @error_404_hash end end diff --git a/spec/lib/wpscan/modules/web_site_spec.rb b/spec/lib/wpscan/modules/web_site_spec.rb index 067cfbc0..d99aee60 100644 --- a/spec/lib/wpscan/modules/web_site_spec.rb +++ b/spec/lib/wpscan/modules/web_site_spec.rb @@ -120,6 +120,26 @@ shared_examples_for "WebSite" do end end + describe "#page_hash" do + it "should return the MD5 hash of the page" do + url = "http://e.localhost/somepage.php" + body = "Hello World !" + + stub_request(:get, url).to_return(:body => body) + + WebSite.page_hash(url).should === Digest::MD5.hexdigest(body) + end + end + + describe "#homepage_hash" do + it "should return the MD5 hash of the homepage" do + body = "Hello World" + + stub_request(:get, web_site.url).to_return(:body => body) + web_site.homepage_hash.should === Digest::MD5.hexdigest(body) + end + end + describe "#error_404_hash" do it "should return the md5sum of the 404 page" do stub_request(:any, /.*/).