From 236c28b6fb2fd24d172f15e0e957c4140d9c299a Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Tue, 24 Nov 2015 09:42:57 -0600 Subject: [PATCH] Add shared context --- .../remote/java/rmi/client/jmx/server_spec.rb | 42 +------------------ spec/support/shared/contexts/msf/string_io.rb | 37 ++++++++++++++++ 2 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 spec/support/shared/contexts/msf/string_io.rb diff --git a/spec/lib/msf/core/exploit/remote/java/rmi/client/jmx/server_spec.rb b/spec/lib/msf/core/exploit/remote/java/rmi/client/jmx/server_spec.rb index 371c987b16..deb6cb78e3 100644 --- a/spec/lib/msf/core/exploit/remote/java/rmi/client/jmx/server_spec.rb +++ b/spec/lib/msf/core/exploit/remote/java/rmi/client/jmx/server_spec.rb @@ -19,54 +19,16 @@ RSpec.describe Msf::Exploit::Remote::Java::Rmi::Client::Jmx::Server do describe "#send_new_client" do context "when there is an RMIServerImpl_Stub interface" do + include_context "Msf::StringIO" + # # lets # - let(:io) { - StringIO.new('', 'w+b') - } - let(:remote_address) { '172.16.158.132' } - # - # Callbacks - # - - before(:each) do - def io.get_once - read - end - - def io.has_read_data?(_timeout) - false - end - - def io.put(_data) - seek(0) - write( - "\x51\xac\xed\x00\x05\x77\x0f\x01\x82\x73\x92\x35\x00\x00\x01\x4c" + - "\x48\x27\x84\x49\x80\xbf\x73\x72\x00\x32\x6a\x61\x76\x61\x78\x2e" + - "\x6d\x61\x6e\x61\x67\x65\x6d\x65\x6e\x74\x2e\x72\x65\x6d\x6f\x74" + - "\x65\x2e\x72\x6d\x69\x2e\x52\x4d\x49\x43\x6f\x6e\x6e\x65\x63\x74" + - "\x69\x6f\x6e\x49\x6d\x70\x6c\x5f\x53\x74\x75\x62\x00\x00\x00\x00" + - "\x00\x00\x00\x02\x02\x00\x00\x70\x78\x72\x00\x1a\x6a\x61\x76\x61" + - "\x2e\x72\x6d\x69\x2e\x73\x65\x72\x76\x65\x72\x2e\x52\x65\x6d\x6f" + - "\x74\x65\x53\x74\x75\x62\xe9\xfe\xdc\xc9\x8b\xe1\x65\x1a\x02\x00" + - "\x00\x70\x78\x72\x00\x1c\x6a\x61\x76\x61\x2e\x72\x6d\x69\x2e\x73" + - "\x65\x72\x76\x65\x72\x2e\x52\x65\x6d\x6f\x74\x65\x4f\x62\x6a\x65" + - "\x63\x74\xd3\x61\xb4\x91\x0c\x61\x33\x1e\x03\x00\x00\x70\x78\x70" + - "\x77\x37\x00\x0a\x55\x6e\x69\x63\x61\x73\x74\x52\x65\x66\x00\x0e" + - "\x31\x37\x32\x2e\x31\x36\x2e\x31\x35\x38\x2e\x31\x33\x32\x00\x00" + - "\x13\x26\xa2\x01\x50\x97\x40\xd4\x90\xd1\x82\x73\x92\x35\x00\x00" + - "\x01\x4c\x48\x27\x84\x49\x80\xbe\x01\x78" - ) - seek(0) - end - end - it "returns the reference information" do expect(instance.send_new_client(sock: io)[:address]).to eq(remote_address) end diff --git a/spec/support/shared/contexts/msf/string_io.rb b/spec/support/shared/contexts/msf/string_io.rb new file mode 100644 index 0000000000..c3fd7dfd3b --- /dev/null +++ b/spec/support/shared/contexts/msf/string_io.rb @@ -0,0 +1,37 @@ +RSpec.shared_context 'Msf::StringIO' do + let(:io) do + StringIO.new('', 'w+b') + end + + before(:each) do + def io.get_once + read + end + + def io.has_read_data?(_timeout) + false + end + + def io.put(_data) + seek(0) + write( + "\x51\xac\xed\x00\x05\x77\x0f\x01\x82\x73\x92\x35\x00\x00\x01\x4c" + + "\x48\x27\x84\x49\x80\xbf\x73\x72\x00\x32\x6a\x61\x76\x61\x78\x2e" + + "\x6d\x61\x6e\x61\x67\x65\x6d\x65\x6e\x74\x2e\x72\x65\x6d\x6f\x74" + + "\x65\x2e\x72\x6d\x69\x2e\x52\x4d\x49\x43\x6f\x6e\x6e\x65\x63\x74" + + "\x69\x6f\x6e\x49\x6d\x70\x6c\x5f\x53\x74\x75\x62\x00\x00\x00\x00" + + "\x00\x00\x00\x02\x02\x00\x00\x70\x78\x72\x00\x1a\x6a\x61\x76\x61" + + "\x2e\x72\x6d\x69\x2e\x73\x65\x72\x76\x65\x72\x2e\x52\x65\x6d\x6f" + + "\x74\x65\x53\x74\x75\x62\xe9\xfe\xdc\xc9\x8b\xe1\x65\x1a\x02\x00" + + "\x00\x70\x78\x72\x00\x1c\x6a\x61\x76\x61\x2e\x72\x6d\x69\x2e\x73" + + "\x65\x72\x76\x65\x72\x2e\x52\x65\x6d\x6f\x74\x65\x4f\x62\x6a\x65" + + "\x63\x74\xd3\x61\xb4\x91\x0c\x61\x33\x1e\x03\x00\x00\x70\x78\x70" + + "\x77\x37\x00\x0a\x55\x6e\x69\x63\x61\x73\x74\x52\x65\x66\x00\x0e" + + "\x31\x37\x32\x2e\x31\x36\x2e\x31\x35\x38\x2e\x31\x33\x32\x00\x00" + + "\x13\x26\xa2\x01\x50\x97\x40\xd4\x90\xd1\x82\x73\x92\x35\x00\x00" + + "\x01\x4c\x48\x27\x84\x49\x80\xbe\x01\x78" + ) + seek(0) + end + end +end