Module: Msf::Exploit::Remote::HTTP::Beyondtrust::RemoteSupport::Fields
- Defined in:
- lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb
Overview
BeyondTrust pack_data escaping, shared by service and transfer messages.
Class Method Summary collapse
-
.decode(data) ⇒ Hash<String, String>
Decoded values.
-
.encode(values) ⇒ String
Escaped semicolon-delimited fields.
-
.escape(value, delimiter) ⇒ String
encode uses this for names and values in packed service requests and transfer metadata.
Class Method Details
.decode(data) ⇒ Hash<String, String>
Returns decoded values.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 36 def decode(data) result = {} key = String.new value = String.new in_value = false escaped = false data.each_char do |char| if escaped char = { 'n' => "\n", '0' => "\x00", 'd' => "\x7f" }.fetch(char, char) escaped = false elsif char == '\\' escaped = true next elsif char == '=' && !in_value in_value = true next elsif char == ';' && in_value result[key] = value key = String.new value = String.new in_value = false next end (in_value ? value : key) << char end raise ProtocolError, 'Truncated packed message' if escaped || (!in_value && !key.empty?) result[key] = value if in_value result end |
.encode(values) ⇒ String
Returns escaped semicolon-delimited fields.
27 28 29 30 31 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 27 def encode(values) values.sort_by { |key, _value| key.to_s }.map do |key, value| "#{escape(key.to_s, '=')}=#{escape(value.to_s, ';')}" end.join(';') end |
.escape(value, delimiter) ⇒ String
encode uses this for names and values in packed service requests and transfer metadata. Escape the field delimiter and backslash so data cannot become another field or escape; encode LF, NUL, and DEL using BeyondTrust's pack_data escapes rather than literal control bytes. Nested packed maps are escaped again when included as a value in an outer map.
74 75 76 77 78 |
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 74 def escape(value, delimiter) value.each_char.map do |char| { '\\' => '\\\\', "\n" => '\\n', "\x00" => '\\0', "\x7f" => '\\d', delimiter => "\\#{delimiter}" }.fetch(char, char) end.join end |