Path: blob/master/spec/app/finders/interesting_findings/upload_sql_dump_spec.rb
1483 views
# frozen_string_literal: true12describe WPScan::Finders::InterestingFindings::UploadSQLDump do3subject(:finder) { described_class.new(target) }4let(:target) { WPScan::Target.new(url).extend(CMSScanner::Target::Server::Apache) }5let(:url) { 'http://ex.lo/' }6let(:dump_url) { "#{url}wp-content/uploads/dump.sql" }7let(:fixtures) { FINDERS_FIXTURES.join('interesting_findings', 'upload_sql_dump') }8let(:wp_content) { 'wp-content' }910describe '#aggressive' do11before do12expect(target).to receive(:content_dir).at_least(1).and_return(wp_content)13expect(target).to receive(:head_or_get_params).and_return(method: :head)14end1516after { expect(finder.aggressive).to eql @expected }1718context 'when not a 200' do19it 'returns nil' do20stub_request(:head, dump_url).to_return(status: 404)2122@expected = nil23end24end2526context 'when a 200' do27before do28stub_request(:head, dump_url).to_return(status: 200)2930stub_request(:get, dump_url)31.with(headers: { 'Range' => 'bytes=0-3000' })32.to_return(body: File.read(fixtures.join(fixture)))33end3435context 'when the body does not match a SQL dump' do36let(:fixture) { 'not_sql.txt' }3738it 'returns nil' do39@expected = nil40end41end4243context 'when the body matches a SQL dump' do44let(:fixture) { 'dump.sql' }4546it 'returns the interesting findings' do47@expected = WPScan::Model::UploadSQLDump.new(48dump_url,49confidence: 100,50found_by: described_class::DIRECT_ACCESS51)52end53end54end55end56end575859