From a4ace91e68645f9d7efe2531f310926d5923490f Mon Sep 17 00:00:00 2001 From: erwanlr Date: Tue, 1 Jan 2013 15:30:01 +0100 Subject: [PATCH] Fix #96 Username detection from header location when a trailing slash is present --- lib/wpscan/modules/wp_usernames.rb | 2 +- spec/lib/wpscan/modules/wp_usernames_spec.rb | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/wpscan/modules/wp_usernames.rb b/lib/wpscan/modules/wp_usernames.rb index 035d1cf8..7c120974 100644 --- a/lib/wpscan/modules/wp_usernames.rb +++ b/lib/wpscan/modules/wp_usernames.rb @@ -37,7 +37,7 @@ module WpUsernames username = nil nickname = nil if response.code == 301 # username in location? - username = response.headers_hash['location'][%r{/author/([^/]+)/}i, 1] + username = response.headers_hash['location'][%r{/author/([^/\b]+)/?}i, 1] # Get the real name from the redirect site nickname = get_nickname_from_url(url) elsif response.code == 200 # username in body? diff --git a/spec/lib/wpscan/modules/wp_usernames_spec.rb b/spec/lib/wpscan/modules/wp_usernames_spec.rb index 3ede2927..6d5cd2cf 100644 --- a/spec/lib/wpscan/modules/wp_usernames_spec.rb +++ b/spec/lib/wpscan/modules/wp_usernames_spec.rb @@ -45,7 +45,7 @@ shared_examples_for "WpUsernames" do it "should return an array with 1 username (from header location)" do stub_request(:get, @module.author_url(3)). - to_return(:status => 301, :headers => {'location' => '/author/Youhou/'}) + to_return(:status => 301, :headers => {'location' => '/author/Youhou'}) usernames = @module.usernames usernames.should_not be_empty @@ -57,7 +57,7 @@ shared_examples_for "WpUsernames" do it "should return an array with 1 username (from in the body response)" do stub_request(:get, @module.author_url(2)). - to_return(:status => 200, :body => File.new(@fixtures_dir + '/admin.htm')) + to_return(:status => 200, :body => File.new(@fixtures_dir + '/admin.htm')) usernames = @module.usernames(:range => (1..2)) usernames.should_not be_empty @@ -66,15 +66,17 @@ shared_examples_for "WpUsernames" do it "should return an array with 2 usernames (one is a duplicate and should not be present twice)" do stub_request(:get, @module.author_url(4)). - to_return(:status => 301, :headers => {'location' => '/author/Youhou/'}) + to_return(:status => 301, :headers => {'location' => '/author/Youhou/'}) stub_request(:get, @module.author_url(2)). - to_return(:status => 200, :body => File.new(@fixtures_dir + '/admin.htm')) + to_return(:status => 200, :body => File.new(@fixtures_dir + '/admin.htm')) usernames = @module.usernames(:range => (1..5)) usernames.should_not be_empty - expected = [WpUser.new("admin", 2, "admin | Wordpress 3.3.2"), - WpUser.new("Youhou", 4, "empty")] + expected = [ + WpUser.new("admin", 2, "admin | Wordpress 3.3.2"), + WpUser.new("Youhou", 4, "empty") + ] usernames.sort_by { |u| u.name }.eql?(expected.sort_by { |u| u.name }).should be_true end