|
| 1 | +require_relative '../spec_helper' |
| 2 | + |
| 3 | +describe Wpxf::WordPress::StoredXss do |
| 4 | + let(:subject) do |
| 5 | + Class.new(Wpxf::Module) do |
| 6 | + include Wpxf::WordPress::StoredXss |
| 7 | + end.new |
| 8 | + end |
| 9 | + |
| 10 | + describe '#new' do |
| 11 | + it 'sets up the desc key of the info store' do |
| 12 | + desc = 'This module stores a script in the target system that '\ |
| 13 | + 'will execute when an admin user views the vulnerable page, '\ |
| 14 | + 'which in turn, will create a new admin user to upload '\ |
| 15 | + 'and execute the selected payload in the context of the '\ |
| 16 | + 'web server.' |
| 17 | + |
| 18 | + expect(subject.module_desc).to eq desc |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + describe '#run' do |
| 23 | + it 'starts a HTTP server if the module is configured properly' do |
| 24 | + invoked = false |
| 25 | + allow(subject).to receive(:start_http_server) do |
| 26 | + invoked = true |
| 27 | + end |
| 28 | + |
| 29 | + allow(subject).to receive(:puts).and_return nil |
| 30 | + allow(subject).to receive(:check_wordpress_and_online).and_return true |
| 31 | + allow(subject).to receive(:store_script_and_validate).and_return true |
| 32 | + subject.run |
| 33 | + expect(invoked).to be true |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + describe '#store_script' do |
| 38 | + it 'raises an error if the store_script method isn\'t implemented' do |
| 39 | + expect { subject.store_script }.to raise_error( |
| 40 | + 'Required method "store_script" has not been implemented' |
| 41 | + ) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + describe '#store_script_and_validate' do |
| 46 | + it 'returns false if the response has a code !== 200' do |
| 47 | + typhoeus_res = Typhoeus::Response.new |
| 48 | + allow(typhoeus_res).to receive(:code).and_return(404) |
| 49 | + allow(subject).to receive(:store_script).and_return(Wpxf::Net::HttpResponse.new(typhoeus_res)) |
| 50 | + expect(subject.store_script_and_validate).to be false |
| 51 | + end |
| 52 | + |
| 53 | + it 'returns false if the response is nil' do |
| 54 | + allow(subject).to receive(:store_script).and_return(nil) |
| 55 | + expect(subject.store_script_and_validate).to be false |
| 56 | + end |
| 57 | + |
| 58 | + it 'returns true if the response code is 200' do |
| 59 | + typhoeus_res = Typhoeus::Response.new |
| 60 | + allow(typhoeus_res).to receive(:code).and_return(200) |
| 61 | + allow(subject).to receive(:store_script).and_return(Wpxf::Net::HttpResponse.new(typhoeus_res)) |
| 62 | + expect(subject.store_script_and_validate).to be true |
| 63 | + end |
| 64 | + end |
| 65 | +end |
0 commit comments