githubEdit

Escaping from Jails

circle-check

GTFOBins

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

Chroot Escapes

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. Usually this means that to escape you need to be root inside the chroot.

circle-check

Root + CWD

circle-exclamation

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

chevron-rightC: break_chroot.chashtag
#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");
}
chevron-rightPythonhashtag
chevron-rightPerlhashtag

Root + Saved fd

circle-exclamation
chevron-rightC: break_chroot.chashtag

Root + Fork + UDS (Unix Domain Sockets)

circle-exclamation

Root + Mount

circle-exclamation

Root + /proc

circle-exclamation

Root(?) + Fork

circle-exclamation

ptrace

circle-exclamation

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/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 Linux 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:

References

circle-check

Last updated