-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathDeploy-Deception.ps1
1190 lines (918 loc) · 41.4 KB
/
Deploy-Deception.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
#Requires –Modules ActiveDirectory
<#
File: Deploy-Deception.ps1
Author: Nikhil Mittal (@nikhil_mitt)
Description: A PowerShell module to deploy active directory decoy objects.
Required Dependencies: ActiveDirectory Module by Microsoft
#>
##################################### Helper Functions #####################################
function Create-DecoyUser
{
<#
.SYNOPSIS
Create a user object.
.DESCRIPTION
Creates a user object on the domain. Must be run on a DC with domain admin privileges.
.PARAMETER UserFirstName
First name of the user to be crated.
.PARAMETER UserLastName
Last name of the user to be crated.
.PARAMETER Password
Password for the user to be created.
.PARAMETER OUDistinguishedName
DistinguishedName of OU where the user will be created. The default User OU is used if this paramter is not specified.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName user -UserLastName manager -Password Pass@123
Use the above command to create a user 'usermanager'.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(Position = 0, Mandatory = $False)]
[String]
$UserFirstName,
[Parameter(Position = 1, Mandatory = $False)]
[String]
$UserLastName,
[Parameter(Position = 2, Mandatory = $False)]
[String]
$Password,
[Parameter(Position = 3, Mandatory = $False)]
[String]
$OUDistinguishedName
)
$UserDisplayName = $UserFirstName + $UserLastName
Write-Verbose "Creating user $UserDisplayName."
if (!$OUDistinguishedName)
{
Write-Verbose "Creating user $UserDisplayName."
(New-ADUser -Name $UserDisplayName -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -SamAccountName $UserDisplayName -Enabled $True -DisplayName $UserDisplayName -PassThru).SamAccountName
}
else
{
Write-Verbose "Creating user $UserDisplayName in $OUDistinguishedName."
(New-ADUser -Name $UserDisplayName -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -SamAccountName $UserDisplayName -Enabled $True -DisplayName $UserDisplayName -Path $OUDistinguishedName -PassThru).SamAccountName
}
}
function Create-DecoyComputer
{
<#
.SYNOPSIS
Create a computer object.
.DESCRIPTION
Creates a computer object on the domain. Must be run on a DC with domain admin privileges.
.PARAMETER ComputerName
Name of the computer to be crated.
.PARAMETER OUDistinguishedName
DistinguishedName of OU where the computer will be created. The default Computer OU is used if this paramter is not specified.
.EXAMPLE
PS C:\> Create-DecoyComputer -ComputerName revert-web -Verbose
Use the above command to create a computer 'revert-web'.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(Position = 0, Mandatory = $False)]
[String]
$ComputerName,
[Parameter(Position = 1, Mandatory = $False)]
[String]
$OUDistinguishedName
)
$DNSHostname = $ComputerName + "." + (Get-ADDomain).DNSRoot
Write-Verbose "Creating computer $ComputerName."
if (!$OUDistinguishedName)
{
Write-Verbose "Creating computer $DNSHostname."
(New-ADComputer -Name $ComputerName -Enabled $True -DNSHostName $DNSHostname -PassThru).SamAccountName
}
else
{
Write-Verbose "Creating computer $DNSHostname in $OUDistinguishedName."
(New-ADComputer -Name $ComputerName -Enabled $True -DNSHostName $DNSHostname -Path $OUDistinguishedName -PassThru).SamAccountName
}
}
function Create-DecoyGroup
{
<#
.SYNOPSIS
Create a Group object.
.DESCRIPTION
Creates a Group object on the domain. Must be run on a DC with domain admin privileges.
.PARAMETER GroupName
Name of the Group to be crated.
.PARAMETER GroupScope
The scope of created group. Default is Global.
.EXAMPLE
PS C:\> Create-DecoyGroup -GroupName 'Forest Admins' -Verbose
Use the above command to create a Global Group 'Forest Admins'.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(Position = 0, Mandatory = $False)]
[String]
$GroupName,
[Parameter(Position = 1, Mandatory = $False)]
[String]
[ValidateSet ("DomainLocal","Global","Universal")]
$GroupScope = "Global"
)
Write-Verbose "Creating Group $GroupName."
(New-ADGroup -Name $GroupName -GroupScope $GroupScope -PassThru).SamAccountName
}
function Get-ADObjectDetails
{
<#
.SYNOPSIS
Helper function to retrieve details about an object from domain.
.DESCRIPTION
Helper function to retrieve details - SamAccountName, Distibguished Name and ACL for an object from domain.
.PARAMETER UserName
Username to get details for.
.PARAMETER SamAccountName
SamAccountName of a user to get details for.
.PARAMETER DistinguisedName
DistinguishedName of a user to get details for.
.PARAMETER ComputerName
ComputerName to get details for.
.PARAMETER GroupName
GroupName to get details for.
.PARAMETER OUName
OUName to get details for.
.EXAMPLE
PS C:\> Get-ADObjectDetails -SamAccountName usermanager.
Use the above command to get details for the user 'usermanager'.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(Position = 0, Mandatory = $False)]
[String]
$UserName,
[Parameter(Position = 1, Mandatory = $False)]
[String]
$SAMAccountName,
[Parameter(Position = 2, Mandatory = $False)]
[String]
$DistinguishedName,
[Parameter(Position = 3, Mandatory = $False)]
[String]
$ComputerName,
[Parameter(Position = 4, Mandatory = $False)]
[String]
$GroupName,
[Parameter(Position = 5, Mandatory = $False)]
[String]
$OUName
)
if ($UserName)
{
$objDN = (Get-ADUser -Filter {Name -eq $UserName}).distinguishedname
$TargetSamAccountName = (Get-ADUser -Filter {Name -eq $UserName}).SamAccountName
}
elseif ($SAMAccountName)
{
$objDN = (Get-ADUser -Identity $SamAccountName).distinguishedname
$TargetSamAccountName = $SAMAccountName
}
elseif ($DistinguishedName)
{
$objDN = $DistinguishedName
$TargetSamAccountName = (Get-ADUser -Filter {Name -eq $UserName}).SamAccountName
}
elseif ($ComputerName)
{
$objDN = (Get-ADComputer -Identity $ComputerName).distinguishedname
$TargetSamAccountName = (Get-ADComputer -Identity $ComputerName).SamAccountName
}
elseif ($GroupName)
{
$objDN = (Get-ADGroup -Identity $GroupName).distinguishedname
$TargetSamAccountName = (Get-ADGroup -Identity $GroupName).SamAccountName
}
elseif ($OUName)
{
$objDN = (Get-ADOrganizationalUnit -Filter {Name -eq $OUName}).distinguishedname
$TargetSamAccountName = (Get-ADOrganizationalUnit -Filter {Name -eq $OUName}).SamAccountName
}
else
{
Write-Output 'Cannot find the object.'
}
#Write-Verbose "Getting the existing ACL for $objDN."
$ACL = Get-Acl -Path "AD:\$objDN"
# A PSObject for returning properties
$ObjectProperties = @{
SamAccountName = $TargetSamAccountName
DistinguishedName = $objDN
ACL = $ACL
}
New-Object psobject -Property $ObjectProperties
}
function Set-AuditRUle
{
<#
.SYNOPSIS
Helper function to set auditing for an object in domain.
.DESCRIPTION
Helper function to set auditing for an object in domain.
.PARAMETER UserName
Username to set SACL for.
.PARAMETER SamAccountName
SamAccountName of a user to set SACL for.
.PARAMETER DistinguisedName
DistinguishedName of a user to set SACL for.
.PARAMETER ComputerName
ComputerName to set SACL for.
.PARAMETER GroupName
GroupName to set SACL for.
.PARAMETER OUName
OUName to set SACL for.
.PARAMETER Principal
The Principal (user or group) for which auditing is turned on when they use Rights defined by the Right or GUID paramter.
.PARAMETER Right
Thr Right for which auditing is turned on when used by the principal specified with the Principal parameter.
Default is ReadProperty right.
.PARAMETER GUID
GUID for the property for which auditing is turned on when Princpal uses Right on the property.
.PARAMETER AuditFlag
Turn on Auditing for Success or Failure. Default is Success.
.PARAMETER RemoveAuditing
Remove previously added Auditing ACE.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(Position = 0, Mandatory = $False)]
[String]
$UserName,
[Parameter(Position = 1, Mandatory = $False)]
[String]
$SAMAccountName,
[Parameter(Position = 2, Mandatory = $False)]
[String]
$DistinguishedName,
[Parameter(Position = 3, Mandatory = $False)]
[String]
$ComputerName,
[Parameter(Position = 4, Mandatory = $False)]
[String]
$GroupName,
[Parameter(Position = 5, Mandatory = $False)]
[String]
$OUName,
[Parameter(Position = 6, Mandatory = $False)]
[String]
$Principal,
[Parameter(Position = 7, Mandatory = $False)]
[String]
[ValidateSet ("GenericAll","GenericRead","GenericWrite","ReadControl","ReadProperty","WriteDacl","WriteOwner","WriteProperty")]
$Right = "ReadProperty",
[Parameter(Position = 8, Mandatory = $False)]
[String]
$GUID,
[Parameter(Position = 9, Mandatory = $False)]
[String]
[ValidateSet ("Success","Failure")]
$AuditFlag = "Success",
[Parameter(Mandatory = $False)]
[Bool]
$RemoveAuditing
)
$objectdetails = Get-ADObjectDetails -SAMAccountName $SamAccountName -ComputerName $ComputerName -GroupName $GroupName -OUName $OUName
$ACL = $objectdetails.ACL
$sid = New-Object System.Security.Principal.NTAccount($Principal)
if (!$GUID)
{
$AuditRule = New-Object DirectoryServices.ActiveDirectoryAuditRule($sid,$Right,$AuditFlag)
}
# Set Auditing for a specific property in the object with the property or attribute GUID
# Interesting GUID
# userAccountControl - bf967a68-0de6-11d0-a285-00aa003049e2
# x500uniqueIdentifier - d07da11f-8a3d-42b6-b0aa-76c962be719a
elseif ($GUID)
{
$objectGuid = New-Object Guid $GUID
$AuditRule = New-Object DirectoryServices.ActiveDirectoryAuditRule($sid,$Right,$AuditFlag,$objectGuid)
}
else
{
Write-Warning "Please specify a right. If you are targeting a specific object type, please provide a GUID."
}
$objDN = $objectdetails.DistinguishedName
if(!$RemoveAuditing)
{
Write-Verbose "Turning ""$AuditFlag"" Auditing on for ""$objDN"" when ""$Principal"" uses ""$Right"" right."
$ACL.AddAuditRule($AuditRule)
}
else
{
Write-Verbose "Removing ""$AuditFlag"" Auditing for ""$objDN"" when ""$Principal"" uses ""$Right"" right."
$ACL.RemoveAuditRule($AuditRule)
}
Set-Acl "AD:\$objDN" -AclObject $ACL
}
################################## End of Helper Functions #################################
function Deploy-UserDeception
{
<#
.SYNOPSIS
Deploys the specific decoy user to log Security Event 4662 when a specific Right is used against it.
.DESCRIPTION
This function sets up auditing when a specified Right is used by a specifed principal against the decoy user object.
The function must be run on a DC with domain admin privileges. There are multiple user attributes and flags
which can be set while deploying the decoy. These attributes and flags make the decoy interesting for an attacker.
When a right, say, ReadProperty is used to access the decoy user, a Security Event 4662 is logged.
Note that Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> DS Access - Audit Directory Service Access
Group Policy needs to be configured to enable 4662 logging.
.PARAMETER DecoySamAccountName
SamAccountName of the decoy user.
.PARAMETER DecoyDistinguishedName
DistinguishedName of the decoy user.
.PARAMETER UserFlag
A decoy user property which would be 'interesting' for an attacker.
.PARAMETER PasswordInDescription
Leave a password in Description of the decoy user.
.PARAMETER SPN
Set 'interesting' SPN for the decoy user in the format servicename/host
.PARAMETER Principal
The Principal (user or group) for which auditing is turned on when they use Rights defined by the Right or GUID paramter.
.PARAMETER Right
Thr Right for which auditing is turned on when used by the principal specified with the Principal parameter.
Default is ReadProperty right.
.PARAMETER GUID
GUID for the property for which auditing is turned on when Princpal uses Right on the property.
.PARAMETER AuditFlag
Turn on Auditing for Success or Failure. Default is Success.
.PARAMETER RemoveAuditing
Remove previously added Auditing ACE.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName user -UserLastName manager -Password Pass@123 | Deploy-UserDeception -UserFlag PasswordNeverExpires -Verbose
Creates a decoy user whose password never expires and a 4662 is logged whenever ANY property of the user is read. Very verbose!
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName user -UserLastName manager -Password Pass@123 | Deploy-UserDeception -UserFlag PasswordNeverExpires -GUID d07da11f-8a3d-42b6-b0aa-76c962be719a -Verbose
Creates a decoy user whose password never expires and a 4662 is logged whenever x500uniqueIdentifier - d07da11f-8a3d-42b6-b0aa-76c962be719a property of the user is read.
This property is not read by net.exe, WMI classes (like Win32_UserAccount) and ActiveDirectory module.
But LDAP based tools like PowerView and ADExplorer trigger the logging.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName user -UserLastName manager-control -Password Pass@123 | Deploy-UserDeception -UserFlag AllowReversiblePasswordEncryption -Right ReadControl -Verbose
Creates a decoy user which has Allow Reverisble Password Encrpytion property set.
A 4662 is logged whenever DACL of the user is read.
This property is not read by enumeration tools unless specifically DACL or all properties for the decoy user are force read.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(ParameterSetName="SamAccountName",Position = 0, Mandatory = $False,ValueFromPipeline = $True)]
[String]
$DecoySamAccountName,
[Parameter(ParameterSetName="ADSPath",Position = 1, Mandatory = $False)]
[String]
$DecoyDistinguishedName,
[Parameter(Position = 3, Mandatory = $False)]
[String]
[ValidateSet ("DoesNotRequirePreAuth","AllowReversiblePasswordEncryption","PasswordNeverExpires","TrustedForDelegation","TrustedToAuthForDelegation")]
$UserFlag,
[Parameter(Position = 4, Mandatory = $False)]
[String]
$PasswordInDescription,
[Parameter(Position = 5, Mandatory = $False)]
[String]
$SPN,
[Parameter(Position = 6, Mandatory = $False)]
[String]
$Principal = "Everyone",
[Parameter(Position = 7, Mandatory = $False)]
[String]
[ValidateSet ("GenericAll","GenericRead","GenericWrite","ReadControl","ReadProperty","WriteDacl","WriteOwner","WriteProperty")]
$Right = "ReadProperty",
[Parameter(Position = 8, Mandatory = $False)]
[String]
$GUID,
[Parameter(Position = 9, Mandatory = $False)]
[String]
[ValidateSet ("Success","Failure")]
$AuditFlag = "Success",
[Parameter(Mandatory = $False)]
[Bool]
$RemoveAuditing = $False
)
if($DecoySamAccountName)
{
$DecoySamAccountName = (Get-ADObjectDetails -SAMAccountName $DecoySamAccountName).SamAccountName
}
elseif ($DecoyDistinguishedName)
{
$DecoySamAccountName = (Get-ADObjectDetails -DistinguishedName $DecoyDistinguishedName).SamAccountName
}
else
{
Write-Output "No such decoy user found."
}
if ($UserFlag)
{
# Set the Deocy user account userflags.
Write-Verbose "Adding $UserFlag to decoy user $DecoySamAccountName."
switch($UserFlag)
{
"DoesNotRequirePreAuth"
{
Set-ADAccountControl -Identity $DecoySamAccountName -DoesNotRequirePreAuth $true
}
"AllowReversiblePasswordEncryption"
{
Set-ADAccountControl -Identity $DecoySamAccountName -AllowReversiblePasswordEncryption $true
}
"PasswordNeverExpires"
{
Set-ADAccountControl -Identity $DecoySamAccountName -PasswordNeverExpires $true
}
"TrustedForDelegation"
{
Set-ADAccountControl -Identity $DecoySamAccountName -TrustedForDelegation $true
}
"TrustedToAuthForDelegation"
{
Set-ADAccountControl -Identity $DecoySamAccountName -TrustedToAuthForDelegation $true
}
}
}
if ($PasswordInDescription)
{
# Be creative! For example, "User Password is July@2018 - Last used by Gary"
Write-Verbose "Adding $PasswordInDescription for decoy user $DecoySamAccountName."
Set-ADUser -Identity $DecoySamAccountName -Description $PasswordInDescription
}
if ($SPN)
{
Write-Verbose "Adding $SPN to decoy user $DecoySamAccountName."
Set-ADUser -Identity $DecoySamAccountName -ServicePrincipalNames @{Add=$SPN}
}
Set-AuditRUle -SAMAccountName $DecoySamAccountName -Principal $Principal -Right $Right -GUID $GUID -AuditFlag $AuditFlag -Remove $RemoveAuditing
}
function Deploy-SlaveDeception
{
<#
.SYNOPSIS
Deploys the specific slave user and FUllControl over it for a master user to log Security Event 4662 when a specific Right is used.
.DESCRIPTION
This function sets up auditing when a specified Right is used over the slave user by a master user who has FUllControl/GenericALl over the slave user.
Note that Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> DS Access - Audit Directory Service Access
Group Policy needs to be configured to enable 4662 logging.
.PARAMETER SlaveSamAccountName
SamAccountName of the slave user.
.PARAMETER SlaveDistinguishedName
DistinguishedName of the slave user.
.PARAMETER DecoySamAccountName
SamAccountName of the decoy user.
.PARAMETER DecoyDistinguishedName
DistinguishedName of the decoy user.
.PARAMETER RemoveAuditing
Remove previously added Auditing ACE.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName master -UserLastName user -Password Pass@123
PS C:\> Create-DecoyUser -UserFirstName slave -UserLastName user -Password Pass@123 | Deploy-SlaveDeception -DecoySamAccountName masteruser -Verbose
The first command creates a deocy user 'masteruser'.
The second command creates a decoy user 'slaveuser' and provides masteruser GenericAll rights over slaveuser.
For both the users a 4662 is logged whenever there is any interaction with them.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName master -UserLastName user -Password Pass@123 | Deploy-UserDeception -UserFlag PasswordNeverExpires -GUID d07da11f-8a3d-42b6-b0aa-76c962be719a -Verbose
PS C:\> Create-DecoyUser -UserFirstName slave -UserLastName user -Password Pass@123 | Deploy-SlaveDeception -DecoySamAccountName masteruser -Verbose
PS C:\> Deploy-SlaveDeception -SlaveSamAccountName slaveuser -DecoySamAccountName masteruser -Verbose
The first command creates a decoy user 'masteruser' whose password never expires and a 4662 is logged whenever x500uniqueIdentifier - d07da11f-8a3d-42b6-b0aa-76c962be719a property of the user is read.
The second command creates a decoy user 'slaveuser' whose password never expires and a 4662 is logged whenever x500uniqueIdentifier - d07da11f-8a3d-42b6-b0aa-76c962be719a property of the user is read.
The third command grants masteruser GenericAll rights over slaveuser.
The above three commands make masteruser and slaveuser attractive for an attacker and the logging is triggered only for aggressive enumeration.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName master -UserLastName user -Password Pass@123
PS C:\> Create-DecoyUser -UserFirstName slave -UserLastName user -Password Pass@123
PS C:\> Deploy-SlaveDeception -SlaveSamAccountName slaveuser -DecoySamAccountName masteruser -Verbose
PS C:\> Deploy-UserDeception -DecoySamAccountName slaveuser -Principal masteruser -Right WriteDacl -Verbose
The first three commands create a slaveuser, create a master user and provide masteruser GenericAll rights on slaveuser.
The foruth command triggers a 4662 log only when masteruser is used change DACL (WirteDacl) of the slaveuser.
This is useful when targeting lateral movement and it is assumed that an adversary will get access to masteruser.
For example, masteruser could be a honeyuser whose credentials are left on multipe machines or masteruser can have its
usable password in Description.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(ParameterSetName="SamAccountName",Position = 0, Mandatory = $False,ValueFromPipeline = $True)]
[String]
$SlaveSamAccountName,
[Parameter(ParameterSetName="ADSPath",Position = 1, Mandatory = $False)]
[String]
$SlaveDistinguishedName,
[Parameter(Position = 2, Mandatory = $False)]
[String]
$DecoySamAccountName,
[Parameter(Position = 3, Mandatory = $False)]
[String]
$DecoyDistinguishedName,
[Parameter(Mandatory = $False)]
[Bool]
$RemoveAuditing = $False
)
if($DecoySamAccountName)
{
$DecoySamAccountName = (Get-ADObjectDetails -SAMAccountName $DecoySamAccountName).SamAccountName
}
elseif ($DecoyDistinguishedName)
{
$DecoySamAccountName = (Get-ADObjectDetails -DistinguishedName $DecoyDistinguishedName).SamAccountName
}
else
{
Write-Output "No such decoy user found."
}
if($SlaveSamAccountName)
{
$SlaveSamAccountName = (Get-ADObjectDetails -SAMAccountName $SlaveSamAccountName).SamAccountName
}
elseif ($SlaveDistinguishedName)
{
$SlaveSamAccountName = (Get-ADObjectDetails -DistinguishedName $SlaveDistinguishedName).SamAccountName
}
else
{
Write-Output "No such slave user found."
}
# Get ACL of the slave user
$slaveuserdetails = Get-ADObjectDetails -SAMAccountName $SlaveSamAccountName
$ACL = $slaveuserdetails.ACL
# Set GenericALL (FullControl) rights on Slaveuser for Decoyuser
$sid = New-Object System.Security.Principal.NTAccount($DecoySamAccountName)
$ACE = New-Object DirectoryServices.ActiveDirectoryAccessRule($sid,'GenericAll','Allow')
$objDN = $slaveuserdetails.DistinguishedName
$ACL.AddAccessRule($ACE)
Set-Acl "AD:\$objDN" -AclObject $ACL
# Add auditing for DecoyUser and Slave on ReadProperty for x500uniqueIdentifier user property.
Set-AuditRUle -SAMAccountName $DecoySamAccountName -Principal Everyone -Right ReadProperty -GUID d07da11f-8a3d-42b6-b0aa-76c962be719a -AuditFlag Success -RemoveAuditing $RemoveAuditing
Set-AuditRUle -SAMAccountName $SlaveSamAccountName -Principal Everyone -Right ReadProperty -GUID d07da11f-8a3d-42b6-b0aa-76c962be719a -AuditFlag Success -RemoveAuditing $RemoveAuditing
}
function Deploy-PrivilegedUserDeception
{
<#
.SYNOPSIS
Deploys the specific decoy user and provide it high privileges (with protections) to make it interesting for an adversary.
.DESCRIPTION
This function deploys a decoy user which has high privileges like membership of the Domain Admins group.
There are protections like DenyLogon to avoid abuse of these privileges.
Note that Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> DS Access - Audit Directory Service Access
Group Policy needs to be configured to enable 4662 logging.
and
Audit Kerberos Authentication Service for Failure needs to be enabled for 4768.
.PARAMETER DecoySamAccountName
SamAccountName of the decoy user.
.PARAMETER DecoyDistinguishedName
DistinguishedName of the decoy user.
.PARAMETER Technique
The privilges for the decoy user. Currently, DomainAdminsMembership and DCSyncRights.
.PARAMETER Protection
Protection for avoiding abuse of the privileges. Currently, only DenyLogon is available.
.PARAMETER Principal
The Principal (user or group) for which auditing is turned on when they use Rights defined by the Right or GUID paramter.
.PARAMETER Right
Thr Right for which auditing is turned on when used by the principal specified with the Principal parameter.
Default is ReadControl right.
.PARAMETER GUID
GUID for the property for which auditing is turned on when Princpal uses Right on the property.
.PARAMETER AuditFlag
Turn on Auditing for Success or Failure. Default is Success.
.PARAMETER CreateLogon
Create a logon for the created decoyuser on the DC where the function is run. This helps in avoiding detection of the decoy
which relies on logoncount. A user profile is created on the DC when this parameter is used.
.PARAMETER logonCount
Number of logonCount for the decoy user. Default is 1.
.PARAMETER RemoveAuditing
Remove previously added Auditing ACE.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName dec -UserLastName da -Password Pass@123 | Deploy-PrivilegedUserDeception -Technique DomainAdminsMemebership -Protection DenyLogon -Verbose
Create a decoy user named decda and make it a member of the Domain Admins group. As a protection against potential abuse,
Deny logon to the user on any machine. Please be aware that if another DA gets comprimised the DenyLogon setting can be removed.
If there is any attempt to use the user credentials (password or hashes) a 4768 is logged.
Any enumeration which reads DACL or all properties for the user will result in a 4662 logging.
.EXAMPLE
PS C:\> Deploy-PrivilegedUserDeception -DecoySamaccountName decda -Technique DCSyncRights -Protection DenyLogon -Verbose
Use existing user decda and make provide it DCSyncRights. As a protection against potential abuse,
Deny logon to the user on any machine.
If there is any attempt to use the user credentials (password or hashes) a 4768 is logged.
Any enumeration which reads DACL or all properties for the user will result in a 4662 logging.
.EXAMPLE
PS C:\> Create-DecoyUser -UserFirstName test -UserLastName da -Password Pass@123 | Deploy-PrivilegedUserDeception -Technique DomainAdminsMemebership -Protection DenyLogon -CreateLogon -Verbose
Create a decoy user named decda and make it a member of the Domain Admins group.
As a protection against potential abuse, Deny logon to the user on any machine..
To avoid detection of the decoy which relies on logoncount use the CreateLogon option which starts and stops a process as the
decoy user on the DC. A user profile is created on the DC when this parameter is used.
If there is any attempt to use the user credentials (password or hashes) a 4768 is logged.
Any enumeration which reads DACL or all properties for the user will result in a 4662 logging.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html
https://github.com/samratashok/Deploy-Deception
#>
[CmdletBinding()] Param(
[Parameter(ParameterSetName="SamAccountName",Position = 0, Mandatory = $False,ValueFromPipeline = $True)]
[String]
$DecoySamAccountName,
[Parameter(ParameterSetName="ADSPath",Position = 1, Mandatory = $False)]
[String]
$DecoyDistinguishedName,
[Parameter(Position = 2, Mandatory = $False)]
[String]
[ValidateSet ("DomainAdminsMemebership","DCSyncRights")]
$Technique,
[Parameter(Position = 3, Mandatory = $False)]
[String]
[ValidateSet ("DenyLogon")]
$Protection,
[Parameter(Position = 4, Mandatory = $False)]
[String]
$Principal = "Everyone",
[Parameter(Position = 5, Mandatory = $False)]
[String]
[ValidateSet ("GenericAll","GenericRead","GenericWrite","ReadControl","ReadProperty","WriteDacl","WriteOwner","WriteProperty")]
$Right = "ReadControl",
[Parameter(Position = 6, Mandatory = $False)]
[String]
$GUID,
[Parameter(Position = 7, Mandatory = $False)]
[String]
[ValidateSet ("Success","Failure")]
$AuditFlag = "Success",
[Parameter(Mandatory = $False)]
[Switch]
$CreateLogon,
[Parameter(Mandatory = $False)]
[int]
$logonCount = 1,
[Parameter(Mandatory = $False)]
[Bool]
$RemoveAuditing = $False
)
if($DecoySamAccountName)
{
$DecoySamAccountName = (Get-ADObjectDetails -SAMAccountName $DecoySamAccountName).SamAccountName
}
elseif ($DecoyDistinguishedName)
{
$DecoySamAccountName = (Get-ADObjectDetails -DistinguishedName $DecoyDistinguishedName).SamAccountName
}
else
{
Write-Output "No such decoy user found."
}
if ($Technique)
{
# Set the Deocy user's interesting privileges.
switch($Technique)
{
"DomainAdminsMemebership"
{
# The user will actually be a part of the DA group but cannot logon.
Write-Verbose "Adding $DecoySamAccountName to the Domain Admins Group."
Add-ADGroupMember -Identity "Domain Admins" -Members $DecoySamAccountName
$isDA = $True
}
"DCSyncRights"
{
# Replication Rights
Write-Verbose "Providing DCSync permissions to $DecoySamAccountName."
$DomainDN = (Get-AdDomain).DistinguishedName
$ACL = Get-Acl "AD:\$DomainDN"
$sid = New-Object System.Security.Principal.NTAccount($DecoySamAccountName)
$objectGuidChangesAll = New-Object Guid 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2
$ACE = New-Object DirectoryServices.ActiveDirectoryAccessRule($sid,'ExtendedRight','Allow',$objectGuidChangesAll)
$ACL.AddAccessRule($ACE)
Set-Acl "AD:\$DomainDN" -AclObject $ACL
$ACL = Get-Acl "AD:\$DomainDN"
$objectGuidChanges = New-Object Guid 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2
$ACE = New-Object DirectoryServices.ActiveDirectoryAccessRule($sid,'ExtendedRight','Allow',$objectGuidChanges)
$ACL.AddAccessRule($ACE)
Set-Acl "AD:\$DomainDN" -AclObject $ACL
}
}
}
if ($Protection)
{
switch ($Protection)
{
"DenyLogon"
{
# Deny logon to user from anywhere by setting logon hours
$Hours = New-Object byte[] 21
$Hours[5] = 000; $Hours[8] = 000; $Hours[11] = 000; $Hours[14] = 000; $Hours[17] = 000;
$Hours[6] = 0; $Hours[9] = 0; $Hours[12] = 0; $Hours[15] = 0; $Hours[18] = 0;
$ReplaceHashTable = New-Object HashTable
$ReplaceHashTable.Add("logonHours", $Hours)
Write-Verbose "Adding protection - Decoy user $DecoySamAccountName has been denied logon."
Set-ADUser -Identity $DecoySamAccountName -Replace $ReplaceHashTable
}
}
}
# Add auditing to the decoy user
Set-AuditRule -UserName $DecoyUserName -SAMAccountName $DecoySamAccountName -DistinguishedName $DecoyDistinguishedName -Principal $Principal -Right $Right -GUID $GUID -AuditFlag $AuditFlag -RemoveAuditing $RemoveAuditing
}
function Deploy-ComputerDeception
{
<#
.SYNOPSIS
Deploys the specific decoy computer to log Security Event 4662 when a specific Right is used against it.
.DESCRIPTION
This function sets up auditing when a specified Right is used by a specifed principal against the decoy computer object.
The function must be run on a DC with domain admin privileges. There are multiple computer attributes and flags
that can be set while deploying the decoy. These attributes and flags make the decoy interesting for an attacker.
When a right, say, ReadProperty is used to access the decoy computer, a Security Event 4662 is logged.
Note that Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> DS Access - Audit Directory Service Access
Group Policy needs to be configured to enable 4662 logging.
.PARAMETER DecoyComputerName
SamAccountName of the decoy computer.
.PARAMETER OperatingSystem
OperatingSystem attribute for the decoy computer.
.PARAMETER SPN
Set 'interesting' SPN for the decoy computer in the format servicename/host.
.PARAMETER PropertyFlag
A decoy computer property which would be 'interesting' for an attacker.
.PARAMETER Principal
The Principal (user or group) for which auditing is turned on when they use Rights defined by the Right or GUID paramter.
.PARAMETER Right
Thr Right for which auditing is turned on when used by the principal specified with the Principal parameter.
Default is ReadProperty right.
.PARAMETER GUID
GUID for the property for which auditing is turned on when Princpal uses Right on the property.
.PARAMETER AuditFlag
Turn on Auditing for Success or Failure. Default is Success.
.PARAMETER RemoveAuditing
Remove previously added Auditing ACE.
.EXAMPLE
PS C:\> Create-DecoyComputer -ComputerName revert-web -Verbose | Deploy-ComputerDeception -PropertyFlag TrustedForDelegation -GUID d07da11f-8a3d-42b6-b0aa-76c962be719a -Verbose
Creates a decoy computer that has Unconstrained Delegation enabled and a 4662 is logged whenever x500uniqueIdentifier - d07da11f-8a3d-42b6-b0aa-76c962be719a property or all the properties
of the computer are read.
.EXAMPLE
PS C:\> Deploy-ComputerDeception -DecoyComputerName comp1 -PropertyFlag TrustedForDelegation -GUID d07da11f-8a3d-42b6-b0aa-76c962be719a -Verbose
Uses an existing computer object and set Unconstrained Delegation on it. A 4662 is logged whenever x500uniqueIdentifier - d07da11f-8a3d-42b6-b0aa-76c962be719a property or all the properties
of the computer are read.
Using a real machine for the decoy is always recommended as it is harder to identify as a decoy.
.EXAMPLE
PS C:\> Deploy-ComputerDeception -DecoyComputerName comp1 -OperatingSystem "Windows Server 2003" -Right ReadControl -Verbose
Uses an existing computer object and set its Operating System property to Windows Server 2003.
A 4662 is logged whenever DACL or all the properties of the computer are read.
Using a real machine for the decoy is always recommended as it is harder to identify as a decoy.
.LINK
https://www.labofapenetrationtester.com/2018/10/deploy-deception.html