Shells

Shells

Shell techniques are essential for penetration testers to gain access and control over target systems. This document provides commands and methods for various shell types.

Shell Types

A shell is software that facilitates interaction with the operating system through command lines. There are three primary connection methods:

Type

Method

Reverse Shells

Connects back to our system

Bind Shells

Waits for us to connect to the system

Web Shells

Communicates through a web server over HTTP parameters

Reverse Shells

Reverse shells initiate a connection from the target back to the attacker's machine. They're especially useful when target systems are behind firewalls or NAT.

Setting Up a Listener

# Basic netcat listener
nc -lvnp 1234

# Listeners with different tools
ncat -lvnp 1234
socat TCP-LISTEN:1234,reuseaddr,fork - 

Linux Reverse Shells

Bash TCP Socket

Bash FIFO/Pipe Method

Python Reverse Shell

Perl Reverse Shell

PHP Reverse Shell

Ruby Reverse Shell

Netcat Reverse Shell

Windows Reverse Shells

PowerShell Reverse Shell

PowerShell One-liner

Netcat for Windows

Bind Shells

Bind shells open a listening port on the target, waiting for the attacker to connect.

Linux Bind Shell

Python Bind Shell

PowerShell Bind Shell

Web Shells

Web shells execute commands via HTTP requests, useful when direct connections are blocked.

PHP Web Shell

Access via: http://target.com/shell.php?cmd=whoami

PHP File Upload Shell

JSP Web Shell

ASP/ASPX Web Shell

Upgrading Shells

Basic shells often lack features like tab completion. These methods create more functional shells.

Python TTY

Full TTY Upgrade (Linux)

Socat Fully Interactive Shell

Interactive Shell Creation

Using Perl

Using Ruby

Using Lua

Using AWK

Using Find

Using VIM

MSFvenom Payload Generation

MSFvenom can generate various shellcode payloads.

Linux Payloads

Windows Payloads

Web Payloads

Common Issues and Solutions

Shell Stability Issues

Problem: Shell dies unexpectedly Solution: Try different shell types or full TTY upgrade

Firewall Restrictions

Problem: Can't establish direct connections Solution: Use common ports (80, 443, 8080) or try ICMP/DNS tunneling

Non-Interactive Commands

Problem: Commands like su, ssh require TTY Solution: Upgrade shell to full TTY

Command Output Encoding

Problem: Binary data corrupts terminal Solution: Base64 encode output before transferring

Anti-Virus Detection

Problem: Payloads detected by AV Solution: Use encoders or obfuscation techniques

Last updated