-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdomain-controller-configure.ps1
More file actions
164 lines (140 loc) · 5.03 KB
/
domain-controller-configure.ps1
File metadata and controls
164 lines (140 loc) · 5.03 KB
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
# wait until we can access the AD. this is needed to prevent errors like:
# Unable to find a default server with Active Directory Web Services running.
while ($true) {
try {
Get-ADDomain | Out-Null
break
} catch {
Start-Sleep -Seconds 10
}
}
$adDomain = Get-ADDomain
$domain = $adDomain.DNSRoot
$domainDn = $adDomain.DistinguishedName
$usersAdPath = "CN=Users,$domainDn"
$testerPassword = ConvertTo-SecureString -AsPlainText 'It3st2Detest!' -Force
$thanosPwd = ConvertTo-SecureString -AsPlainText 'S3cur1tyWin2020!' -Force
$rHowePwd = ConvertTo-SecureString -AsPlainText 'DianneWasP@tient0' -Force
$SvcAcctPwd = ConvertTo-SecureString -AsPlainText 'P@ssw0rd1' -Force
$AdminstratorPassword = ConvertTo-SecureString 'YouMortal!HowDareYouQuestionThe1?' -AsPlainText -Force
# add the vagrant user to the Enterprise Admins group.
# NB this is needed to install the Enterprise Root Certification Authority.
Add-ADGroupMember `
-Identity 'Enterprise Admins' `
-Members "CN=vagrant,$usersAdPath"
Add-ADGroupMember `
-Identity 'Domain Admins' `
-Members "CN=vagrant,$usersAdPath"
# set the Administrator password.
# NB this is also an Domain Administrator account.
Set-ADAccountPassword `
-Identity "CN=Administrator,$usersAdPath" `
-Reset `
-NewPassword $AdminstratorPassword
Set-ADUser `
-Identity "CN=Administrator,$usersAdPath" `
-PasswordNeverExpires $true
# add tester.
$name = 'tester'
New-ADUser `
-Path $usersAdPath `
-Name $name `
-UserPrincipalName "$name@$domain" `
-EmailAddress "$name@$domain" `
-DisplayName 'tester' `
-AccountPassword $testerPassword `
-Enabled $true `
-PasswordNeverExpires $true
# add Thanos
$name = 'thanos.dione'
New-ADUser `
-Path $usersAdPath `
-Name $name `
-UserPrincipalName "$name@$domain" `
-EmailAddress "$name@$domain" `
-GivenName 'Thanos' `
-Surname 'Dione' `
-DisplayName 'Thanos Dione' `
-AccountPassword $thanosPwd `
-Enabled $true `
-PasswordNeverExpires $true
Add-ADGroupMember `
-Identity 'Domain Admins' `
-Members "CN=$name,$usersAdPath"
# add Rebecca Howe.
$name = 'rebecca.howe'
New-ADUser `
-Path $usersAdPath `
-Name $name `
-UserPrincipalName "$name@$domain" `
-EmailAddress "$name@$domain" `
-GivenName 'Rebecca' `
-Surname 'Howe' `
-DisplayName 'Rebecca Howe' `
-AccountPassword $rHowePwd `
-Enabled $true `
-PasswordNeverExpires $true
# add Svc Acct.
# Make it kerberoastable.
$name = 'svc.acct'
New-ADUser `
-Path $usersAdPath `
-Name $name `
-DisplayName 'Svc Acct' `
-AccountPassword $SvcAcctPwd `
-Enabled $true `
-ServicePrincipalNames "MSSQLSVC/parentSQL.parentdomain.local" `
-PasswordNeverExpires $true
New-ADComputer `
-Description "Who is a good computer? I'm a good computer." `
-DisplayName "parentWkstn" `
-DNSHostName "parentWkstn.ParentDomain.local" `
-Enabled $True `
-Name "parentWkstn" `
-SAMAccountName "parentWkstn"
New-ADComputer `
-Description "Who is a good computer? Not me." `
-DisplayName "parentSQL" `
-DNSHostName "parentSQL.parentdomain.local" `
-Enabled $True `
-Name "parentSQL" `
-SAMAccountName "parentSQL"
echo 'Let us do some delegation.'
# Add constrained delegation vulnerability.
Get-ADComputer -Identity 'parentWkstn' | Set-ADAccountControl -TrustedToAuthForDelegation $true
Set-ADComputer -Identity 'parentWkstn' -Add @{'msDS-AllowedToDelegateTo'=@('cifs/PARENTDC')}
Set-ADComputer -Identity 'parentWkstn' -Add @{'msDS-AllowedToDelegateTo'=@('host/PARENTDC')}
echo 'thanos.dione Group Membership'
Get-ADPrincipalGroupMembership -Identity 'thanos.dione' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'rebecca.howe Group Membership'
Get-ADPrincipalGroupMembership -Identity 'rebecca.howe' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'svc.acct Group Membership'
Get-ADPrincipalGroupMembership -Identity 'svc.acct' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'vagrant Group Membership'
Get-ADPrincipalGroupMembership -Identity 'vagrant' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'tester Group Membership'
Get-ADPrincipalGroupMembership -Identity 'tester' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'Enterprise Administrators'
Get-ADGroupMember `
-Identity 'Enterprise Admins' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'Domain Administrators'
Get-ADGroupMember `
-Identity 'Domain Admins' `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000
echo 'Enabled Domain User Accounts'
Get-ADUser -Filter {Enabled -eq $true} `
| Select-Object Name,DistinguishedName,SID `
| Format-Table -AutoSize | Out-String -Width 2000