|
| 1 | +# -*- coding:binary -*- |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +require 'stringio' |
| 5 | +require 'rex/java/serialization' |
| 6 | +require 'rex/proto/rmi' |
| 7 | +require 'msf/java/rmi/client' |
| 8 | + |
| 9 | +describe Msf::Java::Rmi::Client::Jmx::Connection::Builder do |
| 10 | + subject(:mod) do |
| 11 | + mod = ::Msf::Exploit.new |
| 12 | + mod.extend ::Msf::Java::Rmi::Client |
| 13 | + mod.send(:initialize) |
| 14 | + mod |
| 15 | + end |
| 16 | + |
| 17 | + let(:default_get_object_instance) do |
| 18 | + "\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00" + |
| 19 | + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff" + |
| 20 | + "\xff\xf0\xe0\x74\xea\xad\x0c\xae\xa8\x70" |
| 21 | + end |
| 22 | + |
| 23 | + let(:mlet_name) do |
| 24 | + 'DefaultDomain:type=MLet' |
| 25 | + end |
| 26 | + |
| 27 | + let(:mlet_get_object_instance) do |
| 28 | + "\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00" + |
| 29 | + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff" + |
| 30 | + "\xff\xf0\xe0\x74\xea\xad\x0c\xae\xa8\x70" |
| 31 | + end |
| 32 | + |
| 33 | + describe "#build_jmx_get_object_instance" do |
| 34 | + context "when no opts" do |
| 35 | + it "creates a Rex::Proto::Rmi::Model::Call" do |
| 36 | + expect(mod.build_jmx_new_client).to be_a(Rex::Proto::Rmi::Model::Call) |
| 37 | + end |
| 38 | + |
| 39 | + it "creates a getObjectInstance call for an empty object name" do |
| 40 | + expect(mod.build_jmx_new_client.encode).to eq(default_get_object_instance) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + context "when opts with class name" do |
| 45 | + it "creates a Rex::Proto::Rmi::Model::Call" do |
| 46 | + expect(mod.build_jmx_new_client(name: mlet_name)).to be_a(Rex::Proto::Rmi::Model::Call) |
| 47 | + end |
| 48 | + |
| 49 | + it "creates a newClient Call with credentials" do |
| 50 | + expect(mod.build_jmx_new_client(name: mlet_name).encode).to eq(mlet_get_object_instance) |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe "#build_jmx_new_client_args" do |
| 56 | + it "return an Array" do |
| 57 | + expect(mod.build_jmx_get_object_instance_args(mlet_name)).to be_an(Array) |
| 58 | + end |
| 59 | + |
| 60 | + it "returns an Array with 4 elements" do |
| 61 | + expect(mod.build_jmx_get_object_instance_args(mlet_name).length).to eq(4) |
| 62 | + end |
| 63 | + |
| 64 | + it "returns an Array whose second element is an utf string with the object name" do |
| 65 | + expect(mod.build_jmx_get_object_instance_args(mlet_name)[1].contents).to eq(mlet_name) |
| 66 | + end |
| 67 | + end |
| 68 | +end |
| 69 | + |
0 commit comments