|
| 1 | +#-*- coding:binary -*- |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +require 'msf/core' |
| 5 | +require 'msf/http/jboss' |
| 6 | + |
| 7 | +describe Msf::HTTP::JBoss::BeanShell do |
| 8 | + |
| 9 | + subject do |
| 10 | + mod = ::Msf::Exploit.new |
| 11 | + mod.extend Msf::HTTP::JBoss |
| 12 | + mod.send(:initialize) |
| 13 | + mod |
| 14 | + end |
| 15 | + |
| 16 | + before :each do |
| 17 | + allow(subject).to receive(:send_request_cgi) do |
| 18 | + case res_code |
| 19 | + when nil |
| 20 | + res = nil |
| 21 | + when 401 |
| 22 | + res = Rex::Proto::Http::Response.new(401, "Authentication required") |
| 23 | + when 404 |
| 24 | + res = Rex::Proto::Http::Response::E404.new |
| 25 | + when 200 |
| 26 | + res = Rex::Proto::Http::Response::OK.new |
| 27 | + else |
| 28 | + res = Rex::Proto::Http::Response.new |
| 29 | + res.code = res_code |
| 30 | + end |
| 31 | + |
| 32 | + res |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + let (:package) do |
| 37 | + 'deployer' |
| 38 | + end |
| 39 | + |
| 40 | + let (:bsh_script) do |
| 41 | + 'String jboss_home = System.getProperty("jboss.server.home.dir");' |
| 42 | + end |
| 43 | + |
| 44 | + describe '#deploy_bsh' do |
| 45 | + context 'when deploy_package fails' do |
| 46 | + let (:res_code) { 404 } |
| 47 | + it { expect(subject.deploy_bsh(:bsh_script)).to be_nil } |
| 48 | + end |
| 49 | + |
| 50 | + context 'when deploy_package successes' do |
| 51 | + let (:res_code) { 200 } |
| 52 | + it { expect(subject.deploy_bsh(:bsh_script)).to be_kind_of(String) } |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + describe '#deploy_package' do |
| 57 | + context 'when invoke_bsh_script returns a 200 response' do |
| 58 | + let (:res_code) { 200 } |
| 59 | + it { expect(subject.deploy_package(:bsh_script, :package)).to be_truthy } |
| 60 | + end |
| 61 | + |
| 62 | + context 'when invoke_bsh_script returns a 404 response' do |
| 63 | + let (:res_code) { 404 } |
| 64 | + it { expect(subject.deploy_package(:bsh_script, :package)).to be_falsey } |
| 65 | + end |
| 66 | + |
| 67 | + context 'when invoke_bsh_script returns a 401 response' do |
| 68 | + let (:res_code) { 401 } |
| 69 | + it { expect(subject.deploy_package(:bsh_script, :package)).to be_falsey } |
| 70 | + end |
| 71 | + |
| 72 | + context 'when invoke_bsh_script returns nil' do |
| 73 | + let (:res_code) { nil } |
| 74 | + it { expect(subject.deploy_package(:bsh_script, :package)).to be_falsey } |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + describe "#invoke_bsh_script" do |
| 79 | + context 'when server timeouts' do |
| 80 | + let (:res_code) { nil } |
| 81 | + it { expect(subject.invoke_bsh_script(:bsh_script, :package)).to be_nil } |
| 82 | + end |
| 83 | + |
| 84 | + context 'when server returns a 200 response' do |
| 85 | + let (:res_code) { 200 } |
| 86 | + it { expect(subject.invoke_bsh_script(:bsh_script, :package)).to be_kind_of Rex::Proto::Http::Response } |
| 87 | + end |
| 88 | + |
| 89 | + context 'when server returns a 404 response' do |
| 90 | + let (:res_code) { 404 } |
| 91 | + it { expect(subject.invoke_bsh_script(:bsh_script, :package)).to be_kind_of Rex::Proto::Http::Response } |
| 92 | + end |
| 93 | + |
| 94 | + context 'when server returns a 401 response' do |
| 95 | + let (:res_code) { 401 } |
| 96 | + it { expect(subject.invoke_bsh_script(:bsh_script, :package)).to be_kind_of Rex::Proto::Http::Response } |
| 97 | + end |
| 98 | + end |
| 99 | + |
| 100 | +end |
0 commit comments