From 564da4446e046f9ca22f2bf9ee5618fb10015713 Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Sun, 7 Dec 2014 17:52:09 -0600 Subject: [PATCH] Add print friendly to_s --- .../java/serialization/model/annotation.rb | 11 +++ .../java/serialization/model/block_data.rb | 10 +++ .../serialization/model/block_data_long.rb | 10 +++ .../java/serialization/model/class_desc.rb | 7 ++ lib/rex/java/serialization/model/contents.rb | 49 +++++++++++++ lib/rex/java/serialization/model/element.rb | 7 ++ lib/rex/java/serialization/model/field.rb | 14 ++++ lib/rex/java/serialization/model/long_utf.rb | 1 + lib/rex/java/serialization/model/new_array.rb | 11 ++- .../serialization/model/new_class_desc.rb | 21 ++++++ lib/rex/java/serialization/model/new_enum.rb | 9 ++- .../java/serialization/model/new_object.rb | 19 ++++- lib/rex/java/serialization/model/reference.rb | 7 ++ lib/rex/java/serialization/model/stream.rb | 18 +++++ lib/rex/java/serialization/model/utf.rb | 7 ++ .../serialization/model/annotation_spec.rb | 13 ++++ .../model/block_data_long_spec.rb | 13 ++++ .../serialization/model/block_data_spec.rb | 12 +++ .../serialization/model/class_desc_spec.rb | 7 ++ .../java/serialization/model/field_spec.rb | 12 +++ .../java/serialization/model/long_utf_spec.rb | 12 +++ .../serialization/model/new_array_spec.rb | 46 ++++++++++++ .../model/new_class_desc_spec.rb | 7 ++ .../java/serialization/model/new_enum_spec.rb | 6 ++ .../serialization/model/new_object_spec.rb | 6 ++ .../java/serialization/model/stream_spec.rb | 73 +++++++++++++++++++ .../rex/java/serialization/model/utf_spec.rb | 13 ++++ tools/java_deserializer.rb | 2 +- 28 files changed, 419 insertions(+), 4 deletions(-) diff --git a/lib/rex/java/serialization/model/annotation.rb b/lib/rex/java/serialization/model/annotation.rb index 24f53742ed..69a7975275 100644 --- a/lib/rex/java/serialization/model/annotation.rb +++ b/lib/rex/java/serialization/model/annotation.rb @@ -49,6 +49,17 @@ module Rex encoded end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + str = '[ ' + contents_data = contents.collect {|content| "#{print_content(content)}"} + str << contents_data.join(', ') + str << ' ]' + str + end + end end end diff --git a/lib/rex/java/serialization/model/block_data.rb b/lib/rex/java/serialization/model/block_data.rb index 51e527aacb..d07e57fed6 100644 --- a/lib/rex/java/serialization/model/block_data.rb +++ b/lib/rex/java/serialization/model/block_data.rb @@ -42,6 +42,16 @@ module Rex self end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + contents_hex = [] + contents.each_byte {|byte| contents_hex << "0x#{byte.to_s(16)}" } + + "[ #{contents_hex.join(', ')} ]" + end + # Serializes the Java::Serialization::Model::BlockData # # @return [String] diff --git a/lib/rex/java/serialization/model/block_data_long.rb b/lib/rex/java/serialization/model/block_data_long.rb index 1ae64d2ac6..c66d1d3819 100644 --- a/lib/rex/java/serialization/model/block_data_long.rb +++ b/lib/rex/java/serialization/model/block_data_long.rb @@ -53,6 +53,16 @@ module Rex encoded end + + # Creates a print-friendly string representation + # + # @return [String] + def to_s + contents_hex = [] + contents.each_byte {|byte| contents_hex << "0x#{byte.to_s(16)}" } + + "[ #{contents_hex.join(', ')} ]" + end end end end diff --git a/lib/rex/java/serialization/model/class_desc.rb b/lib/rex/java/serialization/model/class_desc.rb index 646dba573f..0a8f444930 100644 --- a/lib/rex/java/serialization/model/class_desc.rb +++ b/lib/rex/java/serialization/model/class_desc.rb @@ -48,6 +48,13 @@ module Rex encoded end + + # Creates a print-friendly string representation + # + # @return [String] + def to_s + print_content(description) + end end end end diff --git a/lib/rex/java/serialization/model/contents.rb b/lib/rex/java/serialization/model/contents.rb index 81b71915f3..82416288cd 100644 --- a/lib/rex/java/serialization/model/contents.rb +++ b/lib/rex/java/serialization/model/contents.rb @@ -98,6 +98,55 @@ module Rex encoded << content.encode encoded end + + # Creates a print-friendly string representation + # + # @param content [Rex::Java::Serialization::Model::Element] the content to print + # @return [String] + def print_content(content) + str = '' + + case content + when BlockData + str << "#{print_class(content)} { #{content.to_s} }" + when BlockDataLong + str << "#{print_class(content)} { #{content.to_s} }" + when EndBlockData + str << "#{print_class(content)}" + when NewObject + str << "#{print_class(content)} { #{content.to_s} }" + when ClassDesc + str << "#{print_class(content)} { #{content.to_s} }" + when NewArray + str << "#{print_class(content)} { #{content.to_s} }" + when Utf + str << "#{print_class(content)} { #{content.to_s} }" + when LongUtf + str << "#{print_class(content)} { #{content.to_s} } " + when NewEnum + str << "#{print_class(content)} { #{content.to_s} }" + when NewClassDesc + str << "#{print_class(content)} { #{content.to_s} }" + when NullReference + str << "#{print_class(content)}" + when Reset + str << "#{print_class(content)}" + when Reference + str << "#{print_class(content)} { #{content.to_s} }" + else + raise ::RuntimeError, 'Failed to serialize content' + end + + str + end + + # Creates a print-friendly string representation of the content class + # + # @param content [Rex::Java::Serialization::Model::Element] the content + # @return [String] + def print_class(content) + content.class.name.split('::').last + end end end end diff --git a/lib/rex/java/serialization/model/element.rb b/lib/rex/java/serialization/model/element.rb index 6b7b500d3f..07bf0bf5d7 100644 --- a/lib/rex/java/serialization/model/element.rb +++ b/lib/rex/java/serialization/model/element.rb @@ -28,6 +28,13 @@ module Rex def encode '' end + + # Creates a print-friendly string representation + # + # @return [String] + def to_s + self.class.name.split('::').last + end end end end diff --git a/lib/rex/java/serialization/model/field.rb b/lib/rex/java/serialization/model/field.rb index 9f16314619..52a14d0eb6 100644 --- a/lib/rex/java/serialization/model/field.rb +++ b/lib/rex/java/serialization/model/field.rb @@ -105,6 +105,20 @@ module Rex false end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + str = "#{name} " + if is_primitive? + str << "(#{type})" + else + str << "(#{field_type})" + end + + str + end + private # Whether the type opcode is a valid one. diff --git a/lib/rex/java/serialization/model/long_utf.rb b/lib/rex/java/serialization/model/long_utf.rb index fa1296c9dc..2506accf5f 100644 --- a/lib/rex/java/serialization/model/long_utf.rb +++ b/lib/rex/java/serialization/model/long_utf.rb @@ -38,6 +38,7 @@ module Rex encoded end + end end end diff --git a/lib/rex/java/serialization/model/new_array.rb b/lib/rex/java/serialization/model/new_array.rb index e2eb799bc4..829e4aa575 100644 --- a/lib/rex/java/serialization/model/new_array.rb +++ b/lib/rex/java/serialization/model/new_array.rb @@ -8,7 +8,7 @@ module Rex include Rex::Java::Serialization::Model::Contents # @!attribute array_description - # @return [Java::Serialization::Model::ClassDescription] The description of the array + # @return [Java::Serialization::Model::ClassDesc] The description of the array attr_accessor :array_description # @!attribute type # @return [String] The type of the array values @@ -66,6 +66,15 @@ module Rex encoded end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + str = "#{type}, " + values_data = values.collect {|v| "#{v}"} + str << "#{values_data}" + end + private # Deserializes the NewArray length diff --git a/lib/rex/java/serialization/model/new_class_desc.rb b/lib/rex/java/serialization/model/new_class_desc.rb index d11db8c6f5..38350d19e5 100644 --- a/lib/rex/java/serialization/model/new_class_desc.rb +++ b/lib/rex/java/serialization/model/new_class_desc.rb @@ -84,6 +84,27 @@ module Rex encoded end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + str = "#{class_name}, [ " + fields_str = [] + fields.each do |field| + fields_str << field.to_s + end + str << "#{fields_str.join(', ')} ]" + + case super_class.description + when NewClassDesc + str << ", @super_class: #{super_class.description.class_name.to_s}" + when Reference + str << ", @super_class: #{super_class.description.to_s}" + end + + str + end + private # Deserializes a class serial version diff --git a/lib/rex/java/serialization/model/new_enum.rb b/lib/rex/java/serialization/model/new_enum.rb index 3a9a803811..f8fd38022a 100644 --- a/lib/rex/java/serialization/model/new_enum.rb +++ b/lib/rex/java/serialization/model/new_enum.rb @@ -11,7 +11,7 @@ module Rex # @return [Java::Serialization::Model::ClassDescription] The description of the enum attr_accessor :enum_description # @!attribute constant_name - # @return [Array] The constant value in the Java Enum + # @return [Java::Serialization::Model::Utf] The constant value in the Java Enum attr_accessor :constant_name # @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to @@ -50,6 +50,13 @@ module Rex encoded end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + constant_name.to_s + end + private # Deserializes the NewEnum constant name diff --git a/lib/rex/java/serialization/model/new_object.rb b/lib/rex/java/serialization/model/new_object.rb index d89138759d..0ccd29a04a 100644 --- a/lib/rex/java/serialization/model/new_object.rb +++ b/lib/rex/java/serialization/model/new_object.rb @@ -8,7 +8,7 @@ module Rex include Rex::Java::Serialization::Model::Contents # @!attribute class_desc - # @return [Java::Serialization::Model::ClassDescription] The description of the object + # @return [Rex::Java::Serialization::Model::ClassDesc] The description of the object attr_accessor :class_desc # @!attribute class_data # @return [Array] The data of the object @@ -63,6 +63,23 @@ module Rex encoded end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + str = '' + if class_desc.description.class == NewClassDesc + str << class_desc.description.class_name.to_s + elsif class_desc.description.class == Reference + str << (class_desc.description.handle - BASE_WIRE_HANDLE).to_s(16) + end + + str << ' => { ' + data = class_data.collect { |data| data.to_s } + str << data.join(', ') + str << ' }' + end + private # Deserializes the class_data for a class_desc and its super classes diff --git a/lib/rex/java/serialization/model/reference.rb b/lib/rex/java/serialization/model/reference.rb index 8a78be47c6..a1e2fcc083 100644 --- a/lib/rex/java/serialization/model/reference.rb +++ b/lib/rex/java/serialization/model/reference.rb @@ -45,6 +45,13 @@ module Rex encoded end + + # Creates a print-friendly string representation + # + # @return [String] + def to_s + "0x#{handle.to_s(16)}" + end end end end diff --git a/lib/rex/java/serialization/model/stream.rb b/lib/rex/java/serialization/model/stream.rb index 1b7e0787dd..962ff47404 100644 --- a/lib/rex/java/serialization/model/stream.rb +++ b/lib/rex/java/serialization/model/stream.rb @@ -66,6 +66,24 @@ module Rex self.references.push(ref) end + # Creates a print-friendly string representation + # + # @return [String] + def to_s + str = "@magic: 0x#{magic.to_s(16)}\n" + str << "@version: #{version}\n" + str << "@contents: [\n" + contents.each do |content| + str << " #{print_content(content)}\n" + end + str << "]\n" + str << "@references: [\n" + references.each do |ref| + str << " [#{(references.index(ref) + BASE_WIRE_HANDLE).to_s(16)}] #{print_content(ref)}\n" + end + str << "]\n" + end + private # Deserializes the magic stream value diff --git a/lib/rex/java/serialization/model/utf.rb b/lib/rex/java/serialization/model/utf.rb index 9d5fbf1bbb..4ec3fea5bd 100644 --- a/lib/rex/java/serialization/model/utf.rb +++ b/lib/rex/java/serialization/model/utf.rb @@ -53,6 +53,13 @@ module Rex encoded end + + # Creates a print-friendly string representation + # + # @return [String] + def to_s + contents + end end end end diff --git a/spec/lib/rex/java/serialization/model/annotation_spec.rb b/spec/lib/rex/java/serialization/model/annotation_spec.rb index b8ef4a064a..3eb5839aa4 100644 --- a/spec/lib/rex/java/serialization/model/annotation_spec.rb +++ b/spec/lib/rex/java/serialization/model/annotation_spec.rb @@ -86,4 +86,17 @@ describe Rex::Java::Serialization::Model::Annotation do end end + + describe "#to_s" do + it "prints an empty annotation" do + annotation.decode(empty_contents_io) + expect(annotation.to_s).to eq('[ EndBlockData ]') + end + + it "prints an annotation with contents" do + annotation.decode(contents_io) + expect(annotation.to_s).to eq('[ BlockData { [ 0x1, 0x2, 0x3, 0x4, 0x5 ] }, BlockDataLong { [ 0x1, 0x2, 0x3, 0x4, 0x5 ] }, EndBlockData ]') + end + end + end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/block_data_long_spec.rb b/spec/lib/rex/java/serialization/model/block_data_long_spec.rb index 250bd8cf5b..21306c7663 100644 --- a/spec/lib/rex/java/serialization/model/block_data_long_spec.rb +++ b/spec/lib/rex/java/serialization/model/block_data_long_spec.rb @@ -87,5 +87,18 @@ describe Rex::Java::Serialization::Model::BlockDataLong do expect(block.contents).to eq("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10") end end + + describe "#to_s" do + it "prints a block with contents" do + block.decode(sample_block_io) + expect(block.to_s).to eq('[ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10 ]') + end + + it "prints an empty string for an empty block" do + block.decode(empty_block_io) + expect(block.to_s).to eq('[ ]') + end + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/block_data_spec.rb b/spec/lib/rex/java/serialization/model/block_data_spec.rb index 77d23cd3a4..9d30b0f9b7 100644 --- a/spec/lib/rex/java/serialization/model/block_data_spec.rb +++ b/spec/lib/rex/java/serialization/model/block_data_spec.rb @@ -88,4 +88,16 @@ describe Rex::Java::Serialization::Model::BlockData do end end end + + describe "#to_s" do + it "prints a block with contents" do + block.decode(sample_block_io) + expect(block.to_s).to eq('[ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10 ]') + end + + it "prints an empty string for an empty block" do + block.decode(empty_block_io) + expect(block.to_s).to eq('[ ]') + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/class_desc_spec.rb b/spec/lib/rex/java/serialization/model/class_desc_spec.rb index 7d0c44d13f..82c4b8016c 100644 --- a/spec/lib/rex/java/serialization/model/class_desc_spec.rb +++ b/spec/lib/rex/java/serialization/model/class_desc_spec.rb @@ -68,4 +68,11 @@ describe Rex::Java::Serialization::Model::ClassDesc do expect(class_desc.encode.unpack("C*")).to eq(sample.unpack("C*")) end end + + describe "#to_s" do + it "prints a sample ClassDesc" do + class_desc.decode(sample_io) + expect(class_desc.to_s).to be_a(String) + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/field_spec.rb b/spec/lib/rex/java/serialization/model/field_spec.rb index 0e54883171..417538f337 100644 --- a/spec/lib/rex/java/serialization/model/field_spec.rb +++ b/spec/lib/rex/java/serialization/model/field_spec.rb @@ -90,4 +90,16 @@ describe Rex::Java::Serialization::Model::Field do end end end + + describe "#to_s" do + it "prints an stream containing a primitive field" do + field.decode(sample_primitive_io) + expect(field.to_s).to eq('number (int)') + end + + it "prints an stream containing an object field" do + field.decode(sample_object_io) + expect(field.to_s).to eq('test_array ([LEmployee;)') + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/long_utf_spec.rb b/spec/lib/rex/java/serialization/model/long_utf_spec.rb index 74889b9001..64cddbf8b7 100644 --- a/spec/lib/rex/java/serialization/model/long_utf_spec.rb +++ b/spec/lib/rex/java/serialization/model/long_utf_spec.rb @@ -87,6 +87,18 @@ describe Rex::Java::Serialization::Model::LongUtf do expect(long_utf.contents).to eq('java.lang.Number') end end + + describe "#to_s" do + it "prints an stream containing a sample long utf" do + long_utf.decode(sample_utf_io) + expect(long_utf.to_s).to eq('java.lang.Number') + end + + it "prints an stream containing an empty long utf" do + long_utf.decode(empty_utf_io) + expect(long_utf.to_s).to eq('') + end + end end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/new_array_spec.rb b/spec/lib/rex/java/serialization/model/new_array_spec.rb index 68045246c6..f65d6cc827 100644 --- a/spec/lib/rex/java/serialization/model/new_array_spec.rb +++ b/spec/lib/rex/java/serialization/model/new_array_spec.rb @@ -414,7 +414,53 @@ describe Rex::Java::Serialization::Model::NewArray do expect(new_array.encode.unpack("C*")).to eq(string_array.unpack("C*")) end + end + describe "#to_s" do + it "prints a boolean array stream" do + new_array.decode(boolean_array_io) + expect(new_array.to_s).to eq('boolean, ["1", "0", "1", "1", "1", "1", "1", "1", "1", "0"]') + end + + it "prints a byte array stream" do + new_array.decode(byte_array_io) + expect(new_array.to_s).to eq('byte, ["-20", "65"]') + end + + it "prints a char array stream" do + new_array.decode(char_array_io) + expect(new_array.to_s).to eq('char, ["97", "98"]') + end + + it "prints a short array stream" do + new_array.decode(short_array_io) + expect(new_array.to_s).to eq('short, ["-20", "65"]') + end + + it "prints a double array stream" do + new_array.decode(double_array_io) + expect(new_array.to_s).to eq('double, ["0.25", "0.21"]') + end + + it "prints a float array stream" do + new_array.decode(float_array_io) + expect(new_array.to_s).to eq('float, ["1.0", "2.0"]') + end + + it "prints a int array stream" do + new_array.decode(int_array_io) + expect(new_array.to_s).to eq('int, ["-20", "65"]') + end + + it "prints a long array stream" do + new_array.decode(long_array_io) + expect(new_array.to_s).to eq('long, ["-20", "65"]') + end + + it "prints a string array stream" do + new_array.decode(string_array_io) + expect(new_array.to_s).to eq('java.lang.String;, ["msf"]') + end end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/new_class_desc_spec.rb b/spec/lib/rex/java/serialization/model/new_class_desc_spec.rb index d3c7b03683..362386df2f 100644 --- a/spec/lib/rex/java/serialization/model/new_class_desc_spec.rb +++ b/spec/lib/rex/java/serialization/model/new_class_desc_spec.rb @@ -130,4 +130,11 @@ describe Rex::Java::Serialization::Model::NewClassDesc do expect(class_desc_new.encode.unpack("C*")).to eq(sample.unpack("C*")) end end + + describe "#to_s" do + it "prints a sample NewClassDesc stream" do + class_desc_new.decode(sample_io) + expect(class_desc_new.to_s).to eq('java.lang.Byte, [ value (byte) ], @super_class: java.lang.Number') + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/new_enum_spec.rb b/spec/lib/rex/java/serialization/model/new_enum_spec.rb index 16e0993cb1..7146aec785 100644 --- a/spec/lib/rex/java/serialization/model/new_enum_spec.rb +++ b/spec/lib/rex/java/serialization/model/new_enum_spec.rb @@ -71,4 +71,10 @@ describe Rex::Java::Serialization::Model::NewEnum do end end + describe "#to_s" do + it "prints a sample NewEnum stream" do + new_enum.decode(sample_enum_io) + expect(new_enum.to_s).to eq('SUNDAY') + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/new_object_spec.rb b/spec/lib/rex/java/serialization/model/new_object_spec.rb index 9e04af9c1d..15d0d302cc 100644 --- a/spec/lib/rex/java/serialization/model/new_object_spec.rb +++ b/spec/lib/rex/java/serialization/model/new_object_spec.rb @@ -70,4 +70,10 @@ describe Rex::Java::Serialization::Model::NewObject do end end + describe "#to_s" do + it "prints a sample Object stream" do + new_object.decode(easy_object_io) + expect(new_object.to_s).to eq('Easy => { ["int", 1094861636] }') + end + end end \ No newline at end of file diff --git a/spec/lib/rex/java/serialization/model/stream_spec.rb b/spec/lib/rex/java/serialization/model/stream_spec.rb index 4215fbbe81..1205bd0aea 100644 --- a/spec/lib/rex/java/serialization/model/stream_spec.rb +++ b/spec/lib/rex/java/serialization/model/stream_spec.rb @@ -15,6 +15,19 @@ describe Rex::Java::Serialization::Model::Stream do "\x42\x43\x44" end let(:easy_object_stream_io) { StringIO.new(easy_object_stream) } + let(:easy_object_stream_to_s) { + <<-EOS +@magic: 0xaced +@version: 5 +@contents: [ + NewObject { Easy => { ["int", 1094861636] } } +] +@references: [ + [7e0000] NewClassDesc { Easy, [ SSN (int) ] } + [7e0001] NewObject { Easy => { ["int", 1094861636] } } +] + EOS + } let(:char_array_stream) do "\xac\xed\x00\x05\x75\x72\x00\x02" + @@ -23,6 +36,19 @@ describe Rex::Java::Serialization::Model::Stream do "\x00\x00\x02\x00\x61\x00\x62" end let(:char_array_stream_io) { StringIO.new(char_array_stream) } + let(:char_array_stream_to_s) { + <<-EOS +@magic: 0xaced +@version: 5 +@contents: [ + NewArray { char, ["97", "98"] } +] +@references: [ + [7e0000] NewClassDesc { [C, [ ] } + [7e0001] NewArray { char, ["97", "98"] } +] + EOS + } let(:complex_stream) do "\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00" + @@ -56,6 +82,36 @@ describe Rex::Java::Serialization::Model::Stream do "\xc1\xc0" end let(:complex_stream_io) { StringIO.new(complex_stream) } + let(:complex_stream_to_s) { + <<-EOS +@magic: 0xaced +@version: 5 +@contents: [ + BlockData { [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xf6, 0xb6, 0x89, 0x8d, 0x8b, 0xf2, 0x86, 0x43 ] } + NewArray { java.rmi.server.ObjID;, ["java.rmi.server.ObjID => { [\\"long\\", 991106561224880050], java.rmi.server.UID => { [\\"short\\", -32746], [\\"long\\", 1416095896184], [\\"int\\", -766517433] } }"] } + BlockData { [ 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 ] } + NewObject { java.rmi.dgc.Lease => { ["long", 600000], java.rmi.dgc.VMID => { byte, ["107", "2", "-57", "114", "96", "28", "-57", "-107"], 5 => { ["short", -32767], ["long", 1416097169642], ["int", -379403840] } } } } +] +@references: [ + [7e0000] NewClassDesc { [Ljava.rmi.server.ObjID;, [ ] } + [7e0001] NewArray { java.rmi.server.ObjID;, ["java.rmi.server.ObjID => { [\\"long\\", 991106561224880050], java.rmi.server.UID => { [\\"short\\", -32746], [\\"long\\", 1416095896184], [\\"int\\", -766517433] } }"] } + [7e0002] NewClassDesc { java.rmi.server.ObjID, [ objNum (long), space (Ljava/rmi/server/UID;) ] } + [7e0003] Utf { Ljava/rmi/server/UID; } + [7e0004] NewObject { java.rmi.server.ObjID => { ["long", 991106561224880050], java.rmi.server.UID => { ["short", -32746], ["long", 1416095896184], ["int", -766517433] } } } + [7e0005] NewClassDesc { java.rmi.server.UID, [ count (short), time (long), unique (int) ] } + [7e0006] NewObject { java.rmi.server.UID => { ["short", -32746], ["long", 1416095896184], ["int", -766517433] } } + [7e0007] NewClassDesc { java.rmi.dgc.Lease, [ value (long), vmid (Ljava/rmi/dgc/VMID;) ] } + [7e0008] Utf { Ljava/rmi/dgc/VMID; } + [7e0009] NewObject { java.rmi.dgc.Lease => { ["long", 600000], java.rmi.dgc.VMID => { byte, ["107", "2", "-57", "114", "96", "28", "-57", "-107"], 5 => { ["short", -32767], ["long", 1416097169642], ["int", -379403840] } } } } + [7e000a] NewClassDesc { java.rmi.dgc.VMID, [ addr ([B), uid (0x7e0003) ] } + [7e000b] Utf { [B } + [7e000c] NewObject { java.rmi.dgc.VMID => { byte, ["107", "2", "-57", "114", "96", "28", "-57", "-107"], 5 => { ["short", -32767], ["long", 1416097169642], ["int", -379403840] } } } + [7e000d] NewClassDesc { [B, [ ] } + [7e000e] NewArray { byte, ["107", "2", "-57", "114", "96", "28", "-57", "-107"] } + [7e000f] NewObject { 5 => { ["short", -32767], ["long", 1416097169642], ["int", -379403840] } } +] + EOS + } describe ".new" do it "Rex::Java::Serialization::Model::Stream" do @@ -129,6 +185,23 @@ describe Rex::Java::Serialization::Model::Stream do end end + describe "#to_s" do + it "prints a simple Object stream" do + stream.decode(easy_object_stream_io) + expect(stream.to_s).to eq(easy_object_stream_to_s) + end + + it "prints a char array stream" do + stream.decode(char_array_stream_io) + expect(stream.to_s).to eq(char_array_stream_to_s) + end + + it "prints a complex stream with references" do + stream.decode(complex_stream_io) + expect(stream.to_s).to eq(complex_stream_to_s) + end + end + describe "#encode" do context "when serializing a simple Object stream" do it "serializes the Stream" do diff --git a/spec/lib/rex/java/serialization/model/utf_spec.rb b/spec/lib/rex/java/serialization/model/utf_spec.rb index a30275406e..79d4720939 100644 --- a/spec/lib/rex/java/serialization/model/utf_spec.rb +++ b/spec/lib/rex/java/serialization/model/utf_spec.rb @@ -88,4 +88,17 @@ describe Rex::Java::Serialization::Model::Utf do end end end + + describe "#to_s" do + it "prints an stream containing a sample utf" do + utf.decode(sample_utf_io) + expect(utf.to_s).to eq('java.lang.Number') + end + + it "prints an stream containing an empty utf" do + utf.decode(empty_utf_io) + expect(utf.to_s).to eq('') + end + end + end \ No newline at end of file diff --git a/tools/java_deserializer.rb b/tools/java_deserializer.rb index 30df0ea4d3..b78d2a3cf3 100755 --- a/tools/java_deserializer.rb +++ b/tools/java_deserializer.rb @@ -49,7 +49,7 @@ class JavaDeserializer return end - pp(stream) + puts stream end private