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/tools/java_deserializer_spec.rb
Views: 11766
require 'rex/java'1require 'stringio'23load Metasploit::Framework.root.join('tools/exploit/java_deserializer.rb').to_path45RSpec.describe JavaDeserializer do67before(:context) do8@out = $stdout9@err = $stderr1011$stdout = StringIO.new12$stderr = StringIO.new13end1415after(:context) do16$stdout = @out17$stderr = @err18end1920subject(:deserializer) do21described_class.new22end2324let(:valid_stream) do25"\xac\xed\x00\x05\x75\x72\x00\x02" +26"\x5b\x43\xb0\x26\x66\xb0\xe2\x5d" +27"\x84\xac\x02\x00\x00\x78\x70\x00" +28"\x00\x00\x02\x00\x61\x00\x62"29end3031describe ".new" do32it "returns a JavaDeserializer instance" do33expect(deserializer).to be_a(JavaDeserializer)34end3536it "initializes file to nil" do37expect(deserializer.file).to be_nil38end39end4041describe "#run" do42context "when file is nil" do43it "returns nil" do44expect(deserializer.run).to be_nil45end46end4748context "when file contains a valid stream" do49before(:example) do50$stdout.string = ''51end5253context "when no options" do54it "prints the stream contents" do55expect(File).to receive(:new) do56contents = valid_stream57StringIO.new(contents)58end59deserializer.file = 'sample'60deserializer.run61expect($stdout.string).to include('[7e0001] NewArray { char, ["97", "98"] }')62end63end6465context "when :array in options" do66it "prints the array contents" do67expect(File).to receive(:new) do68contents = valid_stream69StringIO.new(contents)70end71deserializer.file = 'sample'72deserializer.run({:array => '0'})73expect($stdout.string).to include('Array Type: char')74end75end76end7778context "when file contains an invalid stream" do79it "prints the error while deserializing" do80expect(File).to receive(:new) do81contents = 'invalid_stream'82StringIO.new(contents)83end84deserializer.file = 'sample'85deserializer.run86expect($stdout.string).to include('[-] Failed to unserialize Stream')87end88end89end90end9192