rex 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rex.rb +1 -0
  3. data/lib/rex/arch.rb +5 -0
  4. data/lib/rex/arch/x86.rb +19 -5
  5. data/lib/rex/arch/zarch.rb +17 -0
  6. data/lib/rex/compat.rb +5 -4
  7. data/lib/rex/constants.rb +3 -1
  8. data/lib/rex/encoder/alpha2/alpha_mixed.rb +70 -9
  9. data/lib/rex/encoder/alpha2/alpha_upper.rb +67 -8
  10. data/lib/rex/exploitation/cmdstager.rb +1 -0
  11. data/lib/rex/exploitation/cmdstager/certutil.rb +115 -0
  12. data/lib/rex/exploitation/cmdstager/echo.rb +6 -3
  13. data/lib/rex/exploitation/egghunter.rb +1 -1
  14. data/lib/rex/google/geolocation.rb +68 -0
  15. data/lib/rex/io/bidirectional_pipe.rb +0 -4
  16. data/lib/rex/java/serialization.rb +2 -0
  17. data/lib/rex/java/serialization/decode_error.rb +11 -0
  18. data/lib/rex/java/serialization/encode_error.rb +11 -0
  19. data/lib/rex/java/serialization/model.rb +2 -0
  20. data/lib/rex/java/serialization/model/annotation.rb +3 -3
  21. data/lib/rex/java/serialization/model/block_data.rb +3 -3
  22. data/lib/rex/java/serialization/model/block_data_long.rb +3 -3
  23. data/lib/rex/java/serialization/model/class_desc.rb +6 -6
  24. data/lib/rex/java/serialization/model/contents.rb +17 -10
  25. data/lib/rex/java/serialization/model/field.rb +12 -11
  26. data/lib/rex/java/serialization/model/long_utf.rb +3 -3
  27. data/lib/rex/java/serialization/model/new_array.rb +22 -23
  28. data/lib/rex/java/serialization/model/new_class.rb +57 -0
  29. data/lib/rex/java/serialization/model/new_class_desc.rb +15 -16
  30. data/lib/rex/java/serialization/model/new_enum.rb +5 -5
  31. data/lib/rex/java/serialization/model/new_object.rb +22 -17
  32. data/lib/rex/java/serialization/model/proxy_class_desc.rb +109 -0
  33. data/lib/rex/java/serialization/model/reference.rb +4 -4
  34. data/lib/rex/java/serialization/model/stream.rb +7 -7
  35. data/lib/rex/java/serialization/model/utf.rb +3 -3
  36. data/lib/rex/json_hash_file.rb +94 -0
  37. data/lib/rex/logging/log_sink.rb +1 -0
  38. data/lib/rex/logging/sinks/timestamp_flatfile.rb +21 -0
  39. data/lib/rex/parser/appscan_nokogiri.rb +13 -23
  40. data/lib/rex/parser/fs/ntfs.rb +10 -5
  41. data/lib/rex/parser/nmap_nokogiri.rb +3 -1
  42. data/lib/rex/parser/openvas_nokogiri.rb +70 -73
  43. data/lib/rex/parser/winscp.rb +108 -0
  44. data/lib/rex/parser/x509_certificate.rb +92 -0
  45. data/lib/rex/payloads.rb +0 -1
  46. data/lib/rex/payloads/meterpreter/config.rb +154 -0
  47. data/lib/rex/payloads/meterpreter/uri_checksum.rb +136 -0
  48. data/lib/rex/post/meterpreter.rb +1 -1
  49. data/lib/rex/post/meterpreter/client.rb +26 -3
  50. data/lib/rex/post/meterpreter/client_core.rb +387 -75
  51. data/lib/rex/post/meterpreter/extensions/android/android.rb +127 -37
  52. data/lib/rex/post/meterpreter/extensions/android/tlv.rb +46 -25
  53. data/lib/rex/post/meterpreter/extensions/extapi/extapi.rb +4 -0
  54. data/lib/rex/post/meterpreter/extensions/extapi/ntds/ntds.rb +39 -0
  55. data/lib/rex/post/meterpreter/extensions/extapi/pageant/pageant.rb +44 -0
  56. data/lib/rex/post/meterpreter/extensions/extapi/tlv.rb +9 -0
  57. data/lib/rex/post/meterpreter/extensions/kiwi/kiwi.rb +16 -1
  58. data/lib/rex/post/meterpreter/extensions/priv/priv.rb +1 -1
  59. data/lib/rex/post/meterpreter/extensions/python/python.rb +114 -0
  60. data/lib/rex/post/meterpreter/extensions/python/tlv.rb +21 -0
  61. data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +17 -14
  62. data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +33 -12
  63. data/lib/rex/post/meterpreter/extensions/stdapi/fs/mount.rb +57 -0
  64. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_kernel32.rb +3 -3
  65. data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +3 -1
  66. data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +2 -0
  67. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +16 -3
  68. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +29 -6
  69. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +5 -1
  70. data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +18 -6
  71. data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +2 -2
  72. data/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +34 -36
  73. data/lib/rex/post/meterpreter/packet.rb +29 -0
  74. data/lib/rex/post/meterpreter/packet_dispatcher.rb +20 -7
  75. data/lib/rex/post/meterpreter/ui/console.rb +1 -0
  76. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb +230 -72
  77. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +544 -34
  78. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb +188 -57
  79. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/kiwi.rb +115 -93
  80. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb +1 -1
  81. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/mimikatz.rb +1 -1
  82. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +49 -15
  83. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +11 -2
  84. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/python.rb +187 -0
  85. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +324 -133
  86. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +52 -2
  87. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +68 -65
  88. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +9 -1
  89. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +113 -118
  90. data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +3 -0
  91. data/lib/rex/powershell.rb +62 -0
  92. data/lib/rex/powershell/command.rb +359 -0
  93. data/lib/rex/{exploitation/powershell → powershell}/function.rb +0 -2
  94. data/lib/rex/{exploitation/powershell → powershell}/obfu.rb +0 -2
  95. data/lib/rex/{exploitation/powershell → powershell}/output.rb +11 -5
  96. data/lib/rex/{exploitation/powershell → powershell}/param.rb +0 -2
  97. data/lib/rex/powershell/parser.rb +182 -0
  98. data/lib/rex/powershell/payload.rb +78 -0
  99. data/lib/rex/{exploitation/powershell → powershell}/psh_methods.rb +16 -2
  100. data/lib/rex/{exploitation/powershell → powershell}/script.rb +2 -4
  101. data/lib/rex/proto/dcerpc/client.rb +6 -6
  102. data/lib/rex/proto/dcerpc/exceptions.rb +26 -0
  103. data/lib/rex/proto/http/client.rb +3 -3
  104. data/lib/rex/proto/http/client_request.rb +0 -5
  105. data/lib/rex/proto/http/response.rb +86 -0
  106. data/lib/rex/proto/ipmi/utils.rb +30 -26
  107. data/lib/rex/proto/kerberos/client.rb +1 -1
  108. data/lib/rex/proto/kerberos/model/kdc_request.rb +2 -2
  109. data/lib/rex/proto/rfb/client.rb +8 -3
  110. data/lib/rex/proto/rfb/constants.rb +1 -1
  111. data/lib/rex/proto/rmi.rb +2 -0
  112. data/lib/rex/proto/rmi/decode_error.rb +10 -0
  113. data/lib/rex/proto/rmi/exception.rb +10 -0
  114. data/lib/rex/proto/rmi/model.rb +5 -0
  115. data/lib/rex/proto/rmi/model/call.rb +4 -4
  116. data/lib/rex/proto/rmi/model/call_data.rb +137 -0
  117. data/lib/rex/proto/rmi/model/dgc_ack.rb +2 -2
  118. data/lib/rex/proto/rmi/model/element.rb +26 -11
  119. data/lib/rex/proto/rmi/model/output_header.rb +4 -4
  120. data/lib/rex/proto/rmi/model/ping.rb +2 -2
  121. data/lib/rex/proto/rmi/model/ping_ack.rb +2 -2
  122. data/lib/rex/proto/rmi/model/protocol_ack.rb +2 -2
  123. data/lib/rex/proto/rmi/model/return_data.rb +5 -5
  124. data/lib/rex/proto/rmi/model/return_value.rb +124 -0
  125. data/lib/rex/proto/rmi/model/unique_identifier.rb +77 -0
  126. data/lib/rex/proto/steam.rb +3 -0
  127. data/lib/rex/proto/steam/message.rb +125 -0
  128. data/lib/rex/proto/tftp/client.rb +35 -14
  129. data/lib/rex/random_identifier_generator.rb +2 -0
  130. data/lib/rex/ropbuilder.rb +1 -1
  131. data/lib/rex/socket/parameters.rb +9 -0
  132. data/lib/rex/socket/ssl_tcp.rb +25 -41
  133. data/lib/rex/socket/ssl_tcp_server.rb +10 -21
  134. data/lib/rex/sslscan/result.rb +20 -1
  135. data/lib/rex/text.rb +241 -55
  136. data/lib/rex/ui/output.rb +0 -3
  137. data/lib/rex/ui/subscriber.rb +0 -10
  138. data/lib/rex/ui/text/color.rb +9 -0
  139. data/lib/rex/ui/text/dispatcher_shell.rb +1 -0
  140. data/lib/rex/ui/text/output.rb +15 -4
  141. data/lib/rex/ui/text/output/file.rb +1 -0
  142. data/lib/rex/ui/text/output/stdio.rb +0 -16
  143. data/lib/rex/ui/text/shell.rb +3 -0
  144. data/lib/rex/ui/text/table.rb +85 -19
  145. data/lib/rex/user_agent.rb +118 -0
  146. data/rex.gemspec +2 -2
  147. metadata +41 -14
  148. data/lib/rex/exploitation/powershell.rb +0 -62
  149. data/lib/rex/exploitation/powershell/parser.rb +0 -183
  150. data/lib/rex/payloads/meterpreter.rb +0 -2
  151. data/lib/rex/payloads/meterpreter/patch.rb +0 -136
