-
Notifications
You must be signed in to change notification settings - Fork 2
/
PSbettercap.ps1
694 lines (559 loc) · 29.6 KB
/
PSbettercap.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# https://github.com/MelroyB/PSBettercap
function set-basics {
$Host.UI.RawUI.WindowTitle = "PSBettercap"
Clear-Host
### Debug Settings
# $DebugPreference = 'SilentlyContinue'
$DebugPreference = 'Continue'
### File locations
$script:base = $(if ($psISE) { Split-Path -Path $psISE.CurrentFile.FullPath } else { $(if ($script:PSScriptRoot.Length -gt 0) { $script:PSScriptRoot } else { $script:pwd.Path }) })
$script:Sessionfile = $script:base + "\session.xml"
$script:nodefile = $script:base + "\nodes.xml"
$script:csvfile = $script:base + "\log-$((get-date).ToString("yyyyMMdd-HHmmss")).csv"
$script:kmlfile = $script:base + "\log-$((get-date).ToString("yyyyMMdd-HHmmss")).kml"
### PSObjects
$script:events = @()
$script:events += new-object psobject -property @{
message = "Starting PSBettercap"
color = "green"
bcolor = "black"
}
$objAP = @()
}
function new-map {
#### Skip no location
#### descriptions
$kml = @"
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>project</name>
"@
foreach ($objAP in $script:objAPs) {
$strKMLname = $objAp.hostname
$strKMLmac = $objAp.mac
$strKMLlatitude = $objAP.latitude
$strKMLlongitude = $objAP.longitude
$kml += @"
<Placemark>
<name>$strKMLmac</name>
<description>123</description>
<Point>
<coordinates>$strKMLlongitude,$strKMLlatitude</coordinates>
</Point>
</Placemark>
"@
}
$kml += @"
</Document>
</kml>
"@
$kml | Out-File -Force -Encoding ascii ($script:kmlfile)
}
function export-results {
### Convert to CSV
$script:objAPs | Select-Object mac, hostname, vendor, channel, encryption, auth, clients, handshake, latitude, longitude, last_seen, detectedby | export-csv -Path $script:csvfile
}
function Write-HostCenter {
param($Message) Write-Host ("{0}{1}" -f (' ' * (([Math]::Max(0, $Host.UI.RawUI.BufferSize.Width / 2) - [Math]::Floor($Message.Length / 2)))), $Message)
}
function Get-GPS {
write-host $script:objNodes | format-table
foreach ($objNode in $script:objNodes) {
$uri = $objnode.protocol + '://' + $objNode.ip + ':' + $objNode.port + '/api/session'
$all = Invoke-RestMethod -Uri $uri -TimeoutSec 5
$all.gps.Altitude
$all.gps.Longitude
$all.gps.FixQuality
$all.gps.NumSatellites
#clear-variable all
}
}
function Get-BettercapAPs {
### Loop trough nodes
foreach ($objNode in $script:objNodes) {
$objApiResult = $null
if ($objnode.credentials -ne "") {
$Headers = @{
"Authorization" = "Basic $($objnode.credentials)"
"Content-Type" = "application/json"
}
}
else {
$Headers = @{
"Content-Type" = "application/json"
}
}
$uri = $objnode.protocol + '://' + $objNode.ip + ':' + $objNode.port + '/api/session'
try { $objApiResult = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $headers -TimeoutSec 5 }catch {}
$uri = $objnode.protocol + '://' + $objNode.ip + ':' + $objNode.port + '/api/events'
try { $objApiEventsResult = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $headers -TimeoutSec 5 }catch {}
try { Invoke-RestMethod -Uri $uri -Method 'DELETE' -Headers $headers -TimeoutSec 5 }catch {}
if ($null -eq $objApiResult) {
$UpdateNode = $script:objNodes | Where-Object { $_.ip -eq $objNode.ip }
$updatenode.online = $false
}
else {
$UpdateNode = $script:objNodes | Where-Object { $_.ip -eq $objNode.ip }
$updatenode.online = $true
}
### Only set objects if gpsfix
if ($objApiResult.gps.FixQuality -cgt 0) {
$objApiResult.gps.Latitude = [math]::Round($objApiResult.gps.Latitude, 5)
$objApiResult.gps.Latitude = $objApiResult.gps.Latitude -replace ',', '.'
$objApiResult.gps.Longitude = [math]::Round($objApiResult.gps.Longitude, 5)
$objApiResult.gps.Longitude = $objApiResult.gps.Longitude -replace ',', '.'
$script:objGPS = New-Object PSObject -property @{
Longitude = $objApiResult.gps.Longitude
Latitude = $objApiResult.gps.Latitude
NumSatellites = $objApiResult.gps.NumSatellites
}
}
else {
$script:objGPS = New-Object PSObject -property @{
Longitude = $null
Latitude = $null
NumSatellites = $objApiResult.gps.NumSatellites
}
}
### Loop Through all AccessPoints
foreach ($ap in $objApiResult.wifi.aps) {
### Check if AP is already in the table
if (($script:objAPs) -and ($script:objAPs.mac.Contains($ap.mac))) {
$UpdateAP = $script:objAPs | Where-Object { $_.mac -eq $ap.mac }
if (($UpdateAP.handshake -eq $false) -and ($ap.handshake -eq $true)) {
new-event "$((get-date).ToString("HH:mm:ss"))|$($ap.mac)|$($ap.hostname) Handshake captured" "black" "green"
$UpdateAP.handshake = $ap.handshake
}
$UpdateAP.last_seen = $ap.last_seen.Split("\.")[0]
$UpdateAP.detectedby = $objnode.ip + ':' + $objnode.port
$UpdateAP.received = $ap.received
$UpdateAP.sent = $ap.sent
$UpdateAP.clients = $ap.clients.count
###write-host $ap.mac "signaal" $ap.rssi "was eerder" $updateAp.rssi
### Check if AP signal is better before update GPS location
if (($updateAP.rssigpsupdate -lt $ap.rssi) -and ($objApiResult.gps.FixQuality -cgt 0)) {
new-event "$((get-date).ToString("HH:mm:ss"))|$($ap.mac)|$($ap.hostname) GPS location updated" "green" "black"
$updateAP.latitude = $objGPS.latitude
$updateAP.longitude = $objGPS.Longitude
$updateAP.rssigpsupdate = $ap.rssi
$updateAp.rssi = $ap.rssi
}
else {
###Write-host $ap.mac "Minder bereik, GPS geupdate bij " $updateAP.rssigpsupdate " nu " $ap.rssi
$updateAp.rssi = $ap.rssi
}
}
else {
new-event "$((get-date).ToString("HH:mm:ss"))|$($ap.mac)|$($ap.hostname) Found new AP" "green" "black"
$script:objAPs += New-Object PSObject -property @{
mac = $ap.mac
alias = $ap.alias
auth = $ap.authentication
channel = $ap.channel
cipher = $ap.cipher
clients = $ap.clients.count
clientsdetails = $ap.clients
encryption = $ap.encryption
first_seen = $ap.first_seen.Split("\.")[0]
frequency = $ap.frequency
handshake = $ap.handshake
pmkid = ""
hostname = $ap.hostname
ipv4 = $ap.ipv4
ipv6 = $ap.ipv6
last_seen = $ap.last_seen.Split("\.")[0]
meta = $ap.meta
received = $ap.received
rssi = $ap.rssi
sent = $ap.sent
vendor = $ap.vendor
wps = $ap.wps
detectedby = $objnode.ip + ':' + $objnode.port
latitude = $objGPS.latitude
longitude = $objGPS.Longitude
rssigpsupdate = $ap.rssi
}
#Clear-Variable objApiResult
#$script:objAPs += $objAP
}
}
### Loop Trough all events
foreach ($objEvent in $objApiEventsResult) {
if ($objevent.tag -eq "wifi.client.handshake") {
if ($null -ne ($objevent | Select-Object -ExpandProperty data | select-object -ExpandProperty pmkid)) {
$objPMKID = ($objevent | Select-Object -ExpandProperty data | select-object -ExpandProperty pmkid)
$objPMKIDStation = ($objevent | Select-Object -ExpandProperty data | select-object -ExpandProperty station)
$objPMKIDAP = ($objevent | Select-Object -ExpandProperty data | select-object -ExpandProperty ap)
if (($script:objAPs) -and ($script:objAPs.mac.Contains($objPMKIDAP))) {
new-event "$((get-date).ToString("HH:mm:ss"))|$($objPMKIDAP)| PMKID captured" "black" "green"
$UpdateAP = $script:objAPs | Where-Object { $_.mac -eq $objPMKIDAP }
$UpdateAP.pmkid = $objPMKID
}
}
}
#$objStation = $null
#$objPMKID = $null
}
}
###$script:objAPs | Format-table -Property mac,hostname,channel,detectedby,latitude,longitude,rssi,rssigpsupdate
}
function Show-BettercapAPs {
$script:objAPs | Format-table -Property first_seen, last_seen, mac, hostname, vendor, channel, encryption, cipher, auth, handshake, clients, detectedby
Write-host "total Aps:" $script:objAPs.count
}
function Show-Help {
Write-host "nodes show = show bettercap nodes"
Write-host "nodes add = add bettercap nodes"
Write-host "nodes int = Config bettercap node interface"
Write-host "nodes channel = Config bettercap node channel"
Write-host "nodes ttl = Config bettercap node ttl"
Write-host "nodes del = del bettercap nodes"
Write-host "nodes start = start all bettercap nodes"
Write-host "nodes stop = stop all bettercap nodes"
Write-host "show = show networks"
Write-host "start = start session with the nodes"
Write-host "help = help"
Write-host "exit = quit"
}
function command-nodes {
param ($a)
if ($a -like "nodes show") {
write-host $script:objNodes.count "Bettercap node(s) configured"
write-host "----------"
show-nodes
}
if ($a -like "nodes add") { add-node }
if ($a -like "nodes del") { remove-node }
if ($a -like "nodes int") { set-nodeinterface }
if ($a -like "nodes channel") { set-nodechannels }
if ($a -like "nodes ttl") { set-nodettl }
if ($a -like "nodes start") { Start-Nodes }
if ($a -like "nodes stop") { Stop-Nodes }
}
function Out-Debug {
Param
(
[System.Management.Automation.InvocationInfo]$Invocation,
[Parameter(ValueFromPipeline = $true)]
[string[]]$Variable,
[string]$Scope = 1
)
Process {
foreach ($var in $Variable) {
@(
"Origin: $($Invocation.MyCommand.Name)",
"Variable: $var",
'Value:',
(Get-Variable -Name $var -Scope $Scope -ValueOnly |
Format-Table -AutoSize -Wrap | Out-String)
) | Write-Debug
}
}
}
function show-banner {
Write-Host " "
Write-Host " ............................ "
Write-Host " ╔▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ "
Write-Host " ▓▓▓▓▓▓▌ ▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ "
Write-Host " ▐▓▓▓▓▓▓▓▄ ▀▓▓▓▓╢███▓╢▓▓▓▓▓C ,,▄, "
Write-Host " ▓▓▓▓▓▓▓▓▓▓▄ ▓███▀▀▀████╢▓▓ ▄███▀▀███▄ "
Write-Host " ▐▓▓▓▓▓▓▓▓▓▓▓▓▄ ╒██▀░░▄▄▄░▀███ ,▄▄▄▄▄▄▄▄▄▄, ▄██▀░▄▄▄▄░▀██ "
Write-Host " ▓▓▓▓▓▓▓▓▓▓▓▓▓▓╜██░░░░░▀▀██░▀██ ▄▄█████▓▓▓▓▓▓▓██████▄, ██▀░▄██▀░░░░░██ "
Write-Host " ▐▓▓▓▓▓▓▓▓▓▓▓▀ ██░░░░░░░▐███████▓▓████████ ▓▀▀█████▓▓█████▄█▌░░░░░░░██ "
Write-Host " ▓▓▓▓▓▓▓▓▓▀ ,▄▓██░░░░░░▄███████████████▌▓∞²█╜▀██████████▓████▄░░░░░░██ "
Write-Host " ▓▓▓▓▓▓▓▀ ,▄▓ ▐██░░░▄████████████████▓▓█▄▄▄▄██████████████████▄░░░██▀ "
Write-Host " ▓▓▓▓▓▓▓,,▄▓▓▓▓▄▄╦▄▓██▄███▀▀███████████████████▓▓█████████▓████▀▀███╓██▀ "
Write-Host " ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╢████- ▀▀▀▀██████████████████████▀▀▀' `███▀ "
Write-Host " █▌ ████▄ ▐█░░░░░█▌ ▄███▄ ▐█ "
Write-Host " ▐█ ▐█████ ▐█░░░░░█⌐ █████ █▌ "
Write-Host " ██▌ ▀▀` ▐█░░░░░█▌ ▀▀▀ ▐██ "
Write-Host " ██▀█ ╓█░░░░░░╙█▄ ,█▌█▌ "
Write-Host " ██░▀█▄ ▄█⌡▄▄███▄▄░█▄ ▄█▀░▐█ "
Write-Host " ▐██░░░▀██▄, ,▄██▀░██▓▓█▓██▌░▀██▄, ,▄██▀░░░░█▌ "
Write-Host " ████▄░░░░▀▀▀▀▀▀▀▀⌠▄█████████████▄▌▀▀▀▀▀▀▀▀░░░░░▄██▌ "
Write-Host " ██▓█████▄▄▄▄▄▄██████▓████████▓▓██████▄▄▄▄▄▄▄████▓██ "
Write-Host " ██▓██▓▓▓█████▓▓▓███████████████████▓▓▓▓▓▓▓▓████████ "
Write-Host " █████████████▓▓▓████████████████████████████████▓██ "
Write-Host " █████████▓▓▓███████████████████████████████████████ "
Write-Host " ▀██████████████████████████████████████████████▓█▀ "
Write-Host " '▀████████████████▓▓▓▓▓▓██████████████▓▓██▀▀▀ "
Write-Host " ``▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"
Write-Host
Write-Host
Write-Host " https://github.com/MelroyB/PSBettercap"
}
function open-session {
if (Test-Path -Path $script:Sessionfile) {
write-host "Previous session found and imported - $script:Sessionfile" -ForegroundColor Green
$script:objAPs = @(import-clixml $script:Sessionfile)
}
else {
write-host "No previous session found" -ForegroundColor Green
$script:objAPs = @()
}
}
function save-session {
$script:objAPs | export-clixml $script:Sessionfile -Force
}
function add-node {
show-nodes
$addNodeIP = Read-Host -Prompt 'Hostname/IP'
$addNodePort = if (($result = Read-Host "REST API Port [8081]") -eq '') { "8081" }else { $result }
$addNodeProt = if (($result = Read-Host "HTTP or HTTPS [http]") -eq '') { "http" }else { $result }
$addNodeUsername = Read-Host -prompt "Username"
if ($addNodeUsername -eq "") {
$addNodePassword = ""
$addNodeEncodedCreds = ""
}
else {
$addNodePassword = Read-Host -prompt "Password"
$addNodeEncodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($addNodeUsername):$($addNodePassword)"))
}
$addNodeChan = if (($result = Read-Host "Channels to scan [all]") -eq '') { "all" }else { $result }
$addNodeComment = Read-Host -Prompt 'Comment'
$addNodeAPttl = if (($result = Read-Host "AP TTL [300]") -eq '') { "300" }else { $result }
$addNodeSTAttl = if (($result = Read-Host "STA.TTL [300]") -eq '') { "300" }else { $result }
$script:objNodes += new-object psobject -property @{
"ip" = $addNodeIP
"port" = $addNodePort
"protocol" = $addNodeProt
"channel" = $addNodeChan
"comment" = $addNodeComment
"online" = ""
"interface" = ""
"ap.ttl" = $addNodeAPttl
"sta.ttl" = $addNodeSTAttl
"credentials" = $addNodeEncodedCreds
}
save-nodes
}
function open-nodes {
### load node file
if (Test-Path -Path $script:nodefile) {
write-host "Previous nodes found and imported - $script:nodefile" -ForegroundColor Green
$script:objNodes = @(import-clixml $script:nodefile)
}
else {
write-host "No previous nodes found" -ForegroundColor Green
$script:objNodes = @()
}
}
function save-nodes {
$script:objNodes | export-clixml $script:nodefile -Force
}
function remove-node {
$SelectNode = $null
$count = 0
$script:objNodes | select-object ip, port, comment | ForEach-Object {
$_ | Select-Object @{Name = 'ID'; Expression = { $count } }, *
$count++ } | Format-Table -AutoSize
$SelectNode = Read-Host -Prompt 'ID to remove'
$script:objNodes = @($script:objNodes | Where-Object ({ $_.port -ne $script:objNodes[$SelectNode].port -or $_.ip -ne $script:objNodes[$SelectNode].ip }))
save-nodes
load-nodes
}
function show-nodes {
($script:objNodes | format-table online, ip, port, credentials, interface, channel, comment, "ap.ttl", "sta.ttl" | Format-Table | Out-String).Trim()
}
function set-nodeinterface {
$SelectNode = $null
$count = 0
$script:objNodes | select-object ip, port, channel, interface, comment | ForEach-Object {
$_ | Select-Object @{Name = 'ID'; Expression = { $count } }, *
$count++ } | Format-Table -AutoSize
$SelectNode = Read-Host -Prompt 'ID to change interface'
$uri = $script:objNodes[$SelectNode].protocol + '://' + $script:objNodes[$SelectNode].ip + ':' + $script:objNodes[$SelectNode].port + '/api/session'
if ($script:objNodes[$SelectNode].credentials -ne "") {
$Headers = @{
"Authorization" = "Basic $($script:objNodes[$SelectNode].credentials)"
"Content-Type" = "application/json"
}
}
else {
$Headers = @{
"Content-Type" = "application/json"
}
}
$objApiResult = $null
$objApiResult = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $headers -TimeoutSec 5
if ($null -eq $objApiResult) {
}
else {
$selection = $objApiResult.interfaces #| Where-Object {$_.name -like "wl*"}
If ($selection.Count -gt 0) {
$title = "Interfaces"
$message = "Which interface would you like to use?"
# Build the choices menu
$choices = @()
For ($index = 0; $index -lt $selection.Count; $index++) {
$choices += New-Object System.Management.Automation.Host.ChoiceDescription ($selection[$index]).Name, ($selection[$index]).FullName
}
$options = [System.Management.Automation.Host.ChoiceDescription[]]$choices
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
$UpdateNode = $script:objNodes | Where-Object { $_.ip -eq $script:objNodes[$SelectNode].ip } | Where-Object { $_.port -eq $script:objNodes[$SelectNode].port }
$UpdateNode.interface = $selection[$result].name
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"set wifi.interface $($updatenode.interface)`"}" -TimeoutSec 5 }catch { write-host offline }
}
}
save-nodes
}
function set-nodechannels {
$SelectNode = $null
$count = 0
$script:objNodes | select-object ip, port, channel, interface, comment | ForEach-Object {
$_ | Select-Object @{Name = 'ID'; Expression = { $count } }, *
$count++ } | Format-Table -AutoSize
$SelectNode = Read-Host -Prompt 'ID to change channel'
$UpdateNode = $script:objNodes | Where-Object ({ $_.port -eq $script:objNodes[$SelectNode].port -and $_.ip -eq $script:objNodes[$SelectNode].ip })
$UpdateNode.channel = if (($result = Read-Host "Channels to scan [all]") -eq '') { "all" }else { $result }
save-nodes
## send new config to node
$uri = $script:objNodes[$selectnode].protocol + '://' + $script:objNodes[$selectnode].ip + ':' + $script:objNodes[$selectnode].port + '/api/session'
if ($script:objNodes[$SelectNode].credentials -ne "") {
$Headers = @{
"Authorization" = "Basic $($script:objNodes[$SelectNode].credentials)"
"Content-Type" = "application/json"
}
}
else {
$Headers = @{
"Content-Type" = "application/json"
}
}
if ($UpdateNode.channel -eq "all") {
Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"wifi.recon.channel clear`"}"
}
else {
Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"wifi.recon.channel $($UpdateNode.channel)`"}"
}
}
function set-nodettl {
$SelectNode = $null
$count = 0
$script:objNodes | select-object ip, port, channel, interface, comment | ForEach-Object {
$_ | Select-Object @{Name = 'ID'; Expression = { $count } }, *
$count++ } | Format-Table -AutoSize
$SelectNode = Read-Host -Prompt 'ID to change TTL'
$UpdateNode = $script:objNodes | Where-Object ({ $_.port -eq $script:objNodes[$SelectNode].port -and $_.ip -eq $script:objNodes[$SelectNode].ip })
$updateNode.'ap.ttl' = if (($result = Read-Host "AP TTL [300]") -eq '') { "300" }else { $result }
$updateNode.'sta.ttl' = if (($result = Read-Host "STA.TTL [300]") -eq '') { "300" }else { $result }
save-nodes
## send new config to node
$uri = $script:objNodes[$selectnode].protocol + '://' + $script:objNodes[$selectnode].ip + ':' + $script:objNodes[$selectnode].port + '/api/session'
if ($script:objNodes[$SelectNode].credentials -ne "") {
$Headers = @{
"Authorization" = "Basic $($script:objNodes[$SelectNode].credentials)"
"Content-Type" = "application/json"
}
}
else {
$Headers = @{
"Content-Type" = "application/json"
}
}
Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"set wifi.ap.ttl $($updateNode.'ap.ttl')`"}"
Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"set wifi.sta.ttl $($updateNode.'sta.ttl')`"}"
}
function Start-Nodes {
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
foreach ($objNode in $script:objNodes) {
$uri = $objnode.protocol + '://' + $objNode.ip + ':' + $objNode.port + '/api/session'
if ($objNode.channel -eq "all") {
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"wifi.recon.channel clear`"}" }catch {}
}
else {
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"wifi.recon.channel $($objNode.channel)`"}" -TimeoutSec 5 }catch {}
}
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"set wifi.ap.ttl $($objNode.'ap.ttl')`"}" -TimeoutSec 5 }catch {}
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"set wifi.sta.ttl $($objNode.'sta.ttl')`"}" -TimeoutSec 5 }catch {}
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"set wifi.interface $($objNode.interface)`"}" -TimeoutSec 5 }catch {}
try { Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"wifi.recon on`"}" -TimeoutSec 5 }catch {}
}
}
function Stop-Nodes {
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
foreach ($objNode in $script:objNodes) {
$uri = $objnode.protocol + '://' + $objNode.ip + ':' + $objNode.port + '/api/session'
Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"wifi.recon off`"}" -TimeoutSec 10
}
}
function PowerOff-Nodes {
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
foreach ($objNode in $script:objNodes) {
$uri = $objnode.protocol + '://' + $objNode.ip + ':' + $objNode.port + '/api/session'
Invoke-RestMethod -uri $uri -Method 'POST' -Headers $headers -Body "{`"cmd`": `"!shutdown -h -t 0`"}" -TimeoutSec 10
}
}
function new-event($eventmessage, $eventcolor, $eventbcolor) {
$script:events += new-object psobject -property @{message = $eventmessage; color = $eventcolor; bcolor = $eventbcolor }
}
function show-events {
$script:events = $script:events | Select-Object -Last 15
foreach ($objEvent in $script:events) { write-host $objEvent.message -ForegroundColor $objEvent.color -BackgroundColor $objEvent.bcolor }
}
Function GetKeyPress([string]$regexPattern = '[ynq]', [string]$message = $null, [int]$timeOutSeconds = 0) {
$key = $null
# $Host.UI.RawUI.FlushInputBuffer() # Werkt niet met linux
if (![string]::IsNullOrEmpty($message))
{ Write-Host -NoNewLine $message }
$counter = $timeOutSeconds * 1000 / 250
while ($null -eq $key -and ($timeOutSeconds -eq 0 -or $counter-- -gt 0)) {
if (($timeOutSeconds -eq 0) -or $Host.UI.RawUI.KeyAvailable) {
$key_ = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,IncludeKeyUp")
if ($key_.KeyDown -and $key_.Character -match $regexPattern)
{ $key = $key_ }
}
else {
Start-Sleep -m 250 # Milliseconds }
}
}
if (-not ($null -eq $key)) { Write-Host -NoNewLine "$($key.Character)" }
if (![string]::IsNullOrEmpty($message)) {
Write-Host "" # newline}
return $(if ($null -eq $key) { $null } else { $key.Character })
}
}
set-basics
show-banner
open-session
open-nodes
$continue = $true
while ($continue) {
$prompt = Read-Host -Prompt '>'
if ($prompt -eq "exit") { $continue = $false }
if ($prompt -eq "show") { Show-BettercapAPs }
if ($prompt -like "nodes*") { command-nodes $prompt }
if ($prompt -eq "help") { show-help }
if ($prompt -eq "start") {
Write-host "Retrieving data, please wait..."
$continue2 = $true
while ($continue2) {
Get-BettercapAPs
#Clear-Host
Clear-Host
write-HostCenter "######## Last 20 APS ########"
($script:objAPs | Sort-Object -Property last_seen | Select-Object -last 20 | Format-table -Property last_seen, mac, hostname, channel, encryption, auth, handshake, pmkid, clients, latitude, longitude, detectedby | Format-Table)
Write-HostCenter "########### Nodes ###########"
show-nodes
Write-HostCenter "########### Events ##########"
show-events
Write-HostCenter "#############################"
Write-host $script:objAPs.count "Accesspoints / " -NoNewline
Write-host $OBJgps.NumSatellites "GPS Sattelites"
Write-host "press q to return to prompt " -NoNewline
$key = GetKeyPress '[q]' "(q)?" 2
if ($key -eq "q") { $continue2 = $false }
}
}
}
# Exit
new-map
export-results
save-session
save-nodes
# TODO
# curl -X POST -F "email=SOME_VALID_EMAIL" -F "file=@/path/to/handshake.pcap" https://api.onlinehashcrack.com