Class: Msf::Exploit::Remote::HTTP::Beyondtrust::RemoteSupport::MrsStream

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb

Overview

Sequenced MRS byte stream, optionally using raw DEFLATE.

Instance Method Summary collapse

Constructor Details

#initialize(client, handler, remote) ⇒ MrsStream

Returns a new instance of MrsStream.

Parameters:

  • client (MrsClient) —

    owning router

  • handler (Integer) —

    local mailbox

  • remote (String) —

    peer address



277
278
279
280
281
282
283
284
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 277

def initialize(client, handler, remote)
  @client = client
  @handler = handler
  @remote = remote
  @transmit_sequence = 0
  @receive_sequence = 0
  @buffer = String.new(encoding: Encoding::BINARY)
end

Instance Method Details

#close ⇒ Array<Zlib::Error>

Returns cleanup failures, without replacing a transfer error.

Returns:

  • (Array<Zlib::Error>) —

    cleanup failures, without replacing a transfer error



343
344
345
346
347
348
349
350
351
352
353
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 343

def close
  errors = []
  [@encoder, @decoder].compact.each do |stream|
    stream.close unless stream.closed?
  rescue Zlib::Error => e
    errors << e
  end
  @encoder = nil
  @decoder = nil
  errors
end

#compress ⇒ void

This method returns an undefined value.

Raw DEFLATE starts after the initial anonymous-file request.



288
289
290
291
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 288

def compress
  @encoder = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS)
  @decoder = Zlib::Inflate.new(-Zlib::MAX_WBITS)
end

#finish ⇒ void

This method returns an undefined value.



335
336
337
338
339
340
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 335

def finish
  return if @finished

  @finished = true
  transmit('O', 'EOF', flags: 1)
end

#line ⇒ String

Returns next line without LF.

Returns:

  • (String) —

    next line without LF



307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 307

def line
  until (offset = @buffer.index("\n"))
    raise ProtocolError, 'Oversized MRS stream line' if @buffer.bytesize > MAX_MESSAGE

    @buffer << read_chunk
  end
  @buffer.slice!(0, offset + 1).delete_suffix("\n")
rescue StreamEOF
  raise if @buffer.empty?

  @buffer.slice!(0, @buffer.bytesize)
end

#read_to_eof(max_bytes:) ⇒ String

Procfs files can report size zero while still producing stream data.

Parameters:

  • max_bytes (Integer) —

    maximum accepted uncompressed bytes

Returns:

  • (String) —

    all bytes up to the peer's EOF

Raises:



324
325
326
327
328
329
330
331
332
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 324

def read_to_eof(max_bytes:)
  loop do
    raise ProtocolError, 'Native file exceeds the read limit' if @buffer.bytesize > max_bytes

    @buffer << read_chunk
  end
rescue StreamEOF
  @buffer.slice!(0, @buffer.bytesize)
end

#request ⇒ Hash<String, String>

The initial file request occupies one plaintext stream packet without LF.

Returns:

  • (Hash<String, String>) —

    initial file-server request



295
296
297
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 295

def request
  Fields.decode(read_chunk)
end

#write(data) ⇒ void

This method returns an undefined value.

Parameters:

  • data (String) —

    stream bytes



301
302
303
304
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 301

def write(data)
  data = @encoder.deflate(data, Zlib::SYNC_FLUSH) if @encoder
  transmit('I', data, flags: @encoder ? 0 : 1)
end