Escaping from Jails

GTFOBins

Search in https://gtfobins.github.io/ if you can execute any binary with "Shell" property

Chroot Escapes

From wikipedia: The chroot mechanism is not intended to defend against intentional tampering by privileged (root) users. On most systems, chroot contexts do not stack properly and chrooted programs with sufficient privileges may perform a second chroot to break out. Usually this means that to escape you need to be root inside the chroot.

Root + CWD

Usually you won't find the chroot binary inside a chroot jail, but you could compile, upload and execute a binary:

C: break_chroot.c
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>

//gcc break_chroot.c -o break_chroot

int main(void)
{
    mkdir("chroot-dir", 0755);
    chroot("chroot-dir");
    for(int i = 0; i < 1000; i++) {
        chdir("..");
    }
    chroot(".");
    system("/bin/bash");
}
Python
Perl

Root + Saved fd

C: break_chroot.c

Root + Fork + UDS (Unix Domain Sockets)

Root + Mount

Root + /proc

Root(?) + Fork

ptrace

Bash Jails

Enumeration

Get info about the jail:

Modify PATH

Check if you can modify the PATH env variable

Using vim

Create script

Check if you can create an executable file with /bin/bash as content

Get bash from SSH

If you are accessing via ssh you can use this trick to execute a bash shell:

Declare

Wget

You can overwrite for example sudoers file

Other tricks

https://fireshellsecurity.team/restricted-linux-shell-escaping-techniques/ https://pen-testing.sans.org/blog/2012/0b6/06/escaping-restricted-linux-shells https://gtfobins.github.io It could also be interesting the page:

Bypass Linux Restrictions

Python Jails

Tricks about escaping from python jails in the following page:

Bypass Python sandboxes

Lua Jails

In this page you can find the global functions you have access to inside lua: https://www.gammon.com.au/scripts/doc.php?general=lua_base

Eval with command execution:

Some tricks to call functions of a library without using dots:

Enumerate functions of a library:

Note that every time you execute the previous one liner in a different lua environment the order of the functions change. Therefore if you need to execute one specific function you can perform a brute force attack loading different lua environments and calling the first function of le library:

Get interactive lua shell: If you are inside a limited lua shell you can get a new lua shell (and hopefully unlimited) calling:

References

Last updated