Skip to content

Commit 82d5458

Browse files
committed
Add specs for Msf::Java::Rmi::Client::Jmx::Server::Builder
1 parent 87cac6f commit 82d5458

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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::Server::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_new_client) 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(:auth_stream) do
24+
"\x72\x00\x13\x5b\x4c\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x53" +
25+
"\x74\x72\x69\x6e\x67\x3b\xad\xd2\x56\xe7\xe9\x1d\x7b\x47\x02\x00" +
26+
"\x00\x70\x78\x70\x00\x00\x00\x02\x74\x00\x04\x72\x6f\x6c\x65\x74" +
27+
"\x00\x08\x70\x61\x73\x73\x77\x6f\x72\x64"
28+
end
29+
30+
let(:credentials_new_client) do
31+
"\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
32+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff" +
33+
"\xff\xf0\xe0\x74\xea\xad\x0c\xae\xa8\x75\x72\x00\x13\x5b\x4c\x6a" +
34+
"\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x53\x74\x72\x69\x6e\x67\x3b" +
35+
"\xad\xd2\x56\xe7\xe9\x1d\x7b\x47\x02\x00\x00\x70\x78\x70\x00\x00" +
36+
"\x00\x02\x74\x00\x04\x72\x6f\x6c\x65\x74\x00\x08\x70\x61\x73\x73" +
37+
"\x77\x6f\x72\x64"
38+
end
39+
40+
let(:new_client_opts) do
41+
{
42+
username: 'role',
43+
password: 'password'
44+
}
45+
end
46+
47+
describe "#build_jmx_new_client" do
48+
context "when no opts" do
49+
it "creates a Rex::Proto::Rmi::Model::Call" do
50+
expect(mod.build_jmx_new_client).to be_a(Rex::Proto::Rmi::Model::Call)
51+
end
52+
53+
it "creates a lookup Call for an empty name" do
54+
expect(mod.build_jmx_new_client.encode).to eq(default_new_client)
55+
end
56+
end
57+
58+
context "when opts with credentials" do
59+
it "creates a Rex::Proto::Rmi::Model::Call" do
60+
expect(mod.build_jmx_new_client(new_client_opts)).to be_a(Rex::Proto::Rmi::Model::Call)
61+
end
62+
63+
it "creates a newClient Call with credentials" do
64+
expect(mod.build_jmx_new_client(new_client_opts).encode).to eq(credentials_new_client)
65+
end
66+
end
67+
end
68+
69+
describe "#build_jmx_new_client_args" do
70+
it "return an Array" do
71+
expect(mod.build_jmx_new_client_args('role', 'password')).to be_an(Array)
72+
end
73+
74+
it "returns an Array with a Rex::Java::Serialization::Model::NewArray" do
75+
expect(mod.build_jmx_new_client_args('role', 'password')[0]).to be_a(Rex::Java::Serialization::Model::NewArray)
76+
end
77+
78+
it "builds a correct stream" do
79+
expect(mod.build_jmx_new_client_args('role', 'password')[0].encode).to eq(auth_stream)
80+
end
81+
end
82+
end
83+

0 commit comments

Comments
 (0)