Restricted Shell (rbash, rzsh) Bypass
The restricted shell is a Unix shell that restricts some of the capabilities available to an interactive user session.
After logged in a shell, sometimes we faced the error such as below when executing commands.
The target system uses a restricted shell so we may not be able to execute commonly used commands e.g. ls
, cd
, etc.
We need to bypass the restriction First.
Command Enumeration
First check what commands can we execute. Try running varied commands.
How to Bypass
Update Environment Variables
If we can execute export
command and the desired environment variable (PATH, SHELL, etc.) is not readonly, we can update variables.
Autocomplete to List Directories
We can see files and directories in the current directory by inputting the following path and entering “Tab” key.
Copy Shell Command
If we can execute cp
command, we can copy /bin/bash
or /bin/sh
to the current directory.
List/Read Files
If we can use echo
or printf
command, we can list all files or read files.
List
Read
Nmap
If we can use nmap command, we can escape the restricted shell with the interactive mode.
Vi/Vim Editor
If we can use vi
or vim
command, we can update the SHELL variable in the vi/vim editor.
SSH Flags
If we can enter the shell, run tab-completion by pushing “Tab” key. We may be able to retrieve commands available.
Last updated