Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/msf/util/java_deserialization_spec.rb
Views: 11704
require 'rex'12RSpec.describe Msf::Util::JavaDeserialization do3let(:payload_name) do4'PAYLOAD_NAME'5end67let(:default_command) do8nil9end10describe '#ysoserial_payload' do1112context 'when default payload is not found' do13it 'raises a RuntimeError' do14stub_const('Msf::Util::JavaDeserialization::PAYLOAD_FILENAME', 'INVALID')15expect{Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command)}.to raise_error(RuntimeError, /Unable to load JSON data from:/)16end17end1819context 'when default payload is not JSON format' do20it 'raises a RuntimeError error' do21allow(File).to receive(:read).and_return('BAD DATA')22expect{Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command)}.to raise_error(RuntimeError, /Unable to load JSON data from:/)23end24end2526context 'when payload status is unsupported' do27it 'raises a unsupported error' do28json_data = %Q|{"none":{"BeanShell1":{"status":"unsupported","bytes":"AAAA"}}}|29allow(File).to receive(:read).and_return(json_data)30expect{Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command)}.to raise_error(ArgumentError)31end32end3334context 'when payload status is static' do35let(:payload_name) do36'BeanShell1'37end3839it 'returns a Base64 string' do40original_bytes = 'AAAA'41b64 = Rex::Text.encode_base64(original_bytes)42json_data = %Q|{"none":{"BeanShell1":{"status":"static","bytes":"#{b64}"}}}|43allow(File).to receive(:read).and_return(json_data)44p = Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command)45expect(p).to eq(original_bytes)46end47end4849context 'when payload status is dynamic' do50let(:payload_name) do51'CommonsCollections1'52end5354context 'when missing a command' do55it 'raises an argument error' do56expect{Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command)}.to raise_error(ArgumentError)57end58end5960context 'when a modified type is not found' do61it 'raises an argument error' do62type = 'unknown_type'63expect{Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command, modified_type: type)}.to raise_error(ArgumentError)64end65end6667context 'when a command is provided' do68it 'returns serialized data' do69default_command = 'id'70p = Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command)71expect(p).to include('java.util.Mapxr')72end73end7475context 'when command and type are provided' do76it 'returns serialized data' do77default_command = 'id'78type = 'bash'79p = Msf::Util::JavaDeserialization::ysoserial_payload(payload_name, default_command, modified_type: type)80expect(p).to include('java.util.Mapxr')81end82end83end84end85end868788