diff --git a/Retrieve-DNSFile.ps1 b/Retrieve-DNSFile.ps1 index 10e280b..5c23776 100644 --- a/Retrieve-DNSFile.ps1 +++ b/Retrieve-DNSFile.ps1 @@ -1,4 +1,5 @@ -Function Get-DNSTXT { +# Simple Powershell client, also runs on linux with Powershell Core +Function Get-DnsTxt { [CmdletBinding()] param( [string] $Domain ) @@ -9,18 +10,18 @@ Function Get-DNSTXT { } } -Function Get-DNSFile { +Function Get-DnsFile { [CmdletBinding()] param( - [string] $Filename = $(Read-Host -Prompt 'Enter a Filename'), - [string] $DNSName = $(Read-Host -Prompt 'Enter a DNSName'), + [string] $FileName = $(Read-Host -Prompt 'Enter a FileName'), + [string] $DnsName = $(Read-Host -Prompt 'Enter a DnsName'), [switch] $Execute, [switch] $Write, [string] $OutPath ) - $count = [int](Get-DNSTXT -Domain "$Filename.count.$DNSName") + $count = [int](Get-DnsTxt -Domain "$FileName.count.$DnsName") $file_base64 = "" For ($i=0; $i -le $count; $i++) { - $file_base64 += (Get-DNSTXT -Domain "$Filename.$i.$DNSName") + $file_base64 += (Get-DnsTxt -Domain "$FileName.$i.$DnsName") } "Base64 $file_base64" $file_string = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($file_base64)) @@ -31,21 +32,22 @@ Function Get-DNSFile { $file_string | Out-String } If ($Write.IsPresent) { - $file_string | Out-File -FilePath ($OutPath, $Filename)[!$OutPath] + $file_string | Out-File -FilePath ($OutPath, $FileName)[!$OutPath] } } Function Push-DNSFile { [CmdletBinding()] param( - [string] $Filename = $(Read-Host -Prompt 'Enter a Filename'), - [string] $DNSName = $(Read-Host -Prompt 'Enter a DNSName') + [string] $FileName = $(Read-Host -Prompt 'Enter a Filename'), + [string] $DnsName = $(Read-Host -Prompt 'Enter a DnsName') ) - $content_id = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((Get-FileHash -Path $Filename).ToString())).Substring(0,6) - $content_binary = Get-Content -Path $Filename -Encoding utf8 + $id = (Get-FileHash $FileName | Select-Object Hash | Format-Table -HideTableHeaders | Out-String).Trim() + $id = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($id)).Substring(0,6) + $content_binary = Get-Content -Path $FileName -Encoding utf8 $content_base64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($content_binary)) $i = 0 While ($content_base64) { - $url = "."+$i+"-"+$content_id+"u."+$DNSName + $url = "."+$i+"-"+$id+"u."+$DnsName $len = 63 - $url.Length if($len -le $content_base64.Length) { $content_part = $content_base64.Substring(0, $len) @@ -54,7 +56,7 @@ Function Push-DNSFile { $content_part = $content_base64 $content_base64 = $false } - Get-DNSTXT -Domain ($content_part + $url) + Get-DnsTxt -Domain ($content_part + $url) $i++ } } diff --git a/server b/server index 2a10d02..0711587 100755 --- a/server +++ b/server @@ -85,7 +85,7 @@ class FileResolver(BaseResolver): path = self.directory + "/" + pname command = ''.join(parts[-2:-1]) if command.endswith("u"): - with open(f"/tmp/{command.split('-')[1]}.b64", 'a') as f: + with open(args.directory + command.split('-')[1] + ".b64", 'a') as f: f.write(str(pname) + "\n") reply.add_answer(RR(name, QTYPE.TXT, ttl=self.ttl, rdata=TXT("Upload accepted"))) return reply