@@ -11,11 +11,11 @@ module Rex
11
11
  #
12
12
  # @param io [IO] the io to read from
13
13
  # @return [self] if deserialization succeeds
14
- # @return [nil] if deserialization doesn't succeed
14
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
15
15
  def decode(io)
16
16
  raw_length = io.read(8)
17
17
  if raw_length.nil? || raw_length.length != 8
18
- raise ::RuntimeError, 'Failed to unserialize LongUtf'
18
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize LongUtf'
19
19
  end
20
20
  self.length = raw_length.unpack('Q>')[0]
21
21
 
@@ -24,7 +24,7 @@ module Rex
24
24
  else
25
25
  self.contents = io.read(length)
26
26
  if contents.nil? || contents.length != length
27
- raise ::RuntimeError, 'Failed to unserialize LongUtf'
27
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize LongUtf'
28
28
  end
29
29
  end
30
30
 
@@ -31,7 +31,7 @@ module Rex
31
31
  #
32
32
  # @param io [IO] the io to read from
33
33
  # @return [self] if deserialization succeeds
34
- # @raise [RuntimeError] if deserialization doesn't succeed
34
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
35
35
  def decode(io)
36
36
  self.array_description = ClassDesc.decode(io, stream)
37
37
  stream.add_reference(self) unless stream.nil?
