From 8590c790219bd611a540f4200a28a519bf16e2c6 Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Wed, 30 Sep 2015 12:30:52 -0500 Subject: [PATCH 1/2] Add support for NewClass --- lib/rex/java/serialization/model.rb | 1 + lib/rex/java/serialization/model/contents.rb | 6 ++++-- lib/rex/java/serialization/model/new_object.rb | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rex/java/serialization/model.rb b/lib/rex/java/serialization/model.rb index a5587660fd..1f2d6cf0de 100644 --- a/lib/rex/java/serialization/model.rb +++ b/lib/rex/java/serialization/model.rb @@ -19,6 +19,7 @@ module Rex autoload :NewClassDesc, 'rex/java/serialization/model/new_class_desc' autoload :NewEnum, 'rex/java/serialization/model/new_enum' autoload :NewObject, 'rex/java/serialization/model/new_object' + autoload :NewClass, 'rex/java/serialization/model/new_class' autoload :NullReference, 'rex/java/serialization/model/null_reference' autoload :Reference, 'rex/java/serialization/model/reference' autoload :Reset, 'rex/java/serialization/model/reset' diff --git a/lib/rex/java/serialization/model/contents.rb b/lib/rex/java/serialization/model/contents.rb index 1f70781ff2..b13ceb7cdc 100644 --- a/lib/rex/java/serialization/model/contents.rb +++ b/lib/rex/java/serialization/model/contents.rb @@ -28,7 +28,7 @@ module Rex when TC_OBJECT content = NewObject.decode(io, stream) when TC_CLASS - content = ClassDesc.decode(io, stream) + content = NewClass.decode(io, stream) when TC_ARRAY content = NewArray.decode(io, stream) when TC_STRING @@ -75,7 +75,7 @@ module Rex encoded << [TC_ENDBLOCKDATA].pack('C') when NewObject encoded << [TC_OBJECT].pack('C') - when ClassDesc + when NewClass encoded << [TC_CLASS].pack('C') when NewArray encoded << [TC_ARRAY].pack('C') @@ -122,6 +122,8 @@ module Rex str << "#{print_class(content)} { #{content.to_s} }" when ClassDesc str << "#{print_class(content)} { #{content.to_s} }" + when NewClass + str << "#{print_class(content)} { #{content.to_s} }" when NewArray str << "#{print_class(content)} { #{content.to_s} }" when Utf diff --git a/lib/rex/java/serialization/model/new_object.rb b/lib/rex/java/serialization/model/new_object.rb index 9b84548cb2..288dfd00e4 100644 --- a/lib/rex/java/serialization/model/new_object.rb +++ b/lib/rex/java/serialization/model/new_object.rb @@ -71,6 +71,7 @@ module Rex # @return [String] def to_s str = '' + case class_desc.description when NewClassDesc str << class_desc.description.class_name.to_s @@ -84,6 +85,8 @@ module Rex data_str = class_data.collect { |data| data.to_s } str << data_str.join(', ') str << ' }' + + str end private From bfbd6ad475c381958d86152a7800473d9b9a0adc Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Wed, 30 Sep 2015 12:31:18 -0500 Subject: [PATCH 2/2] Add the NewClass code really --- lib/rex/java/serialization/model/new_class.rb | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/rex/java/serialization/model/new_class.rb diff --git a/lib/rex/java/serialization/model/new_class.rb b/lib/rex/java/serialization/model/new_class.rb new file mode 100644 index 0000000000..c3984cae56 --- /dev/null +++ b/lib/rex/java/serialization/model/new_class.rb @@ -0,0 +1,57 @@ +# -*- coding: binary -*- + +module Rex + module Java + module Serialization + module Model + # This class provides a NewArray (Java Array) representation + class NewClass < Element + + include Rex::Java::Serialization::Model::Contents + + # @!attribute array_description + # @return [Java::Serialization::Model::ClassDesc] The description of the class + attr_accessor :class_description + + # @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to + def initialize(stream = nil) + super(stream) + self.class_description = nil + end + + # Deserializes a Rex::Java::Serialization::Model::NewClass + # + # @param io [IO] the io to read from + # @return [self] if deserialization succeeds + # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed + def decode(io) + self.class_description = ClassDesc.decode(io, stream) + stream.add_reference(self) unless stream.nil? + + self + end + + # Serializes the Rex::Java::Serialization::Model::NewClass + # + # @return [String] if serialization succeeds + # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed + def encode + unless class_description.kind_of?(ClassDesc) + raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewClass' + end + + encoded = '' + encoded << class_description.encode + end + + # Creates a print-friendly string representation + # + # @return [String] + def to_s + print_content(class_description) + end + end + end + end + end +end