require 'spec_helper' require 'ronin/exploits/rfi' describe Ronin::Exploits::RFI do module TestRFI class TestExploit < Ronin::Exploits::RFI base_path '/showimage.php' query_param 'file' end end let(:exploit_class) { TestRFI::TestExploit } let(:base_url) { 'http://testphp.vulnweb.com' } subject do exploit_class.new( params: { base_url: base_url } ) end describe ".exploit_type" do subject { described_class } it { expect(subject.exploit_type).to eq(:rfi) } end describe "#vuln" do it "must return a Ronin::Vulns::RFI object" do expect(subject.vuln).to be_kind_of(Ronin::Vulns::RFI) end it "must set the #url attribute of the RFI vuln object" do expect(subject.vuln.url).to eq(subject.url) end it "must infer the #test_scrript_url from the #url attribute" do expect(subject.vuln.test_script_url).to eq(Ronin::Vulns::RFI.test_script_for(subject.vuln.url)) end context "when the 'test_script_url' param is set" do let(:test_script_url) { 'https://myhost.com/path/to/test_script.php' } subject do exploit_class.new( params: { base_url: base_url, test_script_url: test_script_url } ) end it "must set the #test_script_url for the RFI vuln object" do expect(subject.vuln.test_script_url).to eq(test_script_url) end end it "must not set the #filter_bypass attribute of the RFI vuln object by default" do expect(subject.vuln.filter_bypass).to be(nil) end context "when the 'filter_bypass' param is set" do let(:filter_bypass) { :double_encode } subject do exploit_class.new( params: { base_url: base_url, filter_bypass: filter_bypass } ) end it "must set the #filter_bypass attribute of the RFI vuln object to the 'filter_bypass' param" do expect(subject.vuln.filter_bypass).to eq(filter_bypass) end end end describe "#launch" do module TestRFI class RFIPayload < Ronin::Payloads::URLPayload url 'https://example.com/path/to/payload.php' end end let(:payload_class) { TestRFI::RFIPayload } let(:payload) { payload_class.new } subject do exploit_class.new( payload: payload, params: { base_url: base_url } ) end it "must call #exploit on the #vuln object with the #payload" do expect(subject.vuln).to receive(:exploit).with(payload) subject.launch end end end