@@ -50,10 +50,10 @@ module Rex
50
50
  # Serializes the Rex::Java::Serialization::Model::NewArray
51
51
  #
52
52
  # @return [String] if serialization succeeds
53
- # @raise [RuntimeError] if serialization doesn't succeed
53
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
54
54
  def encode
55
55
  unless array_description.kind_of?(ClassDesc)
56
- raise ::RuntimeError, 'Failed to serialize NewArray'
56
+ raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewArray'
57
57
  end
58
58
 
59
59
  encoded = ''
@@ -83,11 +83,11 @@ module Rex
83
83
  #
84
84
  # @param io [IO] the io to read from
85
85
  # @return [Integer] if deserialization succeeds
86
- # @raise [RuntimeError] if deserialization doesn't succeed
86
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
87
87
  def decode_values_length(io)
88
88
  values_length = io.read(4)
89
89
  if values_length.nil? || values_length.length != 4
90
- raise ::RuntimeError, 'Failed to unserialize NewArray'
90
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize NewArray'
91
91
  end
92
92
 
93
93
  values_length.unpack('N')[0]
@@ -96,15 +96,15 @@ module Rex
96
96
  # Extracts the NewArray data type
97
97
  #
98
98
  # @return [String]
99
- # @raise [RuntimeError] if the NewArray description isn't valid
100
- # @raise [RuntimeError] if the NewArray type isn't supported
99
+ # @raise [Rex::Java::Serialization::DecodeError] if the NewArray description isn't valid
100
+ # or type isn't supported
101
101
  def array_type
