1
0
Fork 0

Added upload file id

master
Simon Moser vor 3 Jahren
Ursprung fedda3652f
Commit d037ccddd0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 83765B895FF2CFC6

@ -2,7 +2,11 @@ Function Get-DNSTXT {
[CmdletBinding()] param( [CmdletBinding()] param(
[string] $Domain [string] $Domain
) )
return (Resolve-DnsName -Type TXT $Domain | Select-Object Strings | Format-Table -HideTableHeaders | Out-String -Width 1000).Replace("{", "").Replace("}", "").Trim() Try {
return (Resolve-DnsName -Type TXT $Domain | Select-Object Strings | Format-Table -HideTableHeaders | Out-String -Width 1000).Replace("{", "").Replace("}", "").Trim()
} Catch [System.Management.Automation.CommandNotFoundException] {
return dig +short $Domain TXT
}
} }
Function Get-DNSFile { Function Get-DNSFile {
@ -13,10 +17,10 @@ Function Get-DNSFile {
[switch] $Write, [switch] $Write,
[string] $OutPath [string] $OutPath
) )
$count = [int](Retrieve-DNSTXT -Domain "$Filename.count.$DNSName") $count = [int](Get-DNSTXT -Domain "$Filename.count.$DNSName")
$file_base64 = "" $file_base64 = ""
For ($i=0; $i -le $count; $i++) { For ($i=0; $i -le $count; $i++) {
$file_base64 += (Retrieve-DNSTXT -Domain "$Filename.$i.$DNSName") $file_base64 += (Get-DNSTXT -Domain "$Filename.$i.$DNSName")
} }
"Base64 $file_base64" "Base64 $file_base64"
$file_string = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($file_base64)) $file_string = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($file_base64))
@ -31,20 +35,25 @@ Function Get-DNSFile {
} }
} }
function Push-DNSFile { Function Push-DNSFile {
[CmdletBinding()] param( [CmdletBinding()] param(
[string] $Filename = $(Read-Host -Prompt 'Enter a Filename'), [string] $Filename = $(Read-Host -Prompt 'Enter a Filename'),
[string] $DNSName = $(Read-Host -Prompt 'Enter a DNSName'), [string] $DNSName = $(Read-Host -Prompt 'Enter a DNSName')
[string] $Prefix = ""
) )
$content_id = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((Get-FileHash -Path $Filename).ToString())).Substring(0,6)
$content_binary = Get-Content -Path $Filename -Encoding utf8 $content_binary = Get-Content -Path $Filename -Encoding utf8
$content_base64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($content_binary)) $content_base64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($content_binary))
$i = 0 $i = 0
While ($content_base64) { While ($content_base64) {
$url = ".$(Prefix)$(i)0.$(DNSName)" $url = "."+$i+"-"+$content_id+"u."+$DNSName
$len = 63 - $url.Length $len = 63 - $url.Length
$content_part = $content_base64.Substring(0, $len) if($len -le $content_base64.Length) {
$content_base64 = $content_base64.Substring($len) $content_part = $content_base64.Substring(0, $len)
$content_base64 = $content_base64.Substring($len)
} else {
$content_part = $content_base64
$content_base64 = $false
}
Get-DNSTXT -Domain ($content_part + $url) Get-DNSTXT -Domain ($content_part + $url)
$i++ $i++
} }

@ -84,9 +84,8 @@ class FileResolver(BaseResolver):
pname = '.'.join(parts[:-2]) pname = '.'.join(parts[:-2])
path = self.directory + "/" + pname path = self.directory + "/" + pname
command = ''.join(parts[-2:-1]) command = ''.join(parts[-2:-1])
# TODO: circumvent caching, eg by counting up
if command.endswith("u"): if command.endswith("u"):
with open('/tmp/dns-srv.log', 'a') as f: with open(f"/tmp/{command.split('-')[1]}.b64", 'a') as f:
f.write(str(pname) + "\n") f.write(str(pname) + "\n")
reply.add_answer(RR(name, QTYPE.TXT, ttl=self.ttl, rdata=TXT("Upload accepted"))) reply.add_answer(RR(name, QTYPE.TXT, ttl=self.ttl, rdata=TXT("Upload accepted")))
return reply return reply

Laden…
Abbrechen
Speichern