This commit is contained in:
erwanlr
2019-03-20 15:21:02 +00:00
parent 6304fe4c19
commit f09606cfa3
6 changed files with 77 additions and 2 deletions

View File

@@ -53,7 +53,15 @@ module WPScan
# @return [ String ] The URL of the API listing the Users # @return [ String ] The URL of the API listing the Users
def api_url def api_url
@api_url ||= target.url('wp-json/wp/v2/users/') return @api_url if @api_url
target.in_scope_urls(target.homepage_res, "//link[@rel='https://api.w.org/']/@href").each do |url, _tag|
uri = Addressable::URI.parse(url.strip)
return @api_url = uri.join('wp/v2/users/').to_s if uri.path.include?('wp-json')
end
@api_url = target.url('wp-json/wp/v2/users/')
end end
end end
end end

View File

@@ -5,7 +5,10 @@ describe WPScan::Finders::Users::WpJsonApi do
let(:fixtures) { FINDERS_FIXTURES.join('users', 'wp_json_api') } let(:fixtures) { FINDERS_FIXTURES.join('users', 'wp_json_api') }
describe '#aggressive' do describe '#aggressive' do
before { allow(target).to receive(:sub_dir).and_return(false) } before do
allow(target).to receive(:sub_dir).and_return(false)
allow(finder).to receive(:api_url).and_return(target.url('wp-json/wp/v2/users/'))
end
context 'when only one page of results' do context 'when only one page of results' do
before do before do
@@ -78,4 +81,54 @@ describe WPScan::Finders::Users::WpJsonApi do
end end
end end
end end
describe '#api_url' do
let(:fixtures) { super().join('api_url') }
context 'when url in the homepage' do
{
in_scope: 'https://wp.lab/wp-json/wp/v2/users/',
out_of_scope: 'http://wp.lab/wp-json/wp/v2/users/'
}.each do |fixture, expected|
it "returns #{expected} for #{fixture}.html" do
stub_request(:get, target.url).to_return(body: File.read(fixtures.join("#{fixture}.html")))
expect(finder.api_url).to eql expected
end
end
context 'when subdir' do
before { allow(target).to receive(:subdir).and_return('cms') }
{
in_scope_subdir: 'https://wp.lab/cms/wp-json/wp/v2/users/',
in_scope_subdir_ignored: 'https://wp.lab/wp-json/wp/v2/users/'
}.each do |fixture, expected|
it "returns #{expected} for #{fixture}.html" do
stub_request(:get, target.url).to_return(body: File.read(fixtures.join("#{fixture}.html")))
expect(finder.api_url).to eql expected
end
end
end
end
context 'when not in the homepage' do
before { stub_request(:get, target.url) }
its(:api_url) { should eql target.url('wp-json/wp/v2/users/') }
end
context 'when api_url already found' do
before { allow(target).to receive(:sub_dir).and_return(false) }
it 'does not check the homepage again' do
url = target.url('wp-json/wp/v2/users/')
finder.instance_variable_set(:@api_url, url)
expect(finder.api_url).to eql url
end
end
end
end end

View File

@@ -0,0 +1 @@
<link rel='https://api.w.org/' href='https://wp.lab/wp-json/' />

View File

@@ -0,0 +1,6 @@
<link rel='https://api.w.org/' href='https://wp.lab/cms/wp-json/' />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://wp.lab/cms/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://wp.lab/cms/wp-includes/wlwmanifest.xml" />
<link rel='shortlink' href='https://wp.lab/' />
<link rel="alternate" type="application/json+oembed" href="https://wp.lab/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fwp.lab%2F" />
<link rel="alternate" type="text/xml+oembed" href="https://wp.lab/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fwp.lab%2F&#038;format=xml" />

View File

@@ -0,0 +1,6 @@
<link rel='https://api.w.org/' href='https://wp.lab/wp-json/' />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://wp.lab/cms/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://wp.lab/cms/wp-includes/wlwmanifest.xml" />
<link rel='shortlink' href='https://wp.lab/' />
<link rel="alternate" type="application/json+oembed" href="https://wp.lab/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fwp.lab%2F" />
<link rel="alternate" type="text/xml+oembed" href="https://wp.lab/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fwp.lab%2F&#038;format=xml" />

View File

@@ -0,0 +1 @@
<link rel='https://api.w.org/' href='https://out-there.com/wp-json/' />