102
102
  if array_description.nil?
103
- raise ::RuntimeError, 'Empty NewArray description'
103
+ raise Rex::Java::Serialization::DecodeError, 'Empty NewArray description'
104
104
  end
105
105
 
106
106
  unless array_description.kind_of?(ClassDesc)
107
- raise ::RuntimeError, 'Unsupported NewArray description class'
107
+ raise Rex::Java::Serialization::DecodeError, 'Unsupported NewArray description class'
108
108
  end
109
109
 
110
110
  desc = array_description.description
@@ -115,7 +115,7 @@ module Rex
115
115
  end
116
116
 
117
117
  unless desc.class_name.contents[0] == '[' # Array
118
- raise ::RuntimeError, 'Unsupported NewArray description'
118
+ raise Rex::Java::Serialization::DecodeError, 'Unsupported NewArray description'
119
119
  end
120
120
 
121
121
  decoded_type = desc.class_name.contents[1]
@@ -124,7 +124,7 @@ module Rex
124
124
  elsif decoded_type == 'L' # L : Object
125
125
  return desc.class_name.contents[2..desc.class_name.contents.index(';')] # Object class
126
126
  else
127
- raise ::RuntimeError, 'Unsupported NewArray Type'
127
+ raise Rex::Java::Serialization::DecodeError, 'Unsupported NewArray Type'
128
128
  end
129
129
  end
130
130
 
@@ -132,54 +132,54 @@ module Rex
132
132
  #
133
133
  # @param io [IO] the io to read from
134
134
  # @return [Fixnum, Float] if deserialization succeeds
135
- # @raise [RuntimeError] if deserialization fails
135
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization fails
136
136
  def decode_value(io)
137
137
  value = nil
138
138
 
139
139
  case type
140
140
  when 'byte'
141
141
  value = io.read(1)
142
- raise ::RuntimeError, 'Failed to deserialize NewArray value' if value.nil?
142
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value' if value.nil?
143
143
  value = value.unpack('c')[0]
144
144
  when 'char'
145
145
  value = io.read(2)
146
146
  unless value && value.length == 2
147
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
147
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
148
148
  end
149
149
  value = value.unpack('s>')[0]
150
150
  when 'double'
151
151
  value = io.read(8)
152
152
  unless value && value.length == 8
153
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
153
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
154
154
  end
155
155
  value = value.unpack('G')[0]
156
156
  when 'float'
157
157
  value = io.read(4)
