-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEncode-DnsTxt.ps1
72 lines (58 loc) · 1.71 KB
/
Encode-DnsTxt.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Encode-DnsTxt
# A simple script to spit out a dnsmasq configuration to transfer files
# To a restricted environment.
#
# Script by David Lodge and Ian Williams
param(
[alias("dns")][string]$Domain="",
[alias("in")][string]$FileIn="",
[alias("out")][string]$FileOut="",
[alias("h")][switch]$Help=$False
)
if ([string]::IsNullorEmpty($Domain)) {
Write-Output "Mandatory parameter Domain not passed"
$Help=$True
}
if ([string]::IsNullorEmpty($FileIn)) {
Write-Output "Mandatory parameter FileIn not passed"
$Help=$True
}
if ([string]::IsNullorEmpty($FileOut)) {
Write-Output "Mandatory parameter FileOut not passed"
$Help=$True
}
if($Help) {
"
Encode-DnsTxt: Create dnsmasq configuration to transfer files
-Domain <domain> The domain of the dnscat2 server
-FileIn <file> File to be encoded
-FileOut <file> File to save dnsmasq configuration to
-Help -h Display this help message
"
break
}
# Read FileIn and Base64 it
if (-Not (Test-Path -PathType Leaf $FileIn)) {
Write-Output "File $FileIn does not exist"
break
}
$bytes=[System.IO.File]::ReadAllBytes($FileIn)
$cooked=[Convert]::ToBase64String($bytes)
# Split it into 254 byte chunks
$o=[regex]::split($cooked, '(.{254})')
# Simple dnsmasq header
{log-facility=/var/log/dnsmasq.log
log-queries
} | Set-Content $FileOut
# Add each line to dnsmasq.conf
$i=1
foreach($item in $o) {
if ($item.Length -ne 0) {
$output="txt-record=dnscat" + $i.toString() + ".$Domain," + $item
$i++
Write-Output $output | Add-Content $FileOut
}
}
# Add a count to make it easier
$i--
$output="txt-record=dnscatcount.$domain," + $i.toString() | Add-Content $FileOut