Skip to content

Commit

Permalink
Use Msf::StringIO in connection_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jvazquez-r7 authored and Brent Cook committed Dec 11, 2015
1 parent 4872628 commit 2041149
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'rex/java/serialization'
require 'rex/proto/rmi'
require 'msf/core/exploit/java/rmi/client'
require 'stringio'

RSpec.describe Msf::Exploit::Remote::Java::Rmi::Client::Jmx::Connection do

Expand All @@ -21,10 +20,10 @@
mod
end

let(:io) { StringIO.new('', 'w+b') }

describe "#send_jmx_get_object_instance" do
context "when the object exists" do
include_context "Msf::StringIO"

#
# lets
#
Expand All @@ -36,15 +35,7 @@
#

before(:each) do
def io.get_once
read
end

def io.has_read_data?(_timeout)
false
end

def io.put(_data)
def msf_io.put(_data)
seek(0)
write(
"\x51\xac\xed\x00\x05\x77\x0f\x01\x1e\xc8\x7c\x01\x00\x00\x01\x4c" +
Expand All @@ -69,23 +60,17 @@ def io.put(_data)
end

it "returns true" do
expect(mod.send_jmx_get_object_instance(sock: io, name: name_get)).to be_truthy
expect(mod.send_jmx_get_object_instance(sock: msf_io, name: name_get)).to be_truthy
end
end
end

describe "#send_jmx_create_mbean" do
context "when the object is created successfully" do
before(:each) do
def io.get_once
read
end
include_context "Msf::StringIO"

def io.has_read_data?(_timeout)
false
end

def io.put(_data)
before(:each) do
def msf_io.put(_data)
seek(0)
write(
"\x51\xac\xed\x00\x05\x77\x0f\x01\x1e\xc8\x7c\x01\x00\x00\x01\x4c" +
Expand All @@ -110,13 +95,15 @@ def io.put(_data)
end

it "returns true" do
expect(mod.send_jmx_create_mbean(sock: io, name: name_create)).to be_truthy
expect(mod.send_jmx_create_mbean(sock: msf_io, name: name_create)).to be_truthy
end
end
end

describe "#send_jmx_invoke" do
context "when the remote method is called successfully" do
include_context "Msf::StringIO"

#
# lets
#
Expand All @@ -134,15 +121,7 @@ def io.put(_data)
#

before(:each) do
def io.get_once
read
end

def io.has_read_data?(_timeout)
false
end

def io.put(_data)
def msf_io.put(_data)
seek(0)
write(
"\x51\xac\xed\x00\x05\x77\x0f\x01\x1e\xc8\x7c\x01\x00\x00\x01\x4c" +
Expand Down Expand Up @@ -170,7 +149,7 @@ def io.put(_data)
end

it "returns true" do
expect(mod.send_jmx_invoke(invoke_args.merge(sock: io))).to be_truthy
expect(mod.send_jmx_invoke(invoke_args.merge(sock: msf_io))).to be_truthy
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
context "when there is an RMIServerImpl_Stub interface" do
include_context "Msf::StringIO"

#
# Callbacks
#

before(:each) do
def msf_io.put(_data)
seek(0)
Expand Down
4 changes: 4 additions & 0 deletions spec/support/shared/contexts/msf/string_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
StringIO.new('', 'w+b')
end

#
# Callbacks
#

before(:each) do
def msf_io.get_once
read
Expand Down

0 comments on commit 2041149

Please sign in to comment.