158
158
  unless value && value.length == 4
159
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
159
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
160
160
  end
161
161
  value = value.unpack('g')[0]
162
162
  when 'int'
163
163
  value = io.read(4)
164
164
  unless value && value.length == 4
165
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
165
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
166
166
  end
167
167
  value = value.unpack('l>')[0]
168
168
  when 'long'
169
169
  value = io.read(8)
170
170
  unless value && value.length == 8
171
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
171
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
172
172
  end
173
173
  value = value.unpack('q>')[0]
174
174
  when 'short'
175
175
  value = io.read(2)
176
176
  unless value && value.length == 2
177
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
177
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
178
178
  end
179
179
  value = value.unpack('s>')[0]
180
180
  when 'boolean'
181
181
  value = io.read(1)
182
- raise ::RuntimeError, 'Failed to deserialize NewArray value' if value.nil?
182
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value' if value.nil?
183
183
  value = value.unpack('c')[0]
184
184
  else # object
185
185
  value = decode_content(io, stream)
@@ -190,10 +190,9 @@ module Rex
190
190
 
191
191
  # Serializes an NewArray value
192
192
  #
193
- # @param value [Fixnum] the value to serialize
194
- # @param value [Float] the value to serialize
193
+ # @param value [<Fixnum, Float>] the value to serialize
195
194
  # @return [String] the serialized value
196
- # @raise [RuntimeError] if serialization fails
195
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization fails
197
196
  def encode_value(value)
198
197
  res = ''
199
198
 
@@ -0,0 +1,57 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ module Serialization
6
+ module Model
7
+ # This class provides a NewArray (Java Array) representation
8
+ class NewClass < Element
9
+
10
+ include Rex::Java::Serialization::Model::Contents
11
+
12
+ # @!attribute array_description
13
+ # @return [Java::Serialization::Model::ClassDesc] The description of the class
14
+ attr_accessor :class_description
15
+
16
+ # @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
17
+ def initialize(stream = nil)
18
+ super(stream)
19
+ self.class_description = nil
20
+ end
21
+
22
+ # Deserializes a Rex::Java::Serialization::Model::NewClass
23
+ #
24
+ # @param io [IO] the io to read from
25
+ # @return [self] if deserialization succeeds
26
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
27
+ def decode(io)
28
+ self.class_description = ClassDesc.decode(io, stream)
29
+ stream.add_reference(self) unless stream.nil?
30
+
31
+ self
32
+ end
33
+
34
+ # Serializes the Rex::Java::Serialization::Model::NewClass
35
+ #
36
+ # @return [String] if serialization succeeds
37
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
38
+ def encode
39
+ unless class_description.kind_of?(ClassDesc)
40
+ raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewClass'
41
+ end
42
+
43
+ encoded = ''
44
+ encoded << class_description.encode
45
+ end
46
+
47
+ # Creates a print-friendly string representation
48
+ #
49
+ # @return [String]
50
+ def to_s
51
+ print_content(class_description)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -12,16 +12,16 @@ module Rex
12
12
  # @!attribute class_name
13
13
  # @return [Rex::Java::Serialization::Model::Utf] The name of the class
14
14
  attr_accessor :class_name
15
- # @!attribute name
16
- # @return [Integer] The java class serial version
15
+ # @!attribute serial_version
16
+ # @return [Fixnum] The java class serial version
17
17
  attr_accessor :serial_version
18
18
  # @!attribute flags
19
- # @return [Integer] The java class flags
19
+ # @return [Fixnum] The java class flags
20
20
  attr_accessor :flags
21
21
  # @!attribute fields
22
22
  # @return [Array] The java class fields
23
23
  attr_accessor :fields
24
- # @!attribute fields
24
+ # @!attribute class_annotation
25
25
  # @return [Rex::Java::Serialization::Model::Annotation] The java class annotations
26
26
  attr_accessor :class_annotation
