metasploit-framework/spec/lib/msf/java/rmi/builder_spec.rb

122 lines
3.4 KiB
Ruby
Raw Normal View History

2015-01-08 20:17:57 +00:00
# -*- coding:binary -*-
require 'spec_helper'
require 'rex/java/serialization'
require 'rex/proto/rmi'
2015-03-18 14:29:37 +00:00
require 'msf/java/rmi/builder'
2015-01-08 20:17:57 +00:00
2015-03-18 14:29:37 +00:00
describe Msf::Java::Rmi::Builder do
2015-01-08 20:17:57 +00:00
subject(:mod) do
mod = ::Msf::Exploit.new
2015-03-18 14:29:37 +00:00
mod.extend ::Msf::Java::Rmi::Builder
2015-01-08 20:17:57 +00:00
mod.send(:initialize)
mod
end
let(:default_header) { "JRMI\x00\x02\x4b" }
let(:header_opts) do
{
2015-01-08 20:24:07 +00:00
:version => 1,
:protocol => Rex::Proto::Rmi::Model::MULTIPLEX_PROTOCOL
2015-01-08 20:17:57 +00:00
}
end
let(:opts_header) { "JRMI\x00\x01\x4d" }
2015-03-17 16:48:38 +00:00
let(:default_call) do
"\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff" +
"\xff\x00\x00\x00\x00\x00\x00\x00\x00"
end
2015-01-08 20:17:57 +00:00
let(:call_opts) do
{
2015-03-17 16:48:38 +00:00
message_id: Rex::Proto::Rmi::Model::CALL_MESSAGE,
object_number: 2,
uid_number: 0,
uid_time: 0,
uid_count: 0,
operation: 0,
hash: 0xf6b6898d8bf28643
2015-01-08 20:17:57 +00:00
}
end
2015-03-17 16:48:38 +00:00
let(:opts_call) do
"\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x02\x00" +
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
"\x00\xf6\xb6\x89\x8d\x8b\xf2\x86\x43"
end
2015-01-08 20:17:57 +00:00
2015-01-13 17:02:16 +00:00
let(:default_dgc_ack) { "\x54\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
let(:dgc_ack_opts) do
{
:unique_identifier => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x04\x03\x02\x01"
}
end
let(:opts_dgc_ack) { "\x54\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x04\x03\x02\x01" }
2015-01-08 20:17:57 +00:00
describe "#build_header" do
context "when no opts" do
it "creates a Rex::Proto::Rmi::Model::OutputHeader" do
expect(mod.build_header).to be_a(Rex::Proto::Rmi::Model::OutputHeader)
end
it "creates a default OutputHeader" do
expect(mod.build_header.encode).to eq(default_header)
end
end
context "when opts" do
it "creates a Rex::Proto::Rmi::Model::OutputHeader" do
expect(mod.build_header(header_opts)).to be_a(Rex::Proto::Rmi::Model::OutputHeader)
end
it "creates a OutputHeader with data from opts" do
expect(mod.build_header(header_opts).encode).to eq(opts_header)
end
end
end
describe "#build_call" do
context "when no opts" do
it "creates a Rex::Proto::Rmi::Model::Call" do
expect(mod.build_call).to be_a(Rex::Proto::Rmi::Model::Call)
end
it "creates a default Call" do
expect(mod.build_call.encode).to eq(default_call)
end
end
context "when opts" do
it "creates a Rex::Proto::Rmi::Model::Call" do
expect(mod.build_call(call_opts)).to be_a(Rex::Proto::Rmi::Model::Call)
end
2015-01-13 17:02:16 +00:00
it "creates a Call with data from opts" do
2015-01-08 20:17:57 +00:00
expect(mod.build_call(call_opts).encode).to eq(opts_call)
end
end
end
2015-01-08 20:24:07 +00:00
2015-01-13 17:02:16 +00:00
describe "#build_dgc_ack" do
context "when no opts" do
it "creates a Rex::Proto::Rmi::Model::DgcAck" do
expect(mod.build_dgc_ack).to be_a(Rex::Proto::Rmi::Model::DgcAck)
end
it "creates a default Call" do
expect(mod.build_dgc_ack.encode).to eq(default_dgc_ack)
end
end
context "when opts" do
it "creates a Rex::Proto::Rmi::Model::DgcAck" do
expect(mod.build_dgc_ack(dgc_ack_opts)).to be_a(Rex::Proto::Rmi::Model::DgcAck)
end
it "creates a DgcAck with data from opts" do
expect(mod.build_dgc_ack(dgc_ack_opts).encode).to eq(opts_dgc_ack)
end
end
end
2015-01-08 20:17:57 +00:00
end