forked from danielbohannon/Invoke-Obfuscation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Invoke-Obfuscation.ps1
2189 lines (1882 loc) · 129 KB
/
Invoke-Obfuscation.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
# This file is part of Invoke-Obfuscation.
#
# Copyright 2017 Daniel Bohannon <@danielhbohannon>
# while at Mandiant <http://www.mandiant.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Function Invoke-Obfuscation
{
<#
.SYNOPSIS
Master function that orchestrates the application of all obfuscation functions to provided PowerShell script block or script path contents. Interactive mode enables one to explore all available obfuscation functions and apply them incrementally to input PowerShell script block or script path contents.
Invoke-Obfuscation Function: Invoke-Obfuscation
Author: Daniel Bohannon (@danielhbohannon)
License: Apache License, Version 2.0
Required Dependencies: Show-AsciiArt, Show-HelpMenu, Show-Menu, Show-OptionsMenu, Show-Tutorial and Out-ScriptContents (all located in Invoke-Obfuscation.ps1)
Optional Dependencies: None
.DESCRIPTION
Invoke-Obfuscation orchestrates the application of all obfuscation functions to provided PowerShell script block or script path contents to evade detection by simple IOCs and process execution monitoring relying solely on command-line arguments and common parent-child process relationships.
.PARAMETER ScriptBlock
Specifies a scriptblock containing your payload.
.PARAMETER ScriptPath
Specifies the path to your payload (can be local file, UNC-path, or remote URI).
.PARAMETER Command
Specifies the obfuscation commands to run against the input ScriptBlock or ScriptPath parameter.
.PARAMETER NoExit
(Optional - only works if Command is specified) Outputs the option to not exit after running obfuscation commands defined in Command parameter.
.PARAMETER Quiet
(Optional - only works if Command is specified) Outputs the option to output only the final obfuscated result via stdout.
.EXAMPLE
C:\PS> Import-Module .\Invoke-Obfuscation.psd1; Invoke-Obfuscation
C:\PS> Import-Module .\Invoke-Obfuscation.psd1; Invoke-Obfuscation -ScriptBlock {Write-Host 'Hello World!' -ForegroundColor Green; Write-Host 'Obfuscation Rocks!' -ForegroundColor Green}
C:\PS> Import-Module .\Invoke-Obfuscation.psd1; Invoke-Obfuscation -ScriptBlock {Write-Host 'Hello World!' -ForegroundColor Green; Write-Host 'Obfuscation Rocks!' -ForegroundColor Green} -Command 'TOKEN\ALL\1,1,TEST,LAUNCHER\STDIN++\2347,CLIP'
C:\PS> Import-Module .\Invoke-Obfuscation.psd1; Invoke-Obfuscation -ScriptBlock {Write-Host 'Hello World!' -ForegroundColor Green; Write-Host 'Obfuscation Rocks!' -ForegroundColor Green} -Command 'TOKEN\ALL\1,1,TEST,LAUNCHER\STDIN++\2347,CLIP' -NoExit
C:\PS> Import-Module .\Invoke-Obfuscation.psd1; Invoke-Obfuscation -ScriptBlock {Write-Host 'Hello World!' -ForegroundColor Green; Write-Host 'Obfuscation Rocks!' -ForegroundColor Green} -Command 'TOKEN\ALL\1,1,TEST,LAUNCHER\STDIN++\2347,CLIP' -Quiet
C:\PS> Import-Module .\Invoke-Obfuscation.psd1; Invoke-Obfuscation -ScriptBlock {Write-Host 'Hello World!' -ForegroundColor Green; Write-Host 'Obfuscation Rocks!' -ForegroundColor Green} -Command 'TOKEN\ALL\1,1,TEST,LAUNCHER\STDIN++\2347,CLIP' -NoExit -Quiet
.NOTES
Invoke-Obfuscation orchestrates the application of all obfuscation functions to provided PowerShell script block or script path contents to evade detection by simple IOCs and process execution monitoring relying solely on command-line arguments.
This is a personal project developed by Daniel Bohannon while an employee at MANDIANT, A FireEye Company.
.LINK
http://www.danielbohannon.com
#>
[CmdletBinding(DefaultParameterSetName = 'ScriptBlock')] Param (
[Parameter(Position = 0, ValueFromPipeline = $True, ParameterSetName = 'ScriptBlock')]
[ValidateNotNullOrEmpty()]
[ScriptBlock]
$ScriptBlock,
[Parameter(Position = 0, ParameterSetName = 'ScriptPath')]
[ValidateNotNullOrEmpty()]
[String]
$ScriptPath,
[String]
$Command,
[Switch]
$NoExit,
[Switch]
$Quiet
)
# Define variables for CLI functionality.
$Script:CliCommands = @()
$Script:CompoundCommand = @()
$Script:QuietWasSpecified = $FALSE
$CliWasSpecified = $FALSE
$NoExitWasSpecified = $FALSE
# Either convert ScriptBlock to a String or convert script at $Path to a String.
If($PSBoundParameters['ScriptBlock'])
{
$Script:CliCommands += ('set scriptblock ' + [String]$ScriptBlock)
}
If($PSBoundParameters['ScriptPath'])
{
$Script:CliCommands += ('set scriptpath ' + $ScriptPath)
}
# Append Command to CliCommands if specified by user input.
If($PSBoundParameters['Command'])
{
$Script:CliCommands += $Command.Split(',')
$CliWasSpecified = $TRUE
If($PSBoundParameters['NoExit'])
{
$NoExitWasSpecified = $TRUE
}
If($PSBoundParameters['Quiet'])
{
# Create empty Write-Host and Start-Sleep proxy functions to cause any Write-Host or Start-Sleep invocations to not do anything until non-interactive -Command values are finished being processed.
Function Write-Host {}
Function Start-Sleep {}
$Script:QuietWasSpecified = $TRUE
}
}
########################################
## Script-wide variable instantiation ##
########################################
# Script-level array of Show Options menu, set as SCRIPT-level so it can be set from within any of the functions.
# Build out menu for Show Options selection from user in Show-OptionsMenu menu.
$Script:ScriptPath = ''
$Script:ScriptBlock = ''
$Script:CliSyntax = @()
$Script:ExecutionCommands = @()
$Script:ObfuscatedCommand = ''
$Script:ObfuscatedCommandHistory = @()
$Script:ObfuscationLength = ''
$Script:OptionsMenu = @()
$Script:OptionsMenu += , @('ScriptPath ' , $Script:ScriptPath , $TRUE)
$Script:OptionsMenu += , @('ScriptBlock' , $Script:ScriptBlock , $TRUE)
$Script:OptionsMenu += , @('CommandLineSyntax' , $Script:CliSyntax , $FALSE)
$Script:OptionsMenu += , @('ExecutionCommands' , $Script:ExecutionCommands, $FALSE)
$Script:OptionsMenu += , @('ObfuscatedCommand' , $Script:ObfuscatedCommand, $FALSE)
$Script:OptionsMenu += , @('ObfuscationLength' , $Script:ObfuscatedCommand, $FALSE)
# Build out $SetInputOptions from above items set as $TRUE (as settable).
$SettableInputOptions = @()
ForEach($Option in $Script:OptionsMenu)
{
If($Option[2]) {$SettableInputOptions += ([String]$Option[0]).ToLower().Trim()}
}
# Script-level variable for whether LAUNCHER has been applied to current ObfuscatedToken.
$Script:LauncherApplied = $FALSE
# Ensure Invoke-Obfuscation module was properly imported before continuing.
If(!(Get-Module Invoke-Obfuscation | Where-Object {$_.ModuleType -eq 'Manifest'}))
{
$PathTopsd1 = "$ScriptDir\Invoke-Obfuscation.psd1"
If($PathTopsd1.Contains(' ')) {$PathTopsd1 = '"' + $PathTopsd1 + '"'}
Write-Host "`n`nERROR: Invoke-Obfuscation module is not loaded. You must run:" -ForegroundColor Red
Write-Host " Import-Module $PathTopsd1`n`n" -ForegroundColor Yellow
Start-Sleep -Seconds 3
Exit
}
# Maximum size for cmd.exe and clipboard.
$CmdMaxLength = 8190
# Build interactive menus.
$LineSpacing = '[*] '
# Main Menu.
$MenuLevel = @()
$MenuLevel+= , @($LineSpacing, 'TOKEN' , 'Obfuscate PowerShell command <Tokens>')
$MenuLevel+= , @($LineSpacing, 'AST' , "`tObfuscate PowerShell <Ast> nodes <(PS3.0+)>")
$MenuLevel+= , @($LineSpacing, 'STRING' , 'Obfuscate entire command as a <String>')
$MenuLevel+= , @($LineSpacing, 'ENCODING' , 'Obfuscate entire command via <Encoding>')
$MenuLevel+= , @($LineSpacing, 'COMPRESS' , 'Convert entire command to one-liner and <Compress>')
$MenuLevel+= , @($LineSpacing, 'LAUNCHER' , 'Obfuscate command args w/<Launcher> techniques (run once at end)')
# Main\Token Menu.
$MenuLevel_Token = @()
$MenuLevel_Token += , @($LineSpacing, 'STRING' , 'Obfuscate <String> tokens (suggested to run first)')
$MenuLevel_Token += , @($LineSpacing, 'COMMAND' , 'Obfuscate <Command> tokens')
$MenuLevel_Token += , @($LineSpacing, 'ARGUMENT' , 'Obfuscate <Argument> tokens')
$MenuLevel_Token += , @($LineSpacing, 'MEMBER' , 'Obfuscate <Member> tokens')
$MenuLevel_Token += , @($LineSpacing, 'VARIABLE' , 'Obfuscate <Variable> tokens')
$MenuLevel_Token += , @($LineSpacing, 'TYPE ' , 'Obfuscate <Type> tokens')
$MenuLevel_Token += , @($LineSpacing, 'COMMENT' , 'Remove all <Comment> tokens')
$MenuLevel_Token += , @($LineSpacing, 'WHITESPACE' , 'Insert random <Whitespace> (suggested to run last)')
$MenuLevel_Token += , @($LineSpacing, 'ALL ' , 'Select <All> choices from above (random order)')
$MenuLevel_Token_String = @()
$MenuLevel_Token_String += , @($LineSpacing, '1' , "Concatenate --> e.g. <('co'+'ffe'+'e')>" , @('Out-ObfuscatedTokenCommand', 'String', 1))
$MenuLevel_Token_String += , @($LineSpacing, '2' , "Reorder --> e.g. <('{1}{0}'-f'ffee','co')>" , @('Out-ObfuscatedTokenCommand', 'String', 2))
$MenuLevel_Token_Command = @()
$MenuLevel_Token_Command += , @($LineSpacing, '1' , 'Ticks --> e.g. <Ne`w-O`Bject>' , @('Out-ObfuscatedTokenCommand', 'Command', 1))
$MenuLevel_Token_Command += , @($LineSpacing, '2' , "Splatting + Concatenate --> e.g. <&('Ne'+'w-Ob'+'ject')>" , @('Out-ObfuscatedTokenCommand', 'Command', 2))
$MenuLevel_Token_Command += , @($LineSpacing, '3' , "Splatting + Reorder --> e.g. <&('{1}{0}'-f'bject','New-O')>" , @('Out-ObfuscatedTokenCommand', 'Command', 3))
$MenuLevel_Token_Argument = @()
$MenuLevel_Token_Argument += , @($LineSpacing, '1' , 'Random Case --> e.g. <nEt.weBclIenT>' , @('Out-ObfuscatedTokenCommand', 'CommandArgument', 1))
$MenuLevel_Token_Argument += , @($LineSpacing, '2' , 'Ticks --> e.g. <nE`T.we`Bc`lIe`NT>' , @('Out-ObfuscatedTokenCommand', 'CommandArgument', 2))
$MenuLevel_Token_Argument += , @($LineSpacing, '3' , "Concatenate --> e.g. <('Ne'+'t.We'+'bClient')>" , @('Out-ObfuscatedTokenCommand', 'CommandArgument', 3))
$MenuLevel_Token_Argument += , @($LineSpacing, '4' , "Reorder --> e.g. <('{1}{0}'-f'bClient','Net.We')>" , @('Out-ObfuscatedTokenCommand', 'CommandArgument', 4))
$MenuLevel_Token_Member = @()
$MenuLevel_Token_Member += , @($LineSpacing, '1' , 'Random Case --> e.g. <dOwnLoAdsTRing>' , @('Out-ObfuscatedTokenCommand', 'Member', 1))
$MenuLevel_Token_Member += , @($LineSpacing, '2' , 'Ticks --> e.g. <d`Ow`NLoAd`STRin`g>' , @('Out-ObfuscatedTokenCommand', 'Member', 2))
$MenuLevel_Token_Member += , @($LineSpacing, '3' , "Concatenate --> e.g. <('dOwnLo'+'AdsT'+'Ring').Invoke()>" , @('Out-ObfuscatedTokenCommand', 'Member', 3))
$MenuLevel_Token_Member += , @($LineSpacing, '4' , "Reorder --> e.g. <('{1}{0}'-f'dString','Downloa').Invoke()>" , @('Out-ObfuscatedTokenCommand', 'Member', 4))
$MenuLevel_Token_Variable = @()
$MenuLevel_Token_Variable += , @($LineSpacing, '1' , 'Random Case + {} + Ticks --> e.g. <${c`hEm`eX}>' , @('Out-ObfuscatedTokenCommand', 'Variable', 1))
$MenuLevel_Token_Type = @()
$MenuLevel_Token_Type += , @($LineSpacing, '1' , "Type Cast + Concatenate --> e.g. <[Type]('Con'+'sole')>" , @('Out-ObfuscatedTokenCommand', 'Type', 1))
$MenuLevel_Token_Type += , @($LineSpacing, '2' , "Type Cast + Reordered --> e.g. <[Type]('{1}{0}'-f'sole','Con')>" , @('Out-ObfuscatedTokenCommand', 'Type', 2))
$MenuLevel_Token_Whitespace = @()
$MenuLevel_Token_Whitespace += , @($LineSpacing, '1' , "`tRandom Whitespace --> e.g. <.( 'Ne' +'w-Ob' + 'ject')>" , @('Out-ObfuscatedTokenCommand', 'RandomWhitespace', 1))
$MenuLevel_Token_Comment = @()
$MenuLevel_Token_Comment += , @($LineSpacing, '1' , "Remove Comments --> e.g. self-explanatory" , @('Out-ObfuscatedTokenCommand', 'Comment', 1))
$MenuLevel_Token_All = @()
$MenuLevel_Token_All += , @($LineSpacing, '1' , "`tExecute <ALL> Token obfuscation techniques (random order)" , @('Out-ObfuscatedTokenCommandAll', '', ''))
# Main\Token Menu.
$MenuLevel_Ast = @()
$MenuLevel_Ast += , @($LineSpacing, 'NamedAttributeArgumentAst' , 'Obfuscate <NamedAttributeArgumentAst> nodes')
$MenuLevel_Ast += , @($LineSpacing, 'ParamBlockAst' , "`t`tObfuscate <ParamBlockAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'ScriptBlockAst' , "`t`tObfuscate <ScriptBlockAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'AttributeAst' , "`t`tObfuscate <AttributeAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'BinaryExpressionAst' , "`tObfuscate <BinaryExpressionAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'HashtableAst' , "`t`tObfuscate <HashtableAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'CommandAst' , "`t`tObfuscate <CommandAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'AssignmentStatementAst' , "`tObfuscate <AssignmentStatementAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'TypeExpressionAst' , "`tObfuscate <TypeExpressionAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'TypeConstraintAst' , "`tObfuscate <TypeConstraintAst> nodes")
$MenuLevel_Ast += , @($LineSpacing, 'ALL' , "`t`t`tSelect <All> choices from above")
$MenuLevel_Ast_NamedAttributeArgumentAst = @()
$MenuLevel_Ast_NamedAttributeArgumentAst += , @($LineSpacing, '1' , 'Reorder e.g. <[Parameter(Mandatory, ValueFromPipeline = $True)]> --> <[Parameter(Mandatory = $True, ValueFromPipeline)]>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.NamedAttributeArgumentAst'), 1))
$MenuLevel_Ast_ParamBlockAst = @()
$MenuLevel_Ast_ParamBlockAst += , @($LineSpacing, '1' , 'Reorder e.g. <Param([Int]$One, [Int]$Two)> --> <Param([Int]$Two, [Int]$One)>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.ParamBlockAst'), 1))
$MenuLevel_Ast_ScriptBlockAst = @()
$MenuLevel_Ast_ScriptBlockAst += , @($LineSpacing, '1' , 'Reorder e.g. <{ Begin {} Process {} End {} }> --> <{ End {} Begin {} Process {} }>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.ScriptBlockAst'), 1))
$MenuLevel_Ast_AttributeAst = @()
$MenuLevel_Ast_AttributeAst += , @($LineSpacing, '1' , 'Reorder e.g. <[Parameter(Position = 0, Mandatory)]> --> <[Parameter(Mandatory, Position = 0)]>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.AttributeAst'), 1))
$MenuLevel_Ast_BinaryExpressionAst = @()
$MenuLevel_Ast_BinaryExpressionAst += , @($LineSpacing, '1' , 'Reorder e.g. <(2 + 3) * 4> --> <4 * (3 + 2)>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.BinaryExpressionAst'), 1))
$MenuLevel_Ast_HashtableAst = @()
$MenuLevel_Ast_HashtableAst += , @($LineSpacing, '1' , "Reorder e.g. <@{ProviderName = 'Microsoft-Windows-PowerShell'; Id = 4104}> --> <@{Id = 4104; ProviderName = 'Microsoft-Windows-PowerShell'}>" , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.HashtableAst'), 1))
$MenuLevel_Ast_CommandAst = @()
$MenuLevel_Ast_CommandAst += , @($LineSpacing, '1' , 'Reorder e.g. <Get-Random -Min 1 -Max 100> --> <Get-Random -Max 100 -Min 1>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.CommandAst'), 1))
$MenuLevel_Ast_AssignmentStatementAst = @()
$MenuLevel_Ast_AssignmentStatementAst += , @($LineSpacing, '1' , 'Rename e.g. <$Example = "Example"> --> <Set-Variable -Name Example -Value ("Example")>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.AssignmentStatementAst'), 1))
$MenuLevel_Ast_TypeExpressionAst = @()
$MenuLevel_Ast_TypeExpressionAst += , @($LineSpacing, '1' , 'Rename e.g. <[ScriptBlock]> --> <[Management.Automation.ScriptBlock]>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.TypeExpressionAst'), 1))
$MenuLevel_Ast_TypeConstraintAst = @()
$MenuLevel_Ast_TypeConstraintAst += , @($LineSpacing, '1' , 'Rename e.g. <[Int] $Integer = 1> --> <[System.Int32] $Integer = 1>' , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.TypeConstraintAst'), 1))
$MenuLevel_Ast_All = @()
$MenuLevel_Ast_All += , @($LineSpacing, '1' , "`tExecute <ALL> Ast obfuscation techniques" , @('Out-ObfuscatedAst', @('System.Management.Automation.Language.NamedAttributeArgumentAst', 'System.Management.Automation.Language.ParamBlockAst', 'System.Management.Automation.Language.ScriptBlockAst', 'System.Management.Automation.Language.AttributeAst', 'System.Management.Automation.Language.BinaryExpressionAst', 'System.Management.Automation.Language.HashtableAst', 'System.Management.Automation.Language.CommandAst', 'System.Management.Automation.Language.AssignmentStatementAst', 'System.Management.Automation.Language.TypeExpressionAst', 'System.Management.Automation.Language.TypeConstraintAst'), ''))
# Main\String Menu.
$MenuLevel_String = @()
$MenuLevel_String += , @($LineSpacing, '1' , '<Concatenate> entire command' , @('Out-ObfuscatedStringCommand', '', 1))
$MenuLevel_String += , @($LineSpacing, '2' , '<Reorder> entire command after concatenating' , @('Out-ObfuscatedStringCommand', '', 2))
$MenuLevel_String += , @($LineSpacing, '3' , '<Reverse> entire command after concatenating' , @('Out-ObfuscatedStringCommand', '', 3))
# Main\Encoding Menu.
$MenuLevel_Encoding = @()
$MenuLevel_Encoding += , @($LineSpacing, '1' , "`tEncode entire command as <ASCII>" , @('Out-EncodedAsciiCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '2' , "`tEncode entire command as <Hex>" , @('Out-EncodedHexCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '3' , "`tEncode entire command as <Octal>" , @('Out-EncodedOctalCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '4' , "`tEncode entire command as <Binary>" , @('Out-EncodedBinaryCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '5' , "`tEncrypt entire command as <SecureString> (AES)" , @('Out-SecureStringCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '6' , "`tEncode entire command as <BXOR>" , @('Out-EncodedBXORCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '7' , "`tEncode entire command as <Special Characters>" , @('Out-EncodedSpecialCharOnlyCommand' , '', ''))
$MenuLevel_Encoding += , @($LineSpacing, '8' , "`tEncode entire command as <Whitespace>" , @('Out-EncodedWhitespaceCommand' , '', ''))
# Main\Compress Menu.
$MenuLevel_Compress = @()
$MenuLevel_Compress += , @($LineSpacing, '1' , "Convert entire command to one-liner and <compress>" , @('Out-CompressedCommand' , '', ''))
# Main\Launcher Menu.
$MenuLevel_Launcher = @()
$MenuLevel_Launcher += , @($LineSpacing, 'PS' , "`t<PowerShell>")
$MenuLevel_Launcher += , @($LineSpacing, 'CMD' , '<Cmd> + PowerShell')
$MenuLevel_Launcher += , @($LineSpacing, 'WMIC' , '<Wmic> + PowerShell')
$MenuLevel_Launcher += , @($LineSpacing, 'RUNDLL' , '<Rundll32> + PowerShell')
$MenuLevel_Launcher += , @($LineSpacing, 'VAR+' , 'Cmd + set <Var> && PowerShell iex <Var>')
$MenuLevel_Launcher += , @($LineSpacing, 'STDIN+' , 'Cmd + <Echo> | PowerShell - (stdin)')
$MenuLevel_Launcher += , @($LineSpacing, 'CLIP+' , 'Cmd + <Echo> | Clip && PowerShell iex <clipboard>')
$MenuLevel_Launcher += , @($LineSpacing, 'VAR++' , 'Cmd + set <Var> && Cmd && PowerShell iex <Var>')
$MenuLevel_Launcher += , @($LineSpacing, 'STDIN++' , 'Cmd + set <Var> && Cmd <Echo> | PowerShell - (stdin)')
$MenuLevel_Launcher += , @($LineSpacing, 'CLIP++' , 'Cmd + <Echo> | Clip && Cmd && PowerShell iex <clipboard>')
$MenuLevel_Launcher += , @($LineSpacing, 'RUNDLL++' , 'Cmd + set Var && <Rundll32> && PowerShell iex Var')
$MenuLevel_Launcher += , @($LineSpacing, 'MSHTA++' , 'Cmd + set Var && <Mshta> && PowerShell iex Var')
$MenuLevel_Launcher_PS = @()
$MenuLevel_Launcher_PS += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
$MenuLevel_Launcher_PS += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_PS += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '1'))
$MenuLevel_Launcher_CMD = @()
$MenuLevel_Launcher_CMD += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_CMD += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '2'))
$MenuLevel_Launcher_WMIC = @()
$MenuLevel_Launcher_WMIC += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_WMIC += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '3'))
$MenuLevel_Launcher_RUNDLL = @()
$MenuLevel_Launcher_RUNDLL += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '4'))
$MenuLevel_Launcher_RUNDLL += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '4'))
${MenuLevel_Launcher_VAR+} = @()
${MenuLevel_Launcher_VAR+} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_VAR+} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '5'))
${MenuLevel_Launcher_STDIN+} = @()
${MenuLevel_Launcher_STDIN+} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_STDIN+} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '6'))
${MenuLevel_Launcher_CLIP+} = @()
${MenuLevel_Launcher_CLIP+} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_CLIP+} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '7'))
${MenuLevel_Launcher_VAR++} = @()
${MenuLevel_Launcher_VAR++} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_VAR++} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '8'))
${MenuLevel_Launcher_STDIN++} = @()
${MenuLevel_Launcher_STDIN++} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '0' , "`tNO EXECUTION FLAGS" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '1' , "`t-NoExit" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '2' , "`t-NonInteractive" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '3' , "`t-NoLogo" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '4' , "`t-NoProfile" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '5' , "`t-Command" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '6' , "`t-WindowStyle Hidden" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '7' , "`t-ExecutionPolicy Bypass" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_STDIN++} += , @($LineSpacing, '8' , "`t-Wow64 (to path 32-bit powershell.exe)" , @('Out-PowerShellLauncher', '', '9'))
${MenuLevel_Launcher_CLIP++} = @()
${MenuLevel_Launcher_CLIP++} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_CLIP++} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '10'))
${MenuLevel_Launcher_RUNDLL++} = @()
${MenuLevel_Launcher_RUNDLL++} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_RUNDLL++} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '11'))
${MenuLevel_Launcher_MSHTA++} = @()
${MenuLevel_Launcher_MSHTA++} += , @("Enter string of numbers with all desired flags to pass to function. (e.g. 23459)`n", '' , '' , @('', '', ''))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '0' , 'NO EXECUTION FLAGS' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '1' , '-NoExit' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '2' , '-NonInteractive' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '3' , '-NoLogo' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '4' , '-NoProfile' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '5' , '-Command' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '6' , '-WindowStyle Hidden' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '7' , '-ExecutionPolicy Bypass' , @('Out-PowerShellLauncher', '', '12'))
${MenuLevel_Launcher_MSHTA++} += , @($LineSpacing, '8' , '-Wow64 (to path 32-bit powershell.exe)' , @('Out-PowerShellLauncher', '', '12'))
# Input options to display non-interactive menus or perform actions.
$TutorialInputOptions = @(@('tutorial') , "<Tutorial> of how to use this tool `t " )
$MenuInputOptionsShowHelp = @(@('help','get-help','?','-?','/?','menu'), "Show this <Help> Menu `t " )
$MenuInputOptionsShowOptions = @(@('show options','show','options') , "<Show options> for payload to obfuscate `t " )
$ClearScreenInputOptions = @(@('clear','clear-host','cls') , "<Clear> screen `t " )
$CopyToClipboardInputOptions = @(@('copy','clip','clipboard') , "<Copy> ObfuscatedCommand to clipboard `t " )
$OutputToDiskInputOptions = @(@('out') , "Write ObfuscatedCommand <Out> to disk `t " )
$ExecutionInputOptions = @(@('exec','execute','test','run') , "<Execute> ObfuscatedCommand locally `t " )
$ResetObfuscationInputOptions = @(@('reset') , "<Reset> ALL obfuscation for ObfuscatedCommand ")
$UndoObfuscationInputOptions = @(@('undo') , "<Undo> LAST obfuscation for ObfuscatedCommand ")
$BackCommandInputOptions = @(@('back','cd ..') , "Go <Back> to previous obfuscation menu `t " )
$ExitCommandInputOptions = @(@('quit','exit') , "<Quit> Invoke-Obfuscation `t " )
$HomeMenuInputOptions = @(@('home','main') , "Return to <Home> Menu `t " )
# For Version 1.0 ASCII art is not necessary.
#$ShowAsciiArtInputOptions = @(@('ascii') , "Display random <ASCII> art for the lulz :)`t")
# Add all above input options lists to be displayed in SHOW OPTIONS menu.
$AllAvailableInputOptionsLists = @()
$AllAvailableInputOptionsLists += , $TutorialInputOptions
$AllAvailableInputOptionsLists += , $MenuInputOptionsShowHelp
$AllAvailableInputOptionsLists += , $MenuInputOptionsShowOptions
$AllAvailableInputOptionsLists += , $ClearScreenInputOptions
$AllAvailableInputOptionsLists += , $ExecutionInputOptions
$AllAvailableInputOptionsLists += , $CopyToClipboardInputOptions
$AllAvailableInputOptionsLists += , $OutputToDiskInputOptions
$AllAvailableInputOptionsLists += , $ResetObfuscationInputOptions
$AllAvailableInputOptionsLists += , $UndoObfuscationInputOptions
$AllAvailableInputOptionsLists += , $BackCommandInputOptions
$AllAvailableInputOptionsLists += , $ExitCommandInputOptions
$AllAvailableInputOptionsLists += , $HomeMenuInputOptions
# For Version 1.0 ASCII art is not necessary.
#$AllAvailableInputOptionsLists += , $ShowAsciiArtInputOptions
# Input options to change interactive menus.
$ExitInputOptions = $ExitCommandInputOptions[0]
$MenuInputOptions = $BackCommandInputOptions[0]
# Obligatory ASCII Art.
Show-AsciiArt
Start-Sleep -Seconds 2
# Show Help Menu once at beginning of script.
Show-HelpMenu
# Main loop for user interaction. Show-Menu function displays current function along with acceptable input options (defined in arrays instantiated above).
# User input and validation is handled within Show-Menu.
$UserResponse = ''
While($ExitInputOptions -NotContains ([String]$UserResponse).ToLower())
{
$UserResponse = ([String]$UserResponse).Trim()
If($HomeMenuInputOptions[0] -Contains ([String]$UserResponse).ToLower())
{
$UserResponse = ''
}
# Display menu if it is defined in a menu variable with $UserResponse in the variable name.
If(Test-Path ('Variable:' + "MenuLevel$UserResponse"))
{
$UserResponse = Show-Menu (Get-Variable "MenuLevel$UserResponse").Value $UserResponse $Script:OptionsMenu
}
Else
{
Write-Error "The variable MenuLevel$UserResponse does not exist."
$UserResponse = 'quit'
}
If(($UserResponse -eq 'quit') -AND $CliWasSpecified -AND !$NoExitWasSpecified)
{
Write-Output $Script:ObfuscatedCommand.Trim("`n")
$UserInput = 'quit'
}
}
}
# Get location of this script no matter what the current directory is for the process executing this script.
$ScriptDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
Function Show-Menu
{
<#
.SYNOPSIS
HELPER FUNCTION :: Displays current menu with obfuscation navigation and application options for Invoke-Obfuscation.
Invoke-Obfuscation Function: Show-Menu
Author: Daniel Bohannon (@danielhbohannon)
License: Apache License, Version 2.0
Required Dependencies: None
Optional Dependencies: None
.DESCRIPTION
Show-Menu displays current menu with obfuscation navigation and application options for Invoke-Obfuscation.
.PARAMETER Menu
Specifies the menu options to display, with acceptable input options parsed out of this array.
.PARAMETER MenuName
Specifies the menu header display and the breadcrumb used in the interactive prompt display.
.PARAMETER Script:OptionsMenu
Specifies the script-wide variable containing additional acceptable input in addition to each menu's specific acceptable input (e.g. EXIT, QUIT, BACK, HOME, MAIN, etc.).
.EXAMPLE
C:\PS> Show-Menu
.NOTES
This is a personal project developed by Daniel Bohannon while an employee at MANDIANT, A FireEye Company.
.LINK
http://www.danielbohannon.com
#>
Param(
[Parameter(ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[Object[]]
$Menu,
[String]
$MenuName,
[Object[]]
$Script:OptionsMenu
)
# Extract all acceptable values from $Menu.
$AcceptableInput = @()
$SelectionContainsCommand = $FALSE
ForEach($Line in $Menu)
{
# If there are 4 items in each $Line in $Menu then the fourth item is a command to exec if selected.
If($Line.Count -eq 4)
{
$SelectionContainsCommand = $TRUE
}
$AcceptableInput += ($Line[1]).Trim(' ')
}
$UserInput = $NULL
While($AcceptableInput -NotContains $UserInput)
{
# Format custom breadcrumb prompt.
Write-Host "`n"
$BreadCrumb = $MenuName.Trim('_')
If($BreadCrumb.Length -gt 1)
{
If($BreadCrumb.ToLower() -eq 'show options')
{
$BreadCrumb = 'Show Options'
}
If($MenuName -ne '')
{
# Handle specific case substitutions from what is ALL CAPS in interactive menu and then correct casing we want to appear in the Breadcrumb.
$BreadCrumbOCD = @()
$BreadCrumbOCD += , @('ps' ,'PS')
$BreadCrumbOCD += , @('cmd' ,'Cmd')
$BreadCrumbOCD += , @('wmic' ,'Wmic')
$BreadCrumbOCD += , @('rundll' ,'RunDll')
$BreadCrumbOCD += , @('var+' ,'Var+')
$BreadCrumbOCD += , @('stdin+' ,'StdIn+')
$BreadCrumbOCD += , @('clip+' ,'Clip+')
$BreadCrumbOCD += , @('var++' ,'Var++')
$BreadCrumbOCD += , @('stdin++' ,'StdIn++')
$BreadCrumbOCD += , @('clip++' ,'Clip++')
$BreadCrumbOCD += , @('rundll++','RunDll++')
$BreadCrumbOCD += , @('mshta++' ,'Mshta++')
$BreadCrumbOCD += , @('ast', 'AST')
$BreadCrumbArray = @()
ForEach($Crumb in $BreadCrumb.Split('_'))
{
# Perform casing substitutions for any matches in $BreadCrumbOCD array.
$StillLookingForSubstitution = $TRUE
ForEach($Substitution in $BreadCrumbOCD)
{
If($Crumb.ToLower() -eq $Substitution[0])
{
$BreadCrumbArray += $Substitution[1]
$StillLookingForSubstitution = $FALSE
}
}
# If no substitution occurred above then simply upper-case the first character and lower-case all the remaining characters.
If($StillLookingForSubstitution)
{
$BreadCrumbArray += $Crumb.SubString(0,1).ToUpper() + $Crumb.SubString(1).ToLower()
# If no substitution was found for the 3rd or later BreadCrumb element (only for Launcher BreadCrumb) then throw a warning so we can add this substitution pair to $BreadCrumbOCD.
If(($BreadCrumb.Split('_').Count -eq 2) -AND ($BreadCrumb.StartsWith('Launcher_')) -AND ($Crumb -ne 'Launcher'))
{
Write-Warning "No substituion pair was found for `$Crumb=$Crumb in `$BreadCrumb=$BreadCrumb. Add this `$Crumb substitution pair to `$BreadCrumbOCD array in Invoke-Obfuscation."
}
}
}
$BreadCrumb = $BreadCrumbArray -Join '\'
}
$BreadCrumb = '\' + $BreadCrumb
}
# Output menu heading.
$FirstLine = "Choose one of the below "
If($BreadCrumb -ne '')
{
$FirstLine = $FirstLine + $BreadCrumb.Trim('\') + ' '
}
Write-Host "$FirstLine" -NoNewLine
# Change color and verbiage if selection will execute command.
If($SelectionContainsCommand)
{
Write-Host "options" -NoNewLine -ForegroundColor Green
Write-Host " to" -NoNewLine
Write-Host " APPLY" -NoNewLine -ForegroundColor Green
Write-Host " to current payload" -NoNewLine
}
Else
{
Write-Host "options" -NoNewLine -ForegroundColor Yellow
}
Write-Host ":`n"
ForEach($Line in $Menu)
{
$LineSpace = $Line[0]
$LineOption = $Line[1]
$LineValue = $Line[2]
Write-Host $LineSpace -NoNewLine
# If not empty then include breadcrumb in $LineOption output (is not colored and won't affect user input syntax).
If(($BreadCrumb -ne '') -AND ($LineSpace.StartsWith('[')))
{
Write-Host ($BreadCrumb.ToUpper().Trim('\') + '\') -NoNewLine
}
# Change color if selection will execute command.
If($SelectionContainsCommand)
{
Write-Host $LineOption -NoNewLine -ForegroundColor Green
}
Else
{
Write-Host $LineOption -NoNewLine -ForegroundColor Yellow
}
# Add additional coloring to string encapsulated by <> if it exists in $LineValue.
If($LineValue.Contains('<') -AND $LineValue.Contains('>'))
{
$FirstPart = $LineValue.SubString(0,$LineValue.IndexOf('<'))
$MiddlePart = $LineValue.SubString($FirstPart.Length+1)
$MiddlePart = $MiddlePart.SubString(0,$MiddlePart.IndexOf('>'))
$LastPart = $LineValue.SubString($FirstPart.Length+$MiddlePart.Length+2)
Write-Host "`t$FirstPart" -NoNewLine
Write-Host $MiddlePart -NoNewLine -ForegroundColor Cyan
# Handle if more than one term needs to be output in different color.
If($LastPart.Contains('<') -AND $LastPart.Contains('>'))
{
$LineValue = $LastPart
$FirstPart = $LineValue.SubString(0,$LineValue.IndexOf('<'))
$MiddlePart = $LineValue.SubString($FirstPart.Length+1)
$MiddlePart = $MiddlePart.SubString(0,$MiddlePart.IndexOf('>'))
$LastPart = $LineValue.SubString($FirstPart.Length+$MiddlePart.Length+2)
Write-Host "$FirstPart" -NoNewLine
If($MiddlePart.EndsWith("(PS3.0+)"))
{
Write-Host $MiddlePart -NoNewline -ForegroundColor Red
}
Else
{
Write-Host $MiddlePart -NoNewLine -ForegroundColor Cyan
}
}
Write-Host $LastPart
}
Else
{
Write-Host "`t$LineValue"
}
}
# Prompt for user input with custom breadcrumb prompt.
Write-Host ''
If($UserInput -ne '') {Write-Host ''}
$UserInput = ''
While(($UserInput -eq '') -AND ($Script:CompoundCommand.Count -eq 0))
{
# Output custom prompt.
Write-Host "Invoke-Obfuscation$BreadCrumb> " -NoNewLine -ForegroundColor Magenta
# Get interactive user input if CliCommands input variable was not specified by user.
If(($Script:CliCommands.Count -gt 0) -OR ($Script:CliCommands -ne $NULL))
{
If($Script:CliCommands.GetType().Name -eq 'String')
{
$NextCliCommand = $Script:CliCommands.Trim()
$Script:CliCommands = @()
}
Else
{
$NextCliCommand = ([String]$Script:CliCommands[0]).Trim()
$Script:CliCommands = For($i=1; $i -lt $Script:CliCommands.Count; $i++) {$Script:CliCommands[$i]}
}
$UserInput = $NextCliCommand
}
Else
{
# If Command was defined on command line and NoExit switch was not defined then output final ObfuscatedCommand to stdout and then quit. Otherwise continue with interactive Invoke-Obfuscation.
If($CliWasSpecified -AND ($Script:CliCommands.Count -lt 1) -AND ($Script:CompoundCommand.Count -lt 1) -AND ($Script:QuietWasSpecified -OR !$NoExitWasSpecified))
{
If($Script:QuietWasSpecified)
{
# Remove Write-Host and Start-Sleep proxy functions so that Write-Host and Start-Sleep cmdlets will be called during the remainder of the interactive Invoke-Obfuscation session.
Remove-Item -Path Function:Write-Host
Remove-Item -Path Function:Start-Sleep
$Script:QuietWasSpecified = $FALSE
# Automatically run 'Show Options' so the user has context of what has successfully been executed.
$UserInput = 'show options'
$BreadCrumb = 'Show Options'
}
# -NoExit wasn't specified and -Command was, so we will output the result back in the main While loop.
If(!$NoExitWasSpecified)
{
$UserInput = 'quit'
}
}
Else
{
$UserInput = (Read-Host).Trim()
}
# Process interactive UserInput using CLI syntax, so comma-delimited and slash-delimited commands can be processed interactively.
If(($Script:CliCommands.Count -eq 0) -AND !$UserInput.ToLower().StartsWith('set ') -AND $UserInput.Contains(','))
{
$Script:CliCommands = $UserInput.Split(',')
# Reset $UserInput so current While loop will be traversed once more and process UserInput command as a CliCommand.
$UserInput = ''
}
}
}
# Trim any leading trailing slashes so it doesn't misinterpret it as a compound command unnecessarily.
$UserInput = $UserInput.Trim('/\')
# Cause UserInput of base menu level directories to automatically work.
# The only exception is STRING if the current MenuName is _token since it can be the base menu STRING or TOKEN/STRING.
If((($MenuLevel | ForEach-Object {$_[1].Trim()}) -Contains $UserInput.Split('/\')[0]) -AND !(('string' -Contains $UserInput.Split('/\')[0]) -AND ($MenuName -eq '_token')) -AND ($MenuName -ne ''))
{
$UserInput = 'home/' + $UserInput.Trim()
}
# If current command contains \ or / and does not start with SET or OUT then we are dealing with a compound command.
# Setting $Script:CompounCommand in below IF block.
If(($Script:CompoundCommand.Count -eq 0) -AND !$UserInput.ToLower().StartsWith('set ') -AND !$UserInput.ToLower().StartsWith('out ') -AND ($UserInput.Contains('\') -OR $UserInput.Contains('/')))
{
$Script:CompoundCommand = $UserInput.Split('/\')
}
# If current command contains \ or / and does not start with SET then we are dealing with a compound command.
# Parsing out next command from $Script:CompounCommand in below IF block.
If($Script:CompoundCommand.Count -gt 0)
{
$UserInput = ''
While(($UserInput -eq '') -AND ($Script:CompoundCommand.Count -gt 0))
{
# If last compound command then it will be a string.
If($Script:CompoundCommand.GetType().Name -eq 'String')
{
$NextCompoundCommand = $Script:CompoundCommand.Trim()
$Script:CompoundCommand = @()
}
Else
{
# If there are more commands left in compound command then it won't be a string (above IF block).
# In this else block we get the next command from CompoundCommand array.
$NextCompoundCommand = ([String]$Script:CompoundCommand[0]).Trim()
# Set remaining commands back into CompoundCommand.
$Temp = $Script:CompoundCommand
$Script:CompoundCommand = @()
For($i=1; $i -lt $Temp.Count; $i++)
{
$Script:CompoundCommand += $Temp[$i]
}
}
$UserInput = $NextCompoundCommand
}
}
# Handle new RegEx functionality.
# Identify if there is any regex in current UserInput by removing all alphanumeric characters (and + or # which are found in launcher names).
$TempUserInput = $UserInput.ToLower()
@(97..122) | ForEach-Object {$TempUserInput = $TempUserInput.Replace([String]([Char]$_),'')}
@(0..9) | ForEach-Object {$TempUserInput = $TempUserInput.Replace($_,'')}
$TempUserInput = $TempUserInput.Replace(' ','').Replace('+','').Replace('#','').Replace('\','').Replace('/','').Replace('-','').Replace('?','')
If(($TempUserInput.Length -gt 0) -AND !($UserInput.Trim().ToLower().StartsWith('set ')) -AND !($UserInput.Trim().ToLower().StartsWith('out ')))
{
# Replace any simple wildcard with .* syntax.
$UserInput = $UserInput.Replace('.*','_____').Replace('*','.*').Replace('_____','.*')
# Prepend UserInput with ^ and append with $ if not already there.
If(!$UserInput.Trim().StartsWith('^') -AND !$UserInput.Trim().StartsWith('.*'))
{
$UserInput = '^' + $UserInput
}
If(!$UserInput.Trim().EndsWith('$') -AND !$UserInput.Trim().EndsWith('.*'))
{
$UserInput = $UserInput + '$'
}
# See if there are any filtered matches in the current menu.
Try
{
$MenuFiltered = ($Menu | Where-Object {($_[1].Trim() -Match $UserInput) -AND ($_[1].Trim().Length -gt 0)} | ForEach-Object {$_[1].Trim()})
}
Catch
{
# Output error message if Regular Expression causes error in above filtering step.
# E.g. Using *+ instead of *[+]
Write-Host "`n`nERROR:" -NoNewLine -ForegroundColor Red
Write-Host ' The current Regular Expression caused the following error:'
write-host " $_" -ForegroundColor Red
}
# If there are filtered matches in the current menu then randomly choose one for the UserInput value.
If($MenuFiltered -ne $NULL)
{
# Randomly select UserInput from filtered options.
$UserInput = (Get-Random -Input $MenuFiltered).Trim()
# Output randomly chosen option (and filtered options selected from) if more than one option were returned from regex.
If($MenuFiltered.Count -gt 1)
{
# Change color and verbiage if acceptable options will execute an obfuscation function.
If($SelectionContainsCommand)
{
$ColorToOutput = 'Green'
}
Else
{
$ColorToOutput = 'Yellow'
}
Write-Host "`n`nRandomly selected " -NoNewline
Write-Host $UserInput -NoNewline -ForegroundColor $ColorToOutput
write-host " from the following filtered options: " -NoNewline
For($i=0; $i -lt $MenuFiltered.Count-1; $i++)
{
Write-Host $MenuFiltered[$i].Trim() -NoNewLine -ForegroundColor $ColorToOutput
Write-Host ', ' -NoNewLine
}
Write-Host $MenuFiltered[$MenuFiltered.Count-1].Trim() -NoNewLine -ForegroundColor $ColorToOutput
}
}
}
# If $UserInput is all numbers and is in a menu in $MenusWithMultiSelectNumbers
$OverrideAcceptableInput = $FALSE
$MenusWithMultiSelectNumbers = @('\Launcher')
If(($UserInput.Trim(' 0123456789').Length -eq 0) -AND $BreadCrumb.Contains('\') -AND ($MenusWithMultiSelectNumbers -Contains $BreadCrumb.SubString(0,$BreadCrumb.LastIndexOf('\'))))
{
$OverrideAcceptableInput = $TRUE
}
If($ExitInputOptions -Contains $UserInput.ToLower())
{
Return $ExitInputOptions[0]
}
ElseIf($MenuInputOptions -Contains $UserInput.ToLower())
{
# Commands like 'back' that will return user to previous interactive menu.
If($BreadCrumb.Contains('\')) {$UserInput = $BreadCrumb.SubString(0,$BreadCrumb.LastIndexOf('\')).Replace('\','_')}
Else {$UserInput = ''}
Return $UserInput.ToLower()
}
ElseIf($HomeMenuInputOptions[0] -Contains $UserInput.ToLower())
{
Return $UserInput.ToLower()
}
ElseIf($UserInput.ToLower().StartsWith('set '))
{
# Extract $UserInputOptionName and $UserInputOptionValue from $UserInput SET command.
$UserInputOptionName = $NULL
$UserInputOptionValue = $NULL
$HasError = $FALSE
$UserInputMinusSet = $UserInput.SubString(4).Trim()
If($UserInputMinusSet.IndexOf(' ') -eq -1)
{
$HasError = $TRUE
$UserInputOptionName = $UserInputMinusSet.Trim()
}
Else
{
$UserInputOptionName = $UserInputMinusSet.SubString(0,$UserInputMinusSet.IndexOf(' ')).Trim().ToLower()
$UserInputOptionValue = $UserInputMinusSet.SubString($UserInputMinusSet.IndexOf(' ')).Trim()
}
# Validate that $UserInputOptionName is defined in $SettableInputOptions.
If($SettableInputOptions -Contains $UserInputOptionName)
{
# Perform separate validation for $UserInputOptionValue before setting value. Set to 'emptyvalue' if no value was entered.
If($UserInputOptionValue.Length -eq 0) {$UserInputOptionName = 'emptyvalue'}
Switch($UserInputOptionName.ToLower())
{
'scriptpath' {
If($UserInputOptionValue -AND ((Test-Path $UserInputOptionValue) -OR ($UserInputOptionValue -Match '(http|https)://')))
{
# Reset ScriptBlock in case it contained a value.
$Script:ScriptBlock = ''