27
27
  # @!attribute super_class
@@ -39,11 +39,11 @@ module Rex
39
39
  self.super_class = nil
40
40
  end
41
41
 
42
- # Deserializes a Rex::Java::Serialization::Model::ClassDescription
42
+ # Deserializes a Rex::Java::Serialization::Model::NewClassDesc
43
43
  #
44
44
  # @param io [IO] the io to read from
45
45
  # @return [self] if deserialization succeeds
46
- # @raise [RuntimeError] if deserialization doesn't succeed
46
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
47
47
  def decode(io)
48
48
  self.class_name = Utf.decode(io, stream)
49
49
  self.serial_version = decode_serial_version(io)
@@ -64,17 +64,16 @@ module Rex
64
64
  # Serializes the Rex::Java::Serialization::Model::ClassDescription
65
65
  #
66
66
  # @return [String] if serialization succeeds
67
- # @raise [RuntimeError] if serialization doesn't succeed
67
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
68
68
  def encode
69
69
  unless class_name.class == Rex::Java::Serialization::Model::Utf ||
70
70
  class_annotation.class == Rex::Java::Serialization::Model::Annotation ||
71
71
  super_class.class == Rex::Java::Serialization::Model::ClassDesc
72
- raise ::RuntimeError, 'Filed to serialize NewClassDesc'
72
+ raise Rex::Java::Serialization::EncodeError, 'Filed to serialize NewClassDesc'
73
73
  end
74
74
  encoded = ''
75
75
  encoded << class_name.encode
76
- encoded << [serial_version].pack('Q>')
77
- stream.add_reference(self) unless stream.nil?
76
+ encoded << [serial_version].pack('q>')
78
77
  encoded << [flags].pack('C')
79
78
  encoded << [fields.length].pack('n')
80
79
  fields.each do |field|
@@ -113,11 +112,11 @@ module Rex
113
112
  #
114
113
  # @param io [IO] the io to read from
115
114
  # @return [Integer] if deserialization succeeds
116
- # @raise [RuntimeError] if deserialization doesn't succeed
115
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
117
116
  def decode_serial_version(io)
118
117
  raw_serial = io.read(8)
119
118
  if raw_serial.nil? || raw_serial.length != 8
120
- raise ::RuntimeError, 'Failed to unserialize ClassDescription'
119
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize ClassDescription'
121
120
  end
122
121
 
123
122
  raw_serial.unpack('Q>')[0]
@@ -127,10 +126,10 @@ module Rex
127
126
  #
128
127
  # @param io [IO] the io to read from
129
128
  # @return [Integer] if deserialization is possible
130
- # @raise [RuntimeError] if deserialization doesn't succeed
129
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
131
130
  def decode_flags(io)
132
131
  raw_flags = io.read(1)
133
- raise ::RuntimeError, 'Failed to unserialize ClassDescription' if raw_flags.nil?
132
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize ClassDescription' if raw_flags.nil?
134
133
 
135
134
  raw_flags.unpack('C')[0]
136
135
  end
@@ -139,11 +138,11 @@ module Rex
139
138
  #
140
139
  # @param io [IO] the io to read from
141
140
  # @return [Integer] if deserialization is possible
142
- # @raise [RuntimeError] if deserialization doesn't succeed
141
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
143
142
  def decode_fields_length(io)
144
143
  fields_length = io.read(2)
145
144
  if fields_length.nil? || fields_length.length != 2
146
- raise ::RuntimeError, 'Failed to unserialize ClassDescription'
145
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize ClassDescription'
147
146
  end
148
147
 
149
148
  fields_length.unpack('n')[0]
@@ -27,7 +27,7 @@ module Rex
27
27
  #
28
28
  # @param io [IO] the io to read from
29
29
  # @return [self] if deserialization succeeds
30
- # @raise [RuntimeError] if deserialization doesn't succeed
30
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
31
31
  def decode(io)
32
32
  self.enum_description = ClassDesc.decode(io, stream)
33
33
  stream.add_reference(self) unless stream.nil?
@@ -39,11 +39,11 @@ module Rex
39
39
  # Serializes the Rex::Java::Serialization::Model::NewEnum
40
40
  #
41
41
  # @return [String] if serialization succeeds
42
- # @raise [RuntimeError] if serialization doesn't succeed
42
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
43
43
  def encode
44
44
  unless enum_description.kind_of?(ClassDesc) &&
45
45
  constant_name.kind_of?(Utf)
46
- raise ::RuntimeError, 'Failed to serialize EnumDescription'
46
+ raise Rex::Java::Serialization::EncodeError, 'Failed to serialize EnumDescription'
47
47
  end
48
48
 
49
49
  encoded = ''
@@ -65,10 +65,10 @@ module Rex
65
65
  #
66
66
  # @param io [IO] the io to read from
67
67
  # @return [Rex::Java::Serialization::Model::Utf] if deserialization succeeds
68
- # @raise [RuntimeError] if deserialization doesn't succed
68
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succed
69
69
  def decode_constant_name(io)
70
70
  content = decode_content(io, stream)
71
- raise ::RuntimeError, 'Failed to unserialize NewEnum' unless content.kind_of?(Rex::Java::Serialization::Model::Utf)
71
+ raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize NewEnum' unless content.kind_of?(Rex::Java::Serialization::Model::Utf)
72
72
 
73
73
  content
74
74
  end
@@ -27,7 +27,7 @@ module Rex
27
27
  #
28
28
  # @param io [IO] the io to read from
29
29
  # @return [self] if deserialization succeeds
30
- # @raise [RuntimeError] if deserialization doesn't succeed
30
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
31
31
  def decode(io)
32
32
  self.class_desc = ClassDesc.decode(io, stream)
33
33
  stream.add_reference(self) unless stream.nil?
@@ -46,10 +46,10 @@ module Rex
46
46
  # Serializes the Rex::Java::Serialization::Model::NewObject
47
47
  #
48
48
  # @return [String] if serialization succeeds
49
- # @raise [RuntimeError] if serialization doesn't succeed
49
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
50
50
  def encode
51
51
  unless class_desc.kind_of?(ClassDesc)
52
- raise ::RuntimeError, 'Failed to serialize NewObject'
52
+ raise Rex::Java::Serialization::EncodeError, 'Failed to serialize NewObject'
53
53
  end
54
54
 
55
55
  encoded = ''
@@ -71,9 +71,12 @@ module Rex
71
71
  # @return [String]
72
72
  def to_s
73
73
  str = ''
74
+
74
75
  case class_desc.description
75
76
  when NewClassDesc
76
77
  str << class_desc.description.class_name.to_s
78
+ when ProxyClassDesc
79
+ str << class_desc.description.interfaces.collect { |iface| iface.contents }.join(',')
77
80
  when Reference
78
81
  str << (class_desc.description.handle - BASE_WIRE_HANDLE).to_s(16)
79
82
  end
@@ -82,6 +85,8 @@ module Rex
82
85
  data_str = class_data.collect { |data| data.to_s }
83
86
  str << data_str.join(', ')
84
87
  str << ' }'
88
+
89
+ str
85
90
  end
86
91
 
87
92
  private
@@ -91,7 +96,7 @@ module Rex
91
96
  # @param io [IO] the io to read from
92
97
  # @param my_class_desc [Rex::Java::Serialization::Model::NewClassDesc] the class description whose data is being extracted
93
98
  # @return [Array] class_data values if deserialization succeeds
94
- # @raise [RuntimeError] if deserialization doesn't succeed
99
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
95
100
  def decode_class_data(io, my_class_desc)
96
101
  values = []
97
102
 
@@ -114,7 +119,7 @@ module Rex
114
119
  # @param io [IO] the io to read from
115
120
  # @param my_class_desc [Rex::Java::Serialization::Model::NewClassDesc] the class description whose data is being extracted
116
121
  # @return [Array] class_data values if deserialization succeeds
117
- # @raise [RuntimeError] if deserialization doesn't succeed
122
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
118
123
  def decode_class_fields(io, my_class_desc)
119
124
  values = []
120
125
 
@@ -135,57 +140,57 @@ module Rex
135
140
  # @param io [IO] the io to read from
136
141
  # @param type [String] the type of the value to deserialize
137
142
  # @return [Array(String, <Fixnum, Float>)] type and value if deserialization succeeds
138
- # @raise [RuntimeError] if deserialization fails
143
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization fails
139
144
  def decode_value(io, type)
140
145
  value = []
141
146
 
142
147
  case type
143
148
  when 'byte'
144
149
  value_raw = io.read(1)
145
- raise ::RuntimeError, 'Failed to deserialize NewArray value' if value_raw.nil?
150
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value' if value_raw.nil?
146
151
  value.push('byte', value_raw.unpack('c')[0])
147
152
  when 'char'
148
153
  value_raw = io.read(2)
149
154
  unless value_raw && value_raw.length == 2
150
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
155
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
151
156
  end
152
157
  value.push('char', value_raw.unpack('s>')[0])
153
158
  when 'double'
154
159
  value_raw = io.read(8)
155
160
  unless value_raw && value_raw.length == 8
156
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
161
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
157
162
  end
158
163
  value.push('double', value = value_raw.unpack('G')[0])
159
164
  when 'float'
160
165
  value_raw = io.read(4)
161
166
  unless value_raw && value_raw.length == 4
162
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
167
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
163
168
  end
164
169
  value.push('float', value_raw.unpack('g')[0])
165
170
  when 'int'
166
171
  value_raw = io.read(4)
167
172
  unless value_raw && value_raw.length == 4
168
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
173
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
169
174
  end
170
175
  value.push('int', value_raw.unpack('l>')[0])
171
176
  when 'long'
172
177
  value_raw = io.read(8)
173
178
  unless value_raw && value_raw.length == 8
174
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
179
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
175
180
  end
176
181
  value.push('long', value_raw.unpack('q>')[0])
177
182
  when 'short'
178
183
  value_raw = io.read(2)
179
184
  unless value_raw && value_raw.length == 2
180
- raise ::RuntimeError, 'Failed to deserialize NewArray value'
185
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value'
181
186
  end
182
187
  value.push('short', value_raw.unpack('s>')[0])
183
188
  when 'boolean'
184
189
  value_raw = io.read(1)
185
- raise ::RuntimeError, 'Failed to deserialize NewArray value' if value_raw.nil?
190
+ raise Rex::Java::Serialization::DecodeError, 'Failed to deserialize NewArray value' if value_raw.nil?
186
191
  value.push('boolean', value_raw.unpack('c')[0])
187
192
  else
188
- raise ::RuntimeError, 'Unsupported NewArray type'
193
+ raise Rex::Java::Serialization::DecodeError, 'Unsupported NewArray type'
189
194
  end
190
195
 
191
196
  value
@@ -195,7 +200,7 @@ module Rex
195
200
  #
196
201
  # @param value [Array] the type and value to serialize
197
202
  # @return [String] the serialized value
198
- # @raise [RuntimeError] if serialization fails
203
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization fails
199
204
  def encode_value(value)
200
205
  res = ''
201
206
 
@@ -217,7 +222,7 @@ module Rex
217
222
  when 'boolean'
218
223
  res = [value[1]].pack('c')
219
224
  else
220
- raise ::RuntimeError, 'Unsupported NewArray type'
225
+ raise Rex::Java::Serialization::EncodeError, 'Unsupported NewArray type'
221
226
  end
222
227
 
223